Open MangelMaxime opened 1 year ago
Late on this (incredibly so) but it appears to be an issue with the lastAccessed
state map.
It's empty on the first save so the watcher stores the lastAccessed
time and the write time to the same value.
On the second save the lastTimeWrite
and lastAccessed
time (in seconds) are equal.
if shouldHandle then
let lastTimeWrite = File.GetLastWriteTime(e.FullPath)
match lastAccessed.TryFind e.FullPath with
| Some lt when Math.Abs((lt - lastTimeWrite).Seconds) < 1 -> ()
| _ ->
informationfn "[%s] Changes detected: %s" (DateTime.Now.ToString("HH:mm:ss")) e.FullPath
lastAccessed <- lastAccessed.Add(e.FullPath, lastTimeWrite)
guardedGenerate ())
I'll fiddle around with it.
Describe the bug
To Reproduce Steps to reproduce the behaviour:
dotnet fornax watch
Expected behaviour
The file should always used the last loaded information even on the first change.
Screenshots
First generation (all good)
Loader and generator have the same informations
Second generation (not good) : first time user update a file
Loader is using the new file content while the generator still received the old informations.
Third and more generation (all good)
Loader and generator have the same informations
Could it be caused by a cache mechanism?
Postloader.fsx
```fs #r "../_lib/Fornax.Core.dll" #load "../.paket/load/main.group.fsx" #load "../utils/Log.fsx" #load "../utils/Helpers.fsx" open System open System.IO open System.Diagnostics open System.Threading.Tasks open Legivel.Serialization open Helpers type Post = { relativeFile: string link : string title: string author: string option published: DateTime option tags: string list content: string } type PostFrontMatter = { title: string author: string option published: DateTime option tags: string list } let contentDir = "posts" let private getLastModified (fileName: string) = async { let psi = ProcessStartInfo() psi.FileName <- "git" psi.Arguments <- $"--no-pager log -1 --format=%%ai \"%s{fileName}\"" psi.RedirectStandardError <- true psi.RedirectStandardOutput <- true psi.CreateNoWindow <- true psi.WindowStyle <- ProcessWindowStyle.Hidden psi.UseShellExecute <- false use p = new Process() p.StartInfo <- psi p.Start() |> ignore let outTask = Task.WhenAll( [| p.StandardOutput.ReadToEndAsync() p.StandardError.ReadToEndAsync() |] ) do! p.WaitForExitAsync() |> Async.AwaitTask let! result = outTask |> Async.AwaitTask if p.ExitCode = 0 then // File is not in the git repo if String.IsNullOrEmpty result[0] then return DateTime.Now else return DateTime.Parse(result[0]) else Log.error $"Failed to get last modified information %s{result[1]}" return DateTime.Now } |> Async.RunSynchronously let private loadFile (rootDir: string) (absolutePath: string) = let text = File.ReadAllText absolutePath printfn "==== POST LOADER =====" printfn "%A" text let relativePath = Path.relativePath rootDir absolutePath let lines = text.Replace("\r\n", "\n").Split("\n") let x = getLastModified absolutePath let firstLine = Array.tryHead lines if firstLine <> Some "---" then Log.error $"File '%s{relativePath}' does not have a front matter" None else let lines = lines |> Array.skip 1 let frontMatterLines = lines |> Array.takeWhile (fun line -> line <> "---") let markdownContent = lines |> Array.skip (frontMatterLines.Length + 1) |> String.concat "\n" let frontMatterContent = frontMatterLines |> String.concat "\n" let frontMatterResult = DeserializePostloader.fsx
```fs #r "../_lib/Fornax.Core.dll" #load "layout.fsx" open Giraffe.ViewEngine let generate (ctx: SiteContents) (_projectRoot: string) (page: string) = let postOpt = ctx.TryGetValues