提交 a5ed52e7 编写于 作者: A Andrea Frittoli 提交者: tekton-robot

Fix the case of non-md files in nested folders

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: NAndrea Frittoli <andrea.frittoli@gmail.com>
上级 85a5bcb6
......@@ -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())
......
......@@ -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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册