From 5787339f22e20d21049f3e1e58f6b5daa5493632 Mon Sep 17 00:00:00 2001 From: maybetree Date: Sun, 2 Jun 2024 16:35:16 +0200 Subject: [PATCH] move index to webroot, clickable map --- doc/{pages => }/index.md | 2 +- doc/templ/map.html | 21 +++++++++++++++++++ doc/templ/root.html | 4 ++-- src/raidoc/build.py | 45 ++++++++++++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 9 deletions(-) rename doc/{pages => }/index.md (91%) create mode 100644 doc/templ/map.html diff --git a/doc/pages/index.md b/doc/index.md similarity index 91% rename from doc/pages/index.md rename to doc/index.md index aa0e418..a6f9aa4 100644 --- a/doc/pages/index.md +++ b/doc/index.md @@ -1,6 +1,6 @@ # Welcome to RAIMAD! -Start reading at [Installing RAIMAD](install.md) +Start reading at [Installing RAIMAD](pages/install.md) or [browse the map of all pages](map.md). diff --git a/doc/templ/map.html b/doc/templ/map.html new file mode 100644 index 0000000..85ffae5 --- /dev/null +++ b/doc/templ/map.html @@ -0,0 +1,21 @@ + + + + + + + + + +
+ + + {{map_cmap}} + +
+ + + diff --git a/doc/templ/root.html b/doc/templ/root.html index 2ac9b41..5b1c76f 100644 --- a/doc/templ/root.html +++ b/doc/templ/root.html @@ -2,8 +2,8 @@ - - + + diff --git a/src/raidoc/build.py b/src/raidoc/build.py index 8997dd0..e167bf3 100644 --- a/src/raidoc/build.py +++ b/src/raidoc/build.py @@ -9,6 +9,11 @@ from raidoc.raimark_ext import RaimarkExt, LinkMixin +dot_sanitizer = str.maketrans({ + '-': '_', + '.': '_', + }) + def build(source='./doc', dest='./build'): source = Path(source) @@ -46,7 +51,7 @@ def build(source='./doc', dest='./build'): pyg_style = HtmlFormatter(style='default').get_style_defs() (dest / 'pyg.css').write_text(pyg_style) - for path in (source / 'pages').rglob('*'): + for path in (source).rglob('*'): if path.suffix != '.md': continue @@ -62,10 +67,19 @@ def build(source='./doc', dest='./build'): for link_dest in LinkMixin.links_to: dest_stem = Path(link_dest).stem - graph.append(f"\t{path.stem.replace('-','_')} -> {dest_stem.replace('-','_')};") + graph.append( + f"\t{path.stem.translate(dot_sanitizer)} -> " + f"{dest_stem.translate(dot_sanitizer)};" + ) + + graph.append( + f'''\t{path.stem.translate(dot_sanitizer)} ''' + f'''[URL="{path.relative_to(source).with_suffix('.html')}"];''' + ) html = template.render({ - 'content': content + 'content': content, + 'webroot': '../' * len(path.relative_to(source).parent.parts) }) destparent = dest / path.parent.relative_to(source) @@ -77,18 +91,37 @@ def build(source='./doc', dest='./build'): map_gv = Path(dest / 'map.gv') map_svg = Path(dest / 'map.svg') + map_cmap = Path(dest / 'map-cmap.html') map_gv.write_text('\n'.join(graph)) # TODO copypasta - dot = subprocess.Popen( + subprocess.Popen( [ 'dot', # Call the DOT compiler... '-Tsvg', # tell it to produce an SVG file... '-Gbgcolor=none', # ...with a transparent background '-Nfontsize=10', # ... with a smaller than usual font size - '-Nfontname="Courier New"', # ... with a smaller than usual font size + '-Nfontname=Courier New', # ... with a smaller than usual font size f'-o{str(map_svg)}', f'{str(map_gv)}', ], - ) + ).wait() + subprocess.Popen( + [ + 'dot', # Call the DOT compiler... + '-Tcmapx', # tell it to produce an SVG file... + '-Gbgcolor=none', # ...with a transparent background + '-Nfontsize=10', # ... with a smaller than usual font size + '-Nfontname=Courier New', # ... with a smaller than usual font size + f'-o{str(map_cmap)}', + f'{str(map_gv)}', + ], + ).wait() + + template = env.from_string((source / 'templ/map.html').read_text()) + html = template.render({ + 'webroot': '', + 'map_cmap': map_cmap.read_text() + }) + (dest / 'map.html').write_text(html)