TheDigitalCatOnline / blog_source

Source code of the blog
16 stars 6 forks source link

Setting up your Bengal theme #23

Closed tooh closed 6 months ago

tooh commented 6 months ago

Hello ,

I like your theme very much. I thought I give it a try by setting it up from the Bengal folder.

Basic setup was done without any problems but when generating the site I stumbled upon problems

Error

[10:22:11] CRITICAL TemplateSyntaxError: Encountered unknown tag __init__.py:666
                    'assets'. Jinja was looking for the                         
                    following tags: 'endfor' or 'else'. The                     
                    innermost block that needs to be closed is                  
                    'for'.                                                      
make: *** [publish] Error 1

Probably caused by missing config in JINJA_ENVIRONMENT

Should probably be:

JINJA_ENVIRONMENT = { 'extensions': ['webassets.ext.jinja2.AssetsExtension'] }

After adding this to pelicanconf.py following error:

[10:27:11] CRITICAL RuntimeError: No assets environment          __init__.py:666
                    configured in Jinja2 environment                            
make: *** [publish] Error 1

Traced it back to

/usr/local/lib/python3.11/site-packages/webassets/ext/jinja2.py:172 in       │
│ _render_assets                                                               │
│                                                                              │
│   169 │   def _render_assets(self, filter, output, dbg, depends, files, call │
│   170 │   │   env = self.environment.assets_environment                      │
│   171 │   │   if env is None:                                                │
│ ❱ 172 │   │   │   raise RuntimeError('No assets environment configured in '+ │
│   173 │   │   │   │   │   │   │      'Jinja2 environment')                   │
│   174 │   │                                                                  │
│   175 │   │   # Construct a bundle with the given options        

On this one I'm stuck.

I know this has to do with the webassets module but I'm not very familiar with this.

I installed all the requirements.

Could it be that the pelicanconf.py that is published in your blog_source repo is not the one used for your live blog?

Would really appreciate your help.

lgiordani commented 6 months ago

Hi! Thanks for the message. Have you installed pelican-webassets in the virtual environment? It's in the file requirements.txt and it looks like that might be the problem. The files in the repository are updated from that point of view (I have some experimental changes locally but I've implemented them in the last few days)

Sorry, strike that, I can see that the code you copied comes from the webassets package. Sorry. Let me investigate it.

lgiordani commented 6 months ago

So, as for the JINJA_ENVIRONMENT, it should be set automatically by this https://github.com/pelican-plugins/webassets/blob/17faf0dcf94a165555109b58bd09fabb1decaa61/pelican/plugins/webassets/webassets.py#L36 Which version of Pelican are you using?

tooh commented 6 months ago

Thanks for your quick reaction.

Installed all the requirements from requirements.txt already.

I'm running latest version.

Your last comment triggered me and I checked my PLUGINS setting. Noticed webassets plugin was missing.

Added it and generator does not complain anymore about webassets environment missing.

Now I stumble upon the following error 👍

 /Users/peter/Sites/bengal/templates/includes/share.html:1 in top-level       │
│ template code                                                                │
│                                                                              │
│ ❱ 1 <span><a class="" href="{{article.share_post['twitter']}}" target="_blan │
│   2 <span><a class="" href="{{article.share_post['linkedin']}}" target="_bla │
│   3 <span><a class="" href="{{article.share_post['hacker-news']}}" target="_ │
│   4 <span><a class="" href="{{article.share_post['email']}}" target="_blank" │
│                                                                              │
│ /usr/local/lib/python3.11/site-packages/jinja2/environment.py:466 in getitem │
│                                                                              │
│    463 │   ) -> t.Union[t.Any, Undefined]:                                   │
│    464 │   │   """Get an item or attribute of an object but prefer the item. │
│    465 │   │   try:                                                          │
│ ❱  466 │   │   │   return obj[argument]                                      │
│    467 │   │   except (AttributeError, TypeError, LookupError):              │
│    468 │   │   │   if isinstance(argument, str):                             │
│    469 │   │   │   │   try:                                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
UndefinedError: 'pelican.contents.Article object' has no attribute 'share_post'

Does this need some configuration also ?

lgiordani commented 6 months ago

Oh that is another plugin that I installed (and also contributed to), namely share-post https://github.com/pelican-plugins/share-post

It's up to you if you want to keep it, clearly. If you are not interested in buttons to share posts on social networks you can get rid of the relevant part in the template https://github.com/TheDigitalCatOnline/blog_source/blob/master/bengal/templates/article.html#L96

Same is true for all other plugins that I use e.g. series https://github.com/TheDigitalCatOnline/blog_source/blob/master/bengal/templates/article.html#L104

All the highlighted lines here https://github.com/TheDigitalCatOnline/blog_source/blob/master/requirements.txt#L2-L7 are plugins, so you need either to install them or to get rid of the code in the template that uses them.

Let me know how it goes!

BTW you mentioned PLUGINS: do you know that you can get rid of that variable and let Pelican discover plugins on its own? That the reason why share-post doesn't work even though you installed it.

tooh commented 6 months ago

After some tweaking I have the basics working.

Daily scrum

Thanks for your assistance.

lgiordani commented 6 months ago

Well done!

Now, there is some automated machinery behind the scenes for things like images. Some of it is pretty old and Just Works but might be definitely done in a better way. Feel free to ask if it doesn't make sense or to change the code. Good luck!

tooh commented 6 months ago

Made some steps.

Now I'm puzzled by following code in index.html template

Top series

by
{% for series_name, series_articles in series.items() %} {% set article = series_articles[0] %} {% if article.series_info %}
{{ article.image if article.image else 'article_image_placeholder' }}

{{ series_name }}

{{ article.series_info }}

In my setup it only produces the string Top series. This code seems to be the problem {% if article.series_info %} As far as I understood the series plugin uses metadata Series: [name] Where should series_info come from?
lgiordani commented 6 months ago

Yes, you probably don't have any series yet so series.items() doesn't contain anything. You can see some examples here:

tooh commented 6 months ago

Again thanks.

Did not realize that series_info is a custom article metadata. :(

Added it to the article and working now.

lgiordani commented 6 months ago

No worries! You might want to wrap the whole block in {% if series.items() | length %} (check the syntax) in case you want to keep it but don't have posts belonging to series yet.

tooh commented 6 months ago

Migration of theme finished for now.

http://blog.florijnconsultancy.nl/

Some cleaning up to do of the metadata of the articles and adding some article images and of course crediting your theme in the footer.

Thank you for your assistance!

lgiordani commented 6 months ago

You are very welcome! Thanks for the questions. Should you have further questions feel free to open a new issue.