Absolute URLs for Blog Post Images

39 views
Skip to first unread message

Jeff Jenkins

unread,
Feb 4, 2013, 7:19:47 AM2/4/13
to blogofil...@googlegroups.com
I have a bunch of html and markdown blog posts which have images.  In RSS the images don't show up because I'd been writing my images as <img src="/path/to/img"/>.  In Mako there are helper functions to make URLs which include the domain name, but how do I do that in a blog post that's html or markdown?

Doug Latornell

unread,
Feb 4, 2013, 10:52:35 AM2/4/13
to blogofil...@googlegroups.com, Jeff Jenkins
The blogofile.util.site_path_helper() function may be what you're looking for:
It's available in templates as bf.util.site_path_helper(). You can see examples of its use in blogofile_blog/site_src/_templates/header.mako.



On Mon, Feb 4, 2013 at 4:19 AM, Jeff Jenkins <je...@jeffreyjenkins.ca> wrote:
I have a bunch of html and markdown blog posts which have images.  In RSS the images don't show up because I'd been writing my images as <img src="/path/to/img"/>.  In Mako there are helper functions to make URLs which include the domain name, but how do I do that in a blog post that's html or markdown?

--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blogofile-disc...@googlegroups.com.
To post to this group, send email to blogofil...@googlegroups.com.
Visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jeff Jenkins

unread,
Feb 4, 2013, 12:16:42 PM2/4/13
to Doug Latornell, blogofil...@googlegroups.com
I'm using that inside of my mako templates, but the blog template files are markdown (or raw html), not mako.  Is there a way for me to use that helper from inside a markdown file inside of _posts?

Doug Latornell

unread,
Feb 4, 2013, 5:03:02 PM2/4/13
to blogofil...@googlegroups.com, Jeff Jenkins
On Mon, Feb 4, 2013 at 9:16 AM, Jeff Jenkins <je...@jeffreyjenkins.ca> wrote:
I'm using that inside of my mako templates, but the blog template files are markdown (or raw html), not mako.  Is there a way for me to use that helper from inside a markdown file inside of _posts?

Sorry, I misinterpreted your original question.

Off the top of my head I would say that you will have to use one or more custom filter(s).

If you're looking for guidance on creating a filter, Mike Bayer did a nice writeup on a syntax highlighting filter for RST posts: http://techspot.zzzeek.org/2010/12/06/my-blogofile-hacks/
There is also a filters section in the docs: http://docs.blogofile.com/en/latest/filters.html

Jeffrey jenkins

unread,
Feb 4, 2013, 7:12:17 PM2/4/13
to Doug Latornell, blogofil...@googlegroups.com
Thanks!  That was really easy.  Here's the code for anyone else who wants this.  I'm doing it the (really) quick and dirty way since I don't want to get into real parsing:

==========   _filters/absimg.py   ========

import re
import blogofile_bf as bf
abs_img = re.compile(r"""(?P<img><img src=["'])/""", re.DOTALL)

def run(src):
    return abs_img.sub(r'\1' + bf.config.site.url + '/', src)

========== _config.py ================

blog.post.default_filters = {
    "markdown": "markdown, syntax_highlight, absimg",
    "html": "syntax_highlight, absimg"
}
Reply all
Reply to author
Forward
0 new messages