when symlinking foo.md, also symlink foo.html if generating .html
fixes #24 Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
a327c6b89c
commit
201cd80804
@ -142,6 +142,14 @@ class StaticSiteGenerator(object):
|
||||
src = self.symlink_to_relative_dest(source_dir, os.path.join(base_dir, file_))
|
||||
print(f"creating symlink '{dst}' -> '{src}'")
|
||||
os.symlink(src, dst, target_is_directory=False)
|
||||
if src.endswith('.md') and convert_markdown:
|
||||
# we also need to make a .html symlink so that web server configs
|
||||
# pick up the "redirect"
|
||||
second_src = src.removesuffix('.md') + '.html'
|
||||
second_dst = dst.removesuffix('.md') + '.html'
|
||||
print(f"creating symlink '{second_dst}' -> '{second_src}'")
|
||||
os.symlink(second_src, second_dst, target_is_directory=False)
|
||||
|
||||
else:
|
||||
src = os.path.join(base_dir, file_)
|
||||
print(f"copying file '{src}' -> '{dst}'")
|
||||
|
@ -52,6 +52,23 @@ def test_file_copy_symlink():
|
||||
assert os.path.islink(os.path.join(tmpdir, 'symlink-to-foo.txt'))
|
||||
|
||||
|
||||
def test_file_copy_symlink_of_markdown_also_has_html_symlink():
|
||||
"""Test the ability to sync source and generated symlinks to the output dir."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'symlink-to-no-title.md', tmpdir,
|
||||
True)
|
||||
# need to copy the destination for os.path.exists to be happy with this
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'no-title.md', tmpdir, True)
|
||||
assert os.path.exists(os.path.join(tmpdir, 'symlink-to-no-title.md'))
|
||||
assert os.path.islink(os.path.join(tmpdir, 'symlink-to-no-title.md'))
|
||||
# a .md symlink should also create the .html symlink (see issue #24)
|
||||
assert os.path.exists(os.path.join(tmpdir, 'symlink-to-no-title.html'))
|
||||
assert os.path.islink(os.path.join(tmpdir, 'symlink-to-no-title.html'))
|
||||
|
||||
|
||||
def test_dir_copy():
|
||||
"""Test the ability to sync a directory to the output dir."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
|
Loading…
Reference in New Issue
Block a user