Open luraess opened 10 months ago
can you try {{ispage e"if_is_list_posts_page()"}}
?
separately you could also write hfun_inject_if_posts_page()
and have your block be
{{else}} {{inject_if_posts_page}}
...
with that function returning the whole HTML. You also have access to relative_url
, header etc (via the local context get_lc()
).
Thanks! I also added a attempt to draft what I want to do in the sandbox repo: https://github.com/Unil-SGC/multipost/tree/main
Ideally, I have post_dir = ("news", "events")
in https://github.com/Unil-SGC/multipost/blob/main/config.md
Then, in utils.jl
I could have a hfun
that reads in post_dir
: https://github.com/Unil-SGC/multipost/blob/7f1d47cd25688b96ca6967dbf3e80b4c75138cda/utils.jl#L68-L75
and modifies the strings to construct the correct ones to be passed in _layout/head.html
here https://github.com/Unil-SGC/multipost/blob/7f1d47cd25688b96ca6967dbf3e80b4c75138cda/_layout/head.html#L78 and here https://github.com/Unil-SGC/multipost/blob/7f1d47cd25688b96ca6967dbf3e80b4c75138cda/_layout/head.html#L87
I am though unsure how to access a global variable defined in config.md
and also how to pass the string from the hfun
to the call side in head.html
.
I am though unsure how to access a global variable defined in config.md and also how to pass the string from the hfun to the call side in head.html.
getgvar(:name_of_var)
(so getlvar(...)
for a local context variable and getgvar
for the global one)function hfun_inject_some_html()
return """<img src="https://upload.wikimedia.org/wikipedia/commons/c/c1/Erizo_de_mar_viol%C3%A1ceo_%28Sphaerechinus_granularis%29%2C_Madeira%2C_Portugal%2C_2019-05-31%2C_DD_36.jpg">"""
end
then in any .md
or .html
call {{inject_some_html}}
Thanks, that's the hfun
I came up with https://github.com/Unil-SGC/multipost/blob/852210a1beb0a4465d6f16c0265b8ceefead59f6/utils.jl#L68-L74. But calling it in head https://github.com/Unil-SGC/multipost/blob/852210a1beb0a4465d6f16c0265b8ceefead59f6/_layout/head.html#L78 seems not to perform the expected result.
I may be doing something wrong with the triple quotes wrapping. Curiously, populating the hfun
with @show
does not output anything.
no you can't nest these. What I was saying is that instead of having
{{ispage something}}
HTML to inject
{{end}}
you would do
{{inject_if_page}}
(no ispage!)
and
function hfun_inject_if_page()
# here do the page check using rpath of current context + retrieving global var post_dirs or whatever
if condition_is_verified
return """"HTML to inject"""
end
return ""
end
Thanks for the hints. I got something to work, but it's not super concise - see here: https://github.com/Unil-SGC/multipost/blob/f7d35787e8c926386f21bfc58088d18615ef89a5/utils.jl#L99-L144.
This to be called from _head.html
: https://github.com/Unil-SGC/multipost/blob/f7d35787e8c926386f21bfc58088d18615ef89a5/_layout/head.html#L73-L86.
Also, I am still missing the
{{else}} {{ispage /news/* /events/*}}
<section class="container post">
{{insert post_header.html}}
part as I am unsure how to "convert" the {{insert post_header.html}}
when calling it from an hfun
.
It's maybe finally just easier to manually list post folder in {{ispage }}
construct...
Following up on #273 about specific point
Could you give a hint on how to create such
hfun_if_is_list_posts_page
function that would return a list of folders to further pass to{{ispage}}
based on a input list defined in e.g.config.md
:In
config.md
:In
utils.jl
:In
head.html
: