gouthambs/Flask-Blogging

Markdown metadata rendering as list of unicode strings

mbrookes opened this issue ยท 11 comments

I'm trying to use markdown metadata, but getting strange results.

I have a post with "Summary: First post!" at the top.

and an index.html file containing:

<p>{{ post.meta.summary }}</p>

It's rendering as in the text of the html page as: [u'First post!']

Apologies if I've missed something obvious!

screen shot 2017-06-13 at 00 55 04

According to this:
https://pythonhosted.org/Markdown/extensions/meta_data.html

That is the expected behavior. This library uses the above mentioned module to parse Markdown. So this is the correct expected behavior. Basically you can have the same meta tag repeat more than once, and they show up as items in the list.

Okay, thanks. I'll try to figure out how to filter it in the page.

Rather than open another issue, could I ask a quick question here? Is it possible to access the currently selected tag in the index.html template for blogging.posts_by_tag? I'd like to be able to display the tag in the page title / breadcrumbs... Thanks!

@mbrookes
If i understand your question right, you want to access the tag that was chosen in the posts_by_tag view. This is possible using the plugin framework. The following plugin will insert the tag into the meta variable available in each page, and can be accessed as meta.selected_tag.

# myplugin.py
from flask_blogging import signals

def set_tag_in_meta(app, engine, posts, meta, tag, count, page):
    meta["selected_tag"] = tag
    
def register(app):
    signals.posts_by_tag_processed.connect(set_tag_in_meta)

You can hook the plugin by setting the BLOGGING_PLUGINS config variable as shown here:
http://flask-blogging.readthedocs.io/en/latest/#extending-using-the-plugin-framework

Fantastic, thanks! Goes to show the power of the plugin framework. Still, I think this should really be a standard feature. ๐Ÿ˜„

Agree this should be a standard feature. Happy to take a PR. ๐Ÿ˜„

Ok, I'll see if I can wrap my head around the code base. I'm new to Python & Flask, and all that entails, but (mostly!) enjoying it. ๐Ÿ˜„

No worries. I will try to add that to the next release. It is a small fix and I can take a look at it as well.

@mbrookes
Released v0.9.0 with the "tag" information in the meta keyword.

Thanks!

Just circling back to say that now 0.9.2 is working (tag-cloud plugin aside), I was able to test that, and it's exactly what I needed, thanks! I had been using {{posts[0].tags[0] | title }} as a stop-gap, but meta.tag is much cleaner.

@mbrookes Thanks for the feedback. Yes the tag-cloud plugin would break. I figured it is ok to break the API for the better. I will update the plugin one of these days.