You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See that the new generated file still have the old content
Change the content of one of the file
See that the new generated file is now using the correct content
Change the content of one of the file
See that the new generated file is now using the correct content
etc. (From now, the generation will always be correct)
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
==== POST LOADER =====
"---
layout: post
title: Some nice post title
author: k_cieslak
published: 2020-02-19
tags: [ 'F#', 'blog']
---
# Introduction
First
"
==== POST GENERATOR =====
"# Introduction
First
"
[22:10:56] '/home/mmangel/Workspaces/GitHub/MangelMaxime/mangelmaxime.github.io/_public/posts/first.html' generated in 58ms
Generation time: 00:00:04.6666586
[22:10:56] Watch mode started. Press any key to exit.
[22:10:56 INF] Smooth! Suave listener started in 32.428ms with binding 127.0.0.1:8080
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.
[22:11:11] Changes detected: /home/mmangel/Workspaces/GitHub/MangelMaxime/mangelmaxime.github.io/posts/first.md
==== POST LOADER =====
"---
layout: post
title: Some nice post title
author: k_cieslak
published: 2020-02-19
tags: [ 'F#', 'blog']
---
# Introduction
File is updated
"
==== POST GENERATOR =====
"# Introduction
First
"
[22:11:12] '/home/mmangel/Workspaces/GitHub/MangelMaxime/mangelmaxime.github.io/_public/posts/first.html' generated in 0ms
Generation time: 00:00:00.7931652
Third and more generation (all good)
Loader and generator have the same informations
[22:12:07] Changes detected: /home/mmangel/Workspaces/GitHub/MangelMaxime/mangelmaxime.github.io/posts/first.md
==== POST LOADER =====
"---
layout: post
title: Some nice post title
author: k_cieslak
published: 2020-02-19
tags: [ 'F#', 'blog']
---
# Introduction
File is updated 2
"
==== POST GENERATOR =====
"# Introduction
File is updated 2
"
[22:12:08] '/home/mmangel/Workspaces/GitHub/MangelMaxime/mangelmaxime.github.io/_public/posts/first.html' generated in 49ms
Generation time: 00:00:01.0151255
Could it be caused by a cache mechanism?
Postloader.fsx
#r "../_lib/Fornax.Core.dll"
#load "../.paket/load/main.group.fsx"
#load "../utils/Log.fsx"
#load "../utils/Helpers.fsx"openSystemopenSystem.IOopenSystem.DiagnosticsopenSystem.Threading.TasksopenLegivel.SerializationopenHelperstypePost={
relativeFile:string
link :string
title:string
author:string option
published:DateTime option
tags:string list
content:string}typePostFrontMatter={
title:string
author:string option
published:DateTime option
tags:string list}letcontentDir="posts"letprivategetLastModified(fileName:string)=async{letpsi= 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 <-falseuse p =new Process()
p.StartInfo <- psi
p.Start()|> ignore
letoutTask=
Task.WhenAll([|
p.StandardOutput.ReadToEndAsync()
p.StandardError.ReadToEndAsync()|])do! p.WaitForExitAsync()|> Async.AwaitTask
let!result= outTask |> Async.AwaitTask
if p.ExitCode =0then// File is not in the git repoif String.IsNullOrEmpty result[0]thenreturn DateTime.Now
elsereturn DateTime.Parse(result[0])else
Log.error $"Failed to get last modified information %s{result[1]}"return DateTime.Now
}|> Async.RunSynchronously
letprivateloadFile(rootDir:string)(absolutePath:string)=lettext= File.ReadAllText absolutePath
printfn "==== POST LOADER ====="
printfn "%A" text
letrelativePath=
Path.relativePath rootDir absolutePath
letlines= text.Replace("\r\n","\n").Split("\n")letx= getLastModified absolutePath
letfirstLine= Array.tryHead lines
if firstLine <> Some "---"then
Log.error $"File '%s{relativePath}' does not have a front matter"
None
elseletlines= lines |> Array.skip 1letfrontMatterLines=
lines
|> Array.takeWhile (fun line -> line <>"---")letmarkdownContent=
lines
|> Array.skip (frontMatterLines.Length +1)|> String.concat "\n"letfrontMatterContent= frontMatterLines |> String.concat "\n"letfrontMatterResult=
Deserialize<PostFrontMatter> frontMatterContent
|> List.head
match frontMatterResult with| Error error ->
Log.error $"Error parsing front matter in file '%s{relativePath}': %A{error}"
None
| Success frontMatter ->ifnot(frontMatter.Warn.IsEmpty)thenfor warning in frontMatter.Warn do
Log.warn $"Warning in file '%s{relativePath}': %A{warning}"letlink=
Path.ChangeExtension(relativePath,"html"){
relativeFile = relativePath
link = link
title =""
author = None
published = frontMatter.Data.published
tags = frontMatter.Data.tags
content = markdownContent
}|> Some
letloader(projectRoot:string)(siteContent:SiteContents)=letpostsPath= Path.Combine(projectRoot, contentDir)letoptions= EnumerationOptions(RecurseSubdirectories =true)letfiles= Directory.GetFiles(postsPath,"*", options)
files
|> Array.filter (fun n -> n.EndsWith ".md")|> Array.map (loadFile projectRoot)// Only keep the valid post to avoid to propagate errors|> Array.filter Option.isSome
|> Array.map Option.get
|> Array.iter siteContent.Add
siteContent
Postloader.fsx
#r "../_lib/Fornax.Core.dll"
#load "layout.fsx"openGiraffe.ViewEngineletgenerate(ctx:SiteContents)(_projectRoot:string)(page:string)=letpostOpt=
ctx.TryGetValues<PostLoader.Post>()|> Option.defaultValue Seq.empty
|> Seq.tryFind (fun post -> post.relativeFile = page)match postOpt with| None ->leterror={
Path = page
Message = $"Post %s{page} not found in the context"
Phase = Generating
}
ctx.AddError error
Layout.generationErrorPage ctx
| Some post ->
printfn "==== POST GENERATOR ====="
printfn "%A" post.content
div [][ str post.content ]|> Layout.mainPage ctx
The text was updated successfully, but these errors were encountered:
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 thenletlastTimeWrite= 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 ())
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
Postloader.fsx
The text was updated successfully, but these errors were encountered: