示例#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
示例#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)
示例#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)
示例#4
0
文件: doc.py 项目: SinaKhalili/notes
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))
示例#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,
            )
        )
示例#6
0
文件: path.py 项目: SinaKhalili/notes
def ext_html(pathlike):
    """
    Set suffix `.html` on a pathlike.
    Return a path string.
    """
    return put(ext, pathlike, ".html")
示例#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))
示例#8
0
文件: doc.py 项目: SinaKhalili/notes
 def with_template_on_doc(doc):
     if get(template, doc) != "":
         return doc
     else:
         return put(template, doc, t)
示例#9
0
文件: doc.py 项目: SinaKhalili/notes
def with_ext_html(doc):
    """
    Set doc extension to ".html"
    """
    return put(ext, doc, ".html")