Getting access to post fields in post.content

21 views
Skip to first unread message

Joes Staal

unread,
Nov 18, 2012, 6:39:02 PM11/18/12
to blogofil...@googlegroups.com
Hi,

The final thing I'd like to sort before going online with my blog is the following.
I've written a filter for including images with a lightbox plugin. If I write in my markdown something like:
%%[t2, title of pic]
the filter understands it needs to wrap t2.jpg in a lightbox div, use 'title of pic' as the title and that it needs to link to p2.jpg as its popup image.
However, the thing I struggle with is to include the directory where the pictures are stored. I store them in a folder based on the date: YYYYMMDD. 
I've accomplished this by editing post.py and adding in the __parse function:    
# Add date as html comment so that it can be used for image directories
image_dir = '\n<!--' + self.date.strftime("%Y%m%d") + '-->\n' 
post_src = content_parts[2] + image_dir
This way I can use the filter to get the directory name for the correct date. 
Since I didn't want to change the blogofile source, I've copied the _controllers/blog directory to my blog _controller directory and made the modification there. 
I don't find this a very elegant solution and was wondering if there is a cleaner way of doing this.

Cheers,

Joes

Doug Latornell

unread,
Nov 22, 2012, 5:24:51 PM11/22/12
to blogofil...@googlegroups.com

You're on the right track in that you need to create a custom controller to do what you want.

You shouldn't have to copy the whole _controllers/blog directory though. You should be able to just put your custom controller module in your site's _controller/ directory and enable it in the site _config.py. The docs [1] could probably do a better job of explaining that.

For a concrete example, take a look at the blogofile.com repo [2]. There are 2 custom controllers enabled in _config.py, and the code for them is in _controllers/. The docs building controller is no longer used since the docs got moved into the blogofile repo and are built on readthedocs.org, but I haven't gotten around to removing the related stuff from the blogofile.com repo - good thing, or it would be harder yo point to it as an example!

[1] http://docs.blogofile.com/en/latest/controllers.html
[2] https://github.com/EnigmaCurry/blogofile.com

Cheers,

Joes

--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/blogofile-discuss/-/xY0Ru_xV0CUJ.
To post to this group, send email to blogofil...@googlegroups.com.
To unsubscribe from this group, send email to blogofile-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.

Joes Staal

unread,
Nov 23, 2012, 4:52:13 AM11/23/12
to blogofil...@googlegroups.com, d...@douglatornell.ca
Thanks for the info. I'll give it a try, but am a bit short on time at the moment. I'll let you know how I get on.

Cheers,

Joes
Reply all
Reply to author
Forward
0 new messages