diff --git a/incorporealcms/markdown.py b/incorporealcms/markdown.py index 176516b..e3ae83c 100644 --- a/incorporealcms/markdown.py +++ b/incorporealcms/markdown.py @@ -1,5 +1,9 @@ """Process Markdown pages. +With the project now being a SSG, most files we just let the web server serve +as is, but .md files need to be processed with a Markdown parser, so a lot of this +is our tweaks and customizations for pages my way. + SPDX-FileCopyrightText: © 2025 Brian S. Stephan SPDX-License-Identifier: AGPL-3.0-or-later """ @@ -71,7 +75,7 @@ def parse_md(path: str): logger.debug("file metadata: %s", md.Meta) - page_name = get_meta_str(md, 'title') if md.Meta.get('title') else path + page_name = get_meta_str(md, 'title') if md.Meta.get('title') else instance_resource_path_to_request_path(path) page_title = f'{page_name} - {Config.TITLE_SUFFIX}' if page_name else Config.TITLE_SUFFIX logger.debug("title (potentially derived): %s", page_title) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 6a6dedd..8970049 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -7,7 +7,8 @@ import os from unittest.mock import patch from incorporealcms.markdown import (generate_parent_navs, handle_markdown_file_path, - instance_resource_path_to_request_path, request_path_to_breadcrumb_display) + instance_resource_path_to_request_path, parse_md, + request_path_to_breadcrumb_display) HERE = os.path.dirname(os.path.abspath(__file__)) os.chdir(os.path.join(HERE, 'instance/', 'pages/')) @@ -104,3 +105,24 @@ def test_request_path_to_breadcrumb_display_patterns(): assert request_path_to_breadcrumb_display('/foo/bar') == 'bar' assert request_path_to_breadcrumb_display('/foo/bar/') == 'bar' assert request_path_to_breadcrumb_display('/') == '' + + +def test_parse_md_metadata(): + """Test the direct results of parsing a markdown file.""" + content, md, page_name, page_title, mtime = parse_md('more-metadata.md') + assert page_name == 'title for the page' + assert page_title == 'title for the page - example.org' + + +def test_parse_md_metadata_forced_no_title(): + """Test the direct results of parsing a markdown file.""" + content, md, page_name, page_title, mtime = parse_md('forced-no-title.md') + assert page_name == '' + assert page_title == 'example.org' + + +def test_parse_md_metadata_no_title_so_path(): + """Test the direct results of parsing a markdown file.""" + content, md, page_name, page_title, mtime = parse_md('subdir/index.md') + assert page_name == '/subdir/' + assert page_title == '/subdir/ - example.org'