don't add an artificial ./ subdir due to how os.path.relpath works
this fixes stuff like og:urls of https://foo/./ or https://foo/./page and also removes an extra layer of depth in the breadcrumb hierarchy, just by suppressing the '.' in relpath output at the root of pages/ fixes #21 Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
9caf08a277
commit
d49b9d48a8
@ -4,6 +4,7 @@ SPDX-FileCopyrightText: © 2025 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
"""
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
@ -16,6 +17,8 @@ from incorporealcms.error_pages import generate_error_pages
|
||||
from incorporealcms.feed import generate_feed
|
||||
from incorporealcms.markdown import handle_markdown_file_path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StaticSiteGenerator(object):
|
||||
"""Generate static site output based on the instance's content."""
|
||||
@ -89,8 +92,10 @@ class StaticSiteGenerator(object):
|
||||
cprint(f"copying files from '{source_dir}' to '{dest_dir}'", 'green')
|
||||
os.chdir(source_dir)
|
||||
for base_dir, subdirs, files in os.walk(source_dir):
|
||||
logger.debug("starting to build against %s || %s || %s", base_dir, subdirs, files)
|
||||
# remove the absolute path of the directory from the base_dir
|
||||
base_dir = os.path.relpath(base_dir, source_dir)
|
||||
relpath = os.path.relpath(base_dir, source_dir)
|
||||
base_dir = relpath if relpath != '.' else ''
|
||||
# create subdirs seen here for subsequent depth
|
||||
for subdir in subdirs:
|
||||
self.build_subdir_in_destination(source_dir, base_dir, subdir, dest_dir)
|
||||
@ -149,6 +154,7 @@ class StaticSiteGenerator(object):
|
||||
# render markdown as HTML
|
||||
if src.endswith('.md') and convert_markdown:
|
||||
rendered_file = dst.removesuffix('.md') + '.html'
|
||||
print(f"rendering file '{src}' -> '{rendered_file}'")
|
||||
try:
|
||||
content = handle_markdown_file_path(src)
|
||||
except UnicodeDecodeError:
|
||||
|
@ -73,6 +73,21 @@ def test_og_image():
|
||||
os.chdir(os.path.join(src_dir, 'pages'))
|
||||
|
||||
ssg.build_file_in_destination(os.path.join(HERE, 'instance', 'pages'), '', 'more-metadata.md', tmpdir, True)
|
||||
with open(os.path.join(tmpdir, 'more-metadata.html'), 'r') as graphviz_output:
|
||||
data = graphviz_output.read()
|
||||
assert ('<meta property="og:image" content="http://example.org/test.img') in data
|
||||
with open(os.path.join(tmpdir, 'more-metadata.html'), 'r') as markdown_output:
|
||||
data = markdown_output.read()
|
||||
assert ('<meta property="og:image" content="http://example.org/test.img">') in data
|
||||
|
||||
|
||||
def test_og_url():
|
||||
"""Test that the og:url meta tag is present as expected."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
ssg = StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(src_dir, 'pages'))
|
||||
|
||||
# testing a whole build run because of bugs in how I handle pathing adding a "./" in
|
||||
# the generated URLs for content in the pages/ root
|
||||
ssg.build_in_destination(os.path.join(HERE, 'instance', 'pages'), tmpdir, True)
|
||||
with open(os.path.join(tmpdir, 'index.html'), 'r') as markdown_output:
|
||||
data = markdown_output.read()
|
||||
assert ('<meta property="og:url" content="http://example.org/">') in data
|
||||
|
@ -18,7 +18,7 @@
|
||||
"level": "DEBUG",
|
||||
"handlers": ["console"]
|
||||
},
|
||||
"incorporealcms.pages": {
|
||||
"incorporealcms.ssg": {
|
||||
"level": "DEBUG",
|
||||
"handlers": ["console"]
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
"""Configure the test application.
|
||||
|
||||
SPDX-FileCopyrightText: © 2020 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
"""
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'formatters': {
|
||||
'default': {
|
||||
'format': '[%(asctime)s %(levelname)-7s %(name)s] %(message)s',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'default',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'incorporealcms.mdx': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
},
|
||||
'incorporealcms.pages': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
},
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user