Skip to content

Commit

Permalink
Add base canonical passed to the templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Bille committed Aug 24, 2018
1 parent 222730d commit 9c86e56
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
27 changes: 24 additions & 3 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Local modules
from ubuntudesign.documentation_builder.operations import (
compile_metadata,
convert_path_to_html,
copy_media,
find_files,
find_metadata,
Expand Down Expand Up @@ -612,15 +613,35 @@ def test_version_paths():
relative_filepath=relative_filepath
)

assert paths[0] == {'name': '1.8', 'path': None, 'latest': False}
assert paths[1] == {'name': '1.9', 'path': '', 'latest': False}
assert paths[0] == {
'name': '1.8',
'path': None,
'latest': False,
}
assert paths[1] == {
'name': '1.9',
'path': '',
'latest': False,
}
assert paths[2] == {
'name': 'master',
'path': '../../../master/en/subfolder/index.md',
'latest': True
'latest': True,
}


def test_convert_path_to_html():
path = "path/to/index.md"

new_path = convert_path_to_html(path)
assert new_path == 'path/to/'

path = "path/to/toto.md"

new_path = convert_path_to_html(path)
assert new_path == 'path/to/toto'


def test_write_html():
html_content = "<html>\n<body>\n<h1>Hello</h1>\n<body>\n</html>"
html_dir = path.join(
Expand Down
9 changes: 7 additions & 2 deletions ubuntudesign/documentation_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
prepare_version_branches,
set_active_navigation_items,
version_paths,
write_html
write_html,
convert_path_to_html
)
from .extensions import NotificationsExtension

Expand Down Expand Up @@ -236,7 +237,11 @@ def build_branch(

for version in metadata['versions']:
if version['latest']:
metadata['latest_version'] = version['path']
metadata['relative_canonical'] = version['path']
metadata['base_canonical'] = convert_path_to_html(
version['name'] + '/' + relative_filepath)
else:
metadata['base_canonical'] = convert_path_to_html(filepath)

html = parse_markdown(
self.parser,
Expand Down
7 changes: 7 additions & 0 deletions ubuntudesign/documentation_builder/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ def version_paths(
return version_filepaths


def convert_path_to_html(path):
path = path.replace('.md', '')
path = path.replace('index', '')

return path


def write_html(html, output_filepath):

"""
Expand Down
2 changes: 1 addition & 1 deletion ubuntudesign/documentation_builder/resources/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<meta charset="UTF-8" />
<title>{{ title }} | {{ site_title if site_title else 'Documentation' }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="{{ latest_version }}" />
<link rel="canonical" href="{{ relative_canonical }}" />
<link rel="icon" href="{{ site_favicon }}" type="image/x-icon" />
<style>
/* Vanilla 1.7.1 + docs styling*/
Expand Down

0 comments on commit 9c86e56

Please sign in to comment.