Add support for skipping private headlines.

This commit is contained in:
Sergio Martínez Portela 2025-02-09 13:25:09 +01:00
parent 06b5d1b50c
commit a00a53612e
2 changed files with 39 additions and 2 deletions

View File

@ -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 <path to your notes> _gen/notes [<DEFAULT SUBPATH (usually 'public', '.' to ignore)>]
```
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.

View File

@ -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("<div class='connections'>{}</div>".format(svg))
try:
svg = gen_centered_graph.gen(headline_id, graph['nodes'], doc_to_headline_remapping)
content.append("<div class='connections'>{}</div>".format(svg))
except:
logging.warning("Broken reference on headline ID={}".format(headline_id))
def render(headline, doc, graph, headlineLevel, doc_to_headline_remapping):
try: