Added support for static doctest files generated by the iwmsite static site generator.

This commit is contained in:
2023-05-09 09:52:39 +02:00
parent 0cff31e65b
commit 13e0473328
7 changed files with 295 additions and 133 deletions
+1
View File
@@ -0,0 +1 @@
3.10.1
+45
View File
@@ -0,0 +1,45 @@
import pathlib
from ssg.tags import *
from ssg.utils import *
from markup import iwmlibdoc_document, sitemap_main
src = pathlib.Path('..')
content = src / 'lib'
async def main(path:pathlib.Path):
"""Typical main program, setting up content publishers, defining the site structure and
typical order of generating initial pages and observing subsequent changes.
"""
# 2. Build the site structure with nested context managers
with site('iwmlibdoc', path=path, doc=iwmlibdoc_document) as docsite:
# If we use symlinks the css and image files can be modified without
# notifications.
docsite.symlink(src, 'css')
docsite.symlink(src, 'assets')
docsite.symlink(src, 'dist')
# structures can be created in a loop to ensure indentical hierarchies
sitemap = page('sitemap.html',
title='Sitemap',
main=sitemap_main)
static_folder(content)
# 3. Start generation.
docsite.generate()
#print(docsite)
# 4. Let's check whether all links are working...
# site.validate()
await docsite.observe_filesystem(timeout=120)
def run():
default = pathlib.Path('.') / 'dist'
if default.exists():
shutil.rmtree(default)
default.mkdir(parents=True)
asyncio.run(main(default))
if __name__ == "__main__":
run()
+107
View File
@@ -0,0 +1,107 @@
from typing import Dict, List
import ssg.document
import ssg.utils
from ssg.tags import *
from dominate.tags import *
def iwmlibdoc_document(context):
doc = ssg.document.document(title=context.title)
with doc.head:
meta(charset="utf-8")
attr(lang=context.language())
if isinstance(context, static_page):
for tag in context.soup.find_all('link'):
if href := tag.attrs.get('href'):
link(rel="stylesheet", href=href)
for tag in context.soup.find_all('script'):
if src := tag.attrs.get('src'):
script(src=src)
else:
link(rel="stylesheet", href= "css/doctest.css")
link(rel="stylesheet", href= "css/demo.css")
with doc.body:
site_navigation(context)
ssg.document.placeholder(key='main', alternatives=['body']) # here goes the special content part
site_footer(context)
return doc
def site_navigation(context):
mainmenu(context)
br()
br()
breadcrumb(context)
hr()
def level_menu(context, root):
for name, child in sorted(context.named_children.items()):
if child.folderish():
if index := child.named_children.get('index.html'):
url = '.' + index.url(relative=root)
yield dict(url=url, title=index.title)
if child.title == name:
continue
if name.endswith('.html'):
url = '.' + child.url(relative=root)
yield dict(url=url, title=child.title)
def main_menu(context):
root = context.menuroot()
if context == root:
for info in level_menu(root, root):
yield info
else:
yield dict(url= context.up() + 'sitemap.html', title="Home")
for info in level_menu(context.parent, root):
yield info
@nav(cls="breadcrumb")
def breadcrumb(context):
"""
{% macro breadcrumb(context) -%}
<nav class="breadcrumb">
{% for info in context.breadcrumb() %}
{% if info.url %}
<a href="{{info.url}}">{{info.title}}</a>
{% else %}
<a href="#"><u>{{info.title}}</u></a>
{% endif %}
{% endfor %}
</nav>
{% endmacro %}
"""
for info in context.breadcrumb():
if url := info.get('url'):
a(info['title'], href=url)
else:
a(info['title'], href='#')
@nav(cls="mainmenu")
def mainmenu(context:ssg.generator):
for info in main_menu(context):
if url := info.get('url'):
a(info['title'], href=url)
else:
a(info['title'], href='#')
@main
def sitemap_main(context:ssg.generator):
root = context.menuroot()
h3("Sitemap")
with ul(id="sitemap"):
for info in getsite().page_infos(relative=root):
url = info['url']
if url.endswith('.html'):
li(a(info['title'], href=url))
@footer
def site_footer(context):
hr()
date = ssg.utils.now('en')
p(f'Generated by IWMSite {date}')
+21
View File
@@ -0,0 +1,21 @@
aiohttp
dominate
pytest
Babel
mypy
beautifulsoup4
python-socketio
requests
watchdog
# streamlit apps
streamlit==1.4.0
openpyxl
plotly
fpdf
# architecture overview
diagrams
# ssg
git+ssh://git@gitea.iwm-tuebingen.de/Medienentwicklung/iwmsite.git@master