getnikola / plugins

Extra plugins for Nikola
https://plugins.getnikola.com/
MIT License
59 stars 95 forks source link

ENH: include the sidebar from the sidebar plugin when building the pages #375

Open mattip opened 3 years ago

mattip commented 3 years ago

Rather than generate a sidebar-en.inc file as a task, perhaps the sidebar plugin could add a set_site method and add the sidebar as a blinker.signal callback, like static_comments does. This would make the snippet more useful since no server-side or javascript would be needed to include it. Did I understand correctly the sequence of processes?

mattip commented 3 years ago

It might be sufficient to add the 'public' path to the python code in sidebar.py:

    def set_site(self, site):
        """Set site."""
        site.template_system.inject_directory('public')   # add this line
        super(RenderSidebar, self).set_site(site)

Then I can include the snippet in my templates

{% include 'sidebar-en.inc' %}
felixfontein commented 3 years ago

@mattip the problem with the sidebar is that its contents depend on essentially the whole site. So if the sidebar would already be included during the build in every page, every change to the site would require re-creating all pages. For small pages that's ok, for larger ones it's pretty excessive. That's why it generates a separate file that needs to be included in another step.

I personally use a substitution script / two-phase deployment to create a final version of the site with the sidebar included, to avoid the use of JavaScript to include it.

mattip commented 3 years ago

I personally use a substitution script / two-phase deployment to create a final version

With sed via a marker in the post template? I guess that could work too. My site (www.pypy.org after importing blog posts + comments from https://morepypy.blogspot.com in this MR) has ~500 posts and the strategy I outlined above requires about 3 seconds to recreate the pages, so I am not to worried about rebuilding once a week or so when we have new blog posts.