Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/actions/build-doc/create-site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

BANNER_ANCHOR = '<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">'
VERSION_ANCHOR = '<script>'
CANONICAL_ANCHOR = '<title>'

DOWNLOAD_FOLDER = "v"
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "snippets")

Expand Down Expand Up @@ -120,6 +122,7 @@ def create_latest_version_link(base_dir):

return latest_version


def create_site():

versions_cache_dir = "v"
Expand Down Expand Up @@ -150,6 +153,8 @@ def create_site():
old_version_banner = load_template("old-release-header.html")
dev_version_banner = load_template("dev-header.html")

canonical_header = load_template("canonical.html")

latest_version_dir = os.path.join(versions_dir, latest_version)

# update all the files
Expand All @@ -160,7 +165,7 @@ def create_site():
if not file_name.endswith('.html'):
continue

file_path = os.path.join(root, file_name)
file_path = os.path.join(root, file_name)

if root.startswith(dev_version_dir):
# inject the development version warning in the latest version
Expand All @@ -173,6 +178,17 @@ def create_site():
# inject the version bar in the doc we downloaded from the release
inject_content_into_html(file_path, VERSION_ANCHOR, get_version_bar(versions_dir, file_path))

# inject the canonical header
path_parts = os.path.relpath(file_path, versions_dir).split('/')

if path_parts[-1] == 'index.html':
canonical_path = "/".join(path_parts[1:-1]) + ('/' if len(path_parts) > 2 else '')
else:
canonical_path = "/".join(path_parts[1:])

page_canonical_header = canonical_header.replace('%PAGE_PATH%', canonical_path)
inject_content_into_html(file_path, CANONICAL_ANCHOR, page_canonical_header)

print(f"Processed {file_path}")

def load_template(template_name, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions .github/actions/build-doc/snippets/canonical.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="canonical" href="https://synaptics-synap.github.io/doc/v/latest/%PAGE_PATH%" />