From c9d17523ce3e032b8bee089cf6bb193f420e6807 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 14 Mar 2025 15:50:46 -0500 Subject: [PATCH] static site generator part 4 --- user-selectable styles not entirely happy about using JavaScript, but I think I figured out a way to load the selected style via cookie without causing the page to flash, so for the moment I'm sticking with it because I love the feature so much Signed-off-by: Brian S. Stephan --- incorporealcms/pages.py | 4 ++- incorporealcms/ssg.py | 6 ++-- incorporealcms/templates/base.html | 52 ++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/incorporealcms/pages.py b/incorporealcms/pages.py index 7c6a044..659cc93 100644 --- a/incorporealcms/pages.py +++ b/incorporealcms/pages.py @@ -45,7 +45,9 @@ def handle_markdown_file_path(path: str) -> str: description=get_meta_str(md, 'description'), image=get_meta_str(md, 'image'), content=content, - user_style=Config.PAGE_STYLES.get(Config.DEFAULT_PAGE_STYLE), + stylesheet=(Config.DEFAULT_PAGE_STYLE, + Config.PAGE_STYLES.get(Config.DEFAULT_PAGE_STYLE)), + page_styles=Config.PAGE_STYLES, base_url=Config.BASE_HOST + instance_resource_path_to_request_path(path), navs=parent_navs, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'), diff --git a/incorporealcms/ssg.py b/incorporealcms/ssg.py index 4f01c9c..6b88a88 100644 --- a/incorporealcms/ssg.py +++ b/incorporealcms/ssg.py @@ -45,11 +45,11 @@ def build(): tmp_output_dir = tempfile.mkdtemp(dir=os.path.dirname(output_dir)) cprint(f"creating temporary directory '{tmp_output_dir}' for writing", 'green') - # CORE CONTENT + # copy core content pages_dir = os.path.join(instance_dir, 'pages') copy_to_destination(pages_dir, tmp_output_dir) - # STATIC DIR + # copy the program's static dir program_static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static') static_output_dir = os.path.join(tmp_output_dir, 'static') try: @@ -59,7 +59,7 @@ def build(): pass copy_to_destination(program_static_dir, static_output_dir, convert_markdown=False) - # INSTANCE STATIC DIR + # copy the instance's static dir --- should I deprecate this since it could just be stuff in pages/static/? custom_static_dir = os.path.join(instance_dir, 'custom-static') copy_to_destination(custom_static_dir, static_output_dir, convert_markdown=False) diff --git a/incorporealcms/templates/base.html b/incorporealcms/templates/base.html index d7ec4d8..5e3a761 100644 --- a/incorporealcms/templates/base.html +++ b/incorporealcms/templates/base.html @@ -6,16 +6,64 @@ SPDX-License-Identifier: AGPL-3.0-or-later {{ title }} + {% if title %}{% endif %} {% if description %}{% endif %} {% if image %}{% endif %} - + +{% for style, stylesheet in page_styles.items() %} + +{% endfor %} +
{% block header %} @@ -29,7 +77,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later {% if page_styles %}
{% for style in page_styles %} - [{{ style }}] + [{{ style }}] {% endfor %}
{% endif %}