diff --git a/sync/sync.py b/sync/sync.py index 6b9263296bab4008b34322083d08acea943aef53..ce231b0c0350d9fb7916003167af963139d69048 100755 --- a/sync/sync.py +++ b/sync/sync.py @@ -266,16 +266,16 @@ def transform_link(link, base_path, local_files, rewrite_path, rewrite_url): if ext == '.md': # Links to the index file are rendered as base_path/ if is_index: - path = '' + target_file = '' # links to md other files are rendered as .../[md filename]/ else: - path = filename + '/' + target_file = filename + '/' # for .md files, lower the case of fragments to match hugo's behaviour parsed = parsed._replace(fragment=parsed.fragment.lower()) if target_folder: - new_path = [rewrite_path, target_folder, path] + new_path = [rewrite_path, target_folder, target_file] else: - new_path = [rewrite_path, path] + new_path = [rewrite_path, target_file] return parsed._replace(path="/".join(new_path)).geturl() # when not found on disk, append to the base_url return urljoin(rewrite_url, parsed._replace(path=fq_path).geturl()) diff --git a/sync/test-content/nested/example.yaml b/sync/test-content/nested/example.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/sync/test_sync.py b/sync/test_sync.py index 2392f063a1ad5410542b328b5b71849525b08651..83e75a5731baff09dc070949f5d1a6c7537aa285 100644 --- a/sync/test_sync.py +++ b/sync/test_sync.py @@ -225,7 +225,9 @@ class TestSync(unittest.TestCase): local_files = { 'test-content/content.md': ('_index.md', ''), 'test-content/test.txt': ('test.txt', ''), - 'another-content/test.md': ('test.md', 'another') + 'another-content/test.md': ('test.md', 'another'), + 'test-content/nested/content.md': ('content.md', 'nested'), + 'test-content/nested/example.yaml': ('example.yaml', 'nested') } cases = [ @@ -234,7 +236,9 @@ class TestSync(unittest.TestCase): "test.txt", "content.md", "notthere.txt", - "../another-content/test.md" + "../another-content/test.md", + "./nested/content.md", + "./nested/example.yaml" ] expected_results = [ @@ -243,7 +247,9 @@ class TestSync(unittest.TestCase): "/docs/foo/test.txt", "/docs/foo/", "https://foo.bar/test-content/notthere.txt", - "/docs/foo/another/test/" + "/docs/foo/another/test/", + "/docs/foo/nested/content/", + "/docs/foo/nested/example.yaml" ] for case, expected in zip(cases, expected_results): @@ -385,5 +391,6 @@ class TestSync(unittest.TestCase): base_path='/docs/test', base_url=f'http://test.com/test/tree/{self.tagname}/') + if __name__ == '__main__': unittest.main()