Skip to content

Commit

Permalink
Fix the case of non-md files in nested folders
Browse files Browse the repository at this point in the history
In case of non-md files in nested folders, the filename used in the
rewrite included the target path leading to double-path in the link.
Fixed that and added a use case for the non-md file in a subfolder.

Signed-off-by: Andrea Frittoli <[email protected]>
  • Loading branch information
afrittoli authored and tekton-robot committed Nov 9, 2020
1 parent 85a5bcb commit a5ed52e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Empty file.
13 changes: 10 additions & 3 deletions sync/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def test_transform_link(self):
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 = [
Expand All @@ -234,7 +236,9 @@ def test_transform_link(self):
"test.txt",
"content.md",
"notthere.txt",
"../another-content/test.md"
"../another-content/test.md",
"./nested/content.md",
"./nested/example.yaml"
]

expected_results = [
Expand All @@ -243,7 +247,9 @@ def test_transform_link(self):
"/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):
Expand Down Expand Up @@ -385,5 +391,6 @@ def test_download_resources_to_project(self, transform_docs_mock):
base_path='/docs/test',
base_url=f'http://test.com/test/tree/{self.tagname}/')


if __name__ == '__main__':
unittest.main()

0 comments on commit a5ed52e

Please sign in to comment.