Skip to content

Commit

Permalink
move index to webroot, clickable map
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeetree committed Jun 2, 2024
1 parent 3b0796c commit 5787339
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/pages/index.md → doc/index.md
Original file line number Diff line number Diff line change
@@ -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).


Expand Down
21 changes: 21 additions & 0 deletions doc/templ/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="{{webroot}}css/root.css">
<link rel="stylesheet" href="{{webroot}}pyg.css">
<!--<script src="browser.js"></script>-->
</head>
<body>
<div id="map">
<img
src="map.svg"
usemap="#G"
>
<map name="G">
{{map_cmap}}
</map>
</div>
</body>
</html>

4 changes: 2 additions & 2 deletions doc/templ/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/root.css">
<link rel="stylesheet" href="../pyg.css">
<link rel="stylesheet" href="{{webroot}}css/root.css">
<link rel="stylesheet" href="{{webroot}}pyg.css">
<!--<script src="browser.js"></script>-->
</head>
<body>
Expand Down
45 changes: 39 additions & 6 deletions src/raidoc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

from raidoc.raimark_ext import RaimarkExt, LinkMixin

dot_sanitizer = str.maketrans({
'-': '_',
'.': '_',
})


def build(source='./doc', dest='./build'):
source = Path(source)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)

0 comments on commit 5787339

Please sign in to comment.