The (crude) site.

It's funny that I'm using nbconvert, markdown, pandoc, tidy, and of
course python, all to make a simple static website...

"There's got to be a better way!"
This commit is contained in:
Simon Forman
2022-09-16 07:36:28 -07:00
parent b67fc46291
commit 7a25eee481
36 changed files with 531235 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import pathlib, re, sys
import markdown
url_base = pathlib.Path('/notebooks')
r = re.compile('<title>(.*)</title>')
def title_of(html_path):
return r.search(html_path.read_text()).group(1).replace('_', ' ')
# Just explode if there's no match.
# NoneType has no "group" attr...
notebook_dir = pathlib.Path('.')
htmls = sorted(
(
path
for path in notebook_dir.glob('*.html')
if not path.name == 'index.html'
),
key=title_of,
)
text = ['''\
[Thun](/)
# Notebooks
Various Jupyter notebooks, some more polished than others, a few incomplete.
I'm in the process of rewriting them to use the Joy kernel.
''']
for p in htmls:
text.append(f'* [{title_of(p)}]({(url_base/p.name)!s})\n')
html = markdown.markdown(''.join(text), output_format="html5")
print(f'''\
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Thun Notebooks</title>
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
{html}
</body>
</html>
''')