posativ / acrylamid

(unmaintained) static blog generator in python with incremental rendering ⛺
http://posativ.org/acrylamid/
Other
277 stars 40 forks source link

Processed blog body in meta tags? #210

Closed geekman closed 10 years ago

geekman commented 10 years ago

Currently each entry has a description, inherited from the MetadataMixin, but if not defined in the front matter it will be computed using self.source[:50]. This produces undesired results if the an image markup is within the first 50 characters.

Also, how would one extract the first image from the (processed) entry body and populate it in a meta tag like twitter:image:src?

Without resorting to regex hacks, would it be possible to obtain and manipulate the processed entry body during template rendering?

posativ commented 10 years ago

Unfortunately not. Acrylamid can not track dependencies used in attributes and has no ability to use filters (which is probably the feature you want there) in tags. For attributes, you have to use hard-coded values.

geekman commented 10 years ago

I managed to do it by processing entry.content in the template itself. Problem now is I need to add Jinja2 filters so that the templates can access it when processing the <meta> tags.

What would you recommend is the best way to insert a global filter (without modifying the acrylamid source)? I've looked at the jinja2 filter but that filters the entry body and doesn't run when processing the top-level template.

posativ commented 10 years ago

You can create a custom, no-op view and register your filter there: https://github.com/posativ/acrylamid/blob/master/acrylamid/views/tag.py#L106

geekman commented 10 years ago

Yeap actually that's what I did, but it's still not very ideal as the no-op view still needs to have some boilerplate code to satisfy being a View.

  1. the view must be included in the VIEWS in conf.py with some dummy route. Otherwise it never gets executed
  2. the generate method must be present and must return valid data.
    1. If generate is missing, it fails with object has no attribute 'generate'
    2. If generate is pass or return, it fails with NoneType is not iterable.
    3. If the returned path is invalid, helpers.mkfile will complain

Hopefully there will be another type of plugin in future that is able to suit this need that might not be so hacky, but this works for now.

Thanks :)