def dir_pages(where=".", files="*.markdown", template="", context=None, **kwargs): renderer = _get_template(template, context) files = [] for page in glob(os.path.join(where, files)): name, a = os.path.splitext(os.path.basename(page)) files.append({"name": name, "url": page.replace(".markdown", ".html")}) print files return renderer.render({"files": files})
def blog_listing( path="blog", template=None, order=(("_sortable_date", u"DESC"),), limit=None, tags="", context=None, **kwargs ): """ This is what actually displays the shortened list of blogposts. You should specify a template. This is used by putting a <% blog_listing template="blah" %> tag plugin wherever you want it. As well as the expected fields (title, body, date) there will also be a 'url' field, which gives a relative link from the current page to the blogpost. """ posts_context = {"posts": []} cachedb = os.path.join(context["_cache_dir"], "blog.db") log.info("reading from: %s", cachedb) tag_filters = [] for t in searchable_tags(tags.split(",")): tag_filters.append(("searchable_tags", "LIKE", NoJSON("%" + t + "%"))) with DictLiteStore(cachedb, "pages") as s: posts_context["posts"] = s.get(*tag_filters, order=order) # TODO: filtering? # makes a relative url from the current path to another output file: make_url = lambda p: quote(os.path.relpath(p, context["_output_dir"])) # now do it for all posts: for post in posts_context["posts"]: post["url"] = make_url(post["filename"]) # add the general context: posts_context.update(context) # render the output, and send it back: templ = _get_template(template, posts_context) return templ.render(posts_context)