def render(doc): if should_template(doc): template = env.get_template(doc.template) rendered = template.render({"doc": doc}) return put(Doc.content, doc, rendered) else: return doc
def doc_permalink(doc, permalink_template): """ Given a doc dict and a permalink template, render the output_path field of the doc. """ output_path = permalink_template.format(**read_doc_permalink(doc)) return put(Doc.output_path, doc, output_path)
def add_related(docs): docs = tuple(docs) index = build_index(docs) for doc in docs: tags = get(taxonomy, doc) related = pipe(_get_indexes(index, tags), Docs.dedupe, Docs.remove_id_path(doc.id_path), tuple) yield put(meta_related, doc, related)
def autotemplate(doc): """ Set template based on top-level directory in doc's id_path. E.g. if top-level-directory is "posts", template gets set to "posts.html". """ if get(template, doc) != "": return doc else: return put(template, doc, _infer_template(doc))
def remove_double_hrefs(docs): """ Removes double href-ing of links """ for doc in docs: yield put( Doc.content, doc, re.sub( r'<a href=\"http.+?<a href=\"(http.*?)\">\1</a>\"', r'<a href="\1"', doc.content, ) )
def ext_html(pathlike): """ Set suffix `.html` on a pathlike. Return a path string. """ return put(ext, pathlike, ".html")
def summary(docs): for doc in docs: if get(Doc.meta_summary, doc): yield doc else: yield put(Doc.meta_summary, doc, read_summary(doc.content))
def with_template_on_doc(doc): if get(template, doc) != "": return doc else: return put(template, doc, t)
def with_ext_html(doc): """ Set doc extension to ".html" """ return put(ext, doc, ".html")