Exemplo n.º 1
0
 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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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,
            )
        )
Exemplo n.º 6
0
def ext_html(pathlike):
    """
    Set suffix `.html` on a pathlike.
    Return a path string.
    """
    return put(ext, pathlike, ".html")
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
 def with_template_on_doc(doc):
     if get(template, doc) != "":
         return doc
     else:
         return put(template, doc, t)
Exemplo n.º 9
0
def with_ext_html(doc):
    """
    Set doc extension to ".html"
    """
    return put(ext, doc, ".html")