-
Notifications
You must be signed in to change notification settings - Fork 18
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
[feature] Render page templates as jingoo templates with fields from index #36
Comments
I wouldn't want to add it as a built-in, but I have an idea for a future release that will greatly simplify the task. Why I wouldn't want it as a built-in?
The idea of what to do instead is to add support for hooks that run at different points of page processing. Hook files will be discovered and loaded more or less like plugins. Here's a mockup of a hook that will solve your problem in a simple way: [hooks.pre-save]
hook = "render-template" String.render_template(page_text, index_entry) The
If you feed the entire page to the template processor, it will indiscriminately render those blocks and ruin (or fail on) examples that aren't to be rendered. Unless the user is careful enough to wrap them into a Instead, it's better done by a [hooks.pre-render]
hook = "render-template"
selector = "tmpl" -- Render template tags inside <tmpl> </tmpl> pseudo-elements and unwrap their content
function render(tmpl_elem, env)
tmpl_data = HTML.inner_html(tmpl_elem)
tmpl_out = String.render_template(tmpl_data, env)
html = HTML.parse(tmpl_out)
HTML.insert_after(tmpl_elem, html)
HTML.delete(tmpl_elem)
end
selector = config["selector"]
tmpls = HTML.select(page, selector)
List.iter(render, tmpls) |
That's implying that the Right now index extraction is done before any widgets by default, so that widgets can safely do things that will interfere with index extraction. You can schedule some widgets to run before it with |
I see. That makes sense! This would work for my case. Being more familiar with Jekyll and tools like it, I at first assumed there would be some inbuilt way of getting post metadata into a page template. It took me a bit of reading through the docs and thinking I just couldn't find where it was documented before realizing it's not a core capability. It may be worth adding a note in the docs somewhere, even just to explicitly state page templates in soupault aren't like page/layout templates in others (unless it exists and I did just miss it). |
Well, the big idea was to avoid separation between the page and its metadata, and also avoid duplication of it. Jekyll and friends need the user to keep all machine-readablae metadata in the front matter because they can't look into the page, but to soupault, the entire page is machine-readable, so it's possible to present data on the page as you want (by hand) and also use it as metadata, like I do in the project blog: <h1 id="post-title">Soupault 2.7.0 release</h1>
<p>Date: <time id="post-date">2021-05-12</time> </p>
<p id="post-excerpt">
Soupault 2.7.0, is available for download from <a href="https://files.baturin.org/software/soupault/2.7.0">my own server</a>
and from <a href="https://github.com/dmbaturin/soupault/releases/tag/2.7.0">GitHub releases</a>.
It adds a new <code>wrap</code> widget, ability to disable any widget in the config, and support for multiple build profiles.
</p> I agree that rearranging metadata or displaying metadata scattered throughout the page in a compact block are valid use cases though. I just don't like the inflexibility of the approach Jekyll/Hugo/etc. force on the user, so I'd rather add ways to allow everyone to implement their own. A To serve people who "just want a blog", I made https://github.com/dmbaturin/soupault-sample-blog which I dubbed "the octopress of soupault", though it needs work to be user-friendly. Also, is your site live and is the source public? I'd be curious to see it. |
Hi @ryanartecona, I've added three new things that make it possible to implement this.
Here's a trivial example of a hook that shows the index entry in debug logs but otherwise just pretty-prints the page element tree. [hooks.render]
lua_source = '''
Log.debug(JSON.pretty_print(index_entry))
page_source = HTML.pretty_print(page)
''' That's just a simple example of course, but nothing prevents using that hook to render a template using the printed HTML and the index entry fields. |
This is an idea for an enhancement. I have no idea how invasive a change this would be, but it would have avoided some complexity that otherwise I had to shove into a plugin.
My use case is I have some metadata about each post I want to render via a template with a certain structure so I can style it how I want with css. I made a plugin uses the same selectors I use in my index fields and imperatively moves some html elements around, but it takes a lot more effort for a simple use case that could be handled by a template.
Jekyll and related engines use yaml front-matter to define per-post metadata which then become variables that can be interpreted into templated "layouts" (jekyll layout docs). Soupault already has a nice and flexible way of pulling out per-post metadata from custom tags emedded into each post via index field definitions, but currently those can only be fed to an "index view" on an "index page", with no way to directly use the same fields within the post template itself.
Soupault already uses jingoo templates in a couple place, so it seems a natural extension would be to allow page templates to use jingoo syntax with variables that come from index fields.
The text was updated successfully, but these errors were encountered: