Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagevars are not parsed correctly ? #1054

Closed
SimonCoste opened this issue Sep 13, 2023 · 4 comments
Closed

Pagevars are not parsed correctly ? #1054

SimonCoste opened this issue Sep 13, 2023 · 4 comments

Comments

@SimonCoste
Copy link

Hi, I encounter a bug which is really annoying since it only happens when I deploy on GH pages; on my local machine, everything works well, so it's quite difficult to produce a MWE. I tried to be succinct in explaining the bug.

Context

I have a folder of pages (blogposts) with three local variables defined on each page: titlepost, date and abstract. For example, a typical header for those pages is

+++ 
titlepost = "Gradient descent over convex landscapes" 
date = "April 2022"
abstract = "A note on the most elementary result of convex optimization:... " 
+++

In utils.jl I wrote a custom util function named hfun_post which takes as argument the name of the page, seeks the local variables, and display a short html snippet with only the title, date and abstract; then on the index page of my blog I have a list, typically the body looks like this:

{{post diffusion}}

{{post doubledescent}}

{{post invequiv}}

{{post convmixer}}

{{post gradient}}

see the resulting page.

In hfun_post the local variables of the page at path are extracted using pagevar(path, :titlepost) for example.

Bug description

Unfortunately, some entries are not parsed correctly. More precisely, the local page variables are not correctly extracted and thus the pagevar function outputs the default value nothing. You can see this behaviour at the end of the page - note that the link itself are correct.

What is really strange is that this behaviour seems random. Most of my blogposts are displayed correctly. Only a few ones, usually located at the end of the page, are not correctly parsed.

How could I correct this behaviour ? Any idea why the local vars are not correctly parsed on some pages?
Best,
Simon

@tlienart
Copy link
Owner

Hello Simon, thanks for the nice description and nice blog, seems like we share some common interests.

In this case, using @delay in front of the definition of hfun_post should help so in your utils.jl:

@delay hfun_post(...)
 # rest of the function as you had it
end

This @delay thing is annoying and the next version of Franklin drops it (this is in beta at Xranklin.jl, you could already use it if you wanted to). It was added a while ago to ensure that all pages are processed before the hfun is executed (basically so that the hfun is guaranteed to have access to the full state). It's recommended to use it with Franklin 0.10 for any hfun that makes use of pagevar.

I just did it in a fork of your blog and you can see that the notes page is generated as expected:

https://github.com/tlienart/SimonCoste.github.io/blob/110e6771061e45d09fe4e634d47c84fb24dd2240/notes/index.html#L83-L84

The reason why it was working locally and not on gh page is an unfortunate coincidence related to in what order files are browsed.

@SimonCoste
Copy link
Author

Thanks for the remarkable speed and accuracy of your answer ❤️

So if I understand correctly, without @delay, the hfun_* can be executed before some pages are processed ? 

@SimonCoste
Copy link
Author

SimonCoste commented Sep 14, 2023

There is a catch, however : now with @delay all the links are broken. I think the pages werent processed ?
EDIT: my bad it was my own mistake :)

@tlienart
Copy link
Owner

So if I understand correctly, without @delay, the hfun_* can be executed before some pages are processed ?

yeah that's right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants