From a00a53612e771e998d5a464d45835406e42db622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sun, 9 Feb 2025 13:25:09 +0100 Subject: [PATCH] Add support for skipping private headlines. --- README.md | 17 +++++++++++++++++ scripts/generate.py | 24 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46c72d7..ea46267 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,20 @@ It also copies over some static assets (css, js, fonts). The scripts are hardcoded with the hostnames and paths for my own site, so you might want to update them. General documentation is in progress and might be replaced little by little by the more interactive [org-web-editor](https://code.codigoparallevar.com/kenkeiras/org-web-editor) once that one (1) supports all the features here and (2) has support for building static sites. + +## Instructions + +Generally, what you want to do is to run `make` once to prepare the static files, then run this to generate the notes. + +```bash +mkdir -p _gen +WATCH_AND_REBUILD=0 python3 scripts/generate.py _gen/notes [] +``` + +Use `WATCH_AND_REBUILD=1` (or empty) for automatic rebuilds. + +## Filtering + +This won't render **all** notes, but try to select the PUBLIC ones and skip the PRIVATE ones. + +PUBLIC files are contained on the DEFAULT_SUBPATH, PRIVATE headlines have the `:private:` tag. diff --git a/scripts/generate.py b/scripts/generate.py index 3c9252e..80b3900 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -123,6 +123,21 @@ def load_all(top_dir_relative): logging.info("Collected {} files".format(len(docs))) return docs +def remove_non_public_headlines(doc: org_rw.OrgDoc | org_rw.Headline): + if isinstance(doc, org_rw.OrgDoc): + doc.headlines = list(filter_private_headlines(doc.headlines)) + for hl in doc.headlines: + remove_non_public_headlines(hl) + else: + doc.children = list(filter_private_headlines(doc.children)) + for hl in doc.children: + remove_non_public_headlines(hl) + +def filter_private_headlines(headlines): + for hl in headlines: + if 'private' not in hl.tags: + yield hl + def regen_all(src_top, dest_top, subpath, *, docs=None, db=None): files_generated = 0 cur = db.cursor() @@ -150,6 +165,8 @@ def regen_all(src_top, dest_top, subpath, *, docs=None, db=None): main_headline_to_docid = {} for doc in docs: relpath = os.path.relpath(doc.path, src_top) + + remove_non_public_headlines(doc) changed = False headlines = list(doc.getAllHeadlines()) related = None @@ -717,8 +734,11 @@ def render_connections(headline_id, content, graph, doc_to_headline_remapping): # return logging.info("Generating centered graph for {}".format(headline_id)) - svg = gen_centered_graph.gen(headline_id, graph['nodes'], doc_to_headline_remapping) - content.append("
{}
".format(svg)) + try: + svg = gen_centered_graph.gen(headline_id, graph['nodes'], doc_to_headline_remapping) + content.append("
{}
".format(svg)) + except: + logging.warning("Broken reference on headline ID={}".format(headline_id)) def render(headline, doc, graph, headlineLevel, doc_to_headline_remapping): try: