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 from_doc(doc): """ Read stub from doc """ return Stub(get(Doc.id_path, doc), get(Doc.output_path, doc), get(Doc.created, doc), get(Doc.modified, doc), get(Doc.title, doc), get(Doc.meta_summary, doc))
def should_template(doc): """ Check if a doc should be templated. Returns a bool. """ return get(Doc.template, doc) is not ""
def has_backlinks(doc): return len(get(meta_backlinks, doc)) > 0
def has_links(doc): return len(get(meta_links, doc)) > 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))
def with_template_on_doc(doc): if get(template, doc) != "": return doc else: return put(template, doc, t)