This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild_redirects.py
More file actions
84 lines (58 loc) · 2.75 KB
/
Copy pathbuild_redirects.py
File metadata and controls
84 lines (58 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import glob
def find_files(directory):
pattern = os.path.join(directory, "**", "*.md")
return glob.glob(pattern, recursive=True)
def add_frontmatter_config(file_path, config_key, config_value):
with open(file_path, "r") as file:
content = file.read()
parts = content.split("---")
if len(parts) < 3:
raise ValueError("The file does not contain valid FrontMatter")
frontmatter = parts[1].strip()
rest_of_content = "---".join(parts[2:])
frontmatter_lines = frontmatter.split("\n")
key_exists = False
for i, line in enumerate(frontmatter_lines):
if line.startswith(f"{config_key}:"):
frontmatter_lines[i] = f"{config_key}: {config_value}"
key_exists = True
break
if not key_exists:
frontmatter_lines.append(f"{config_key}: {config_value}")
frontmatter = "\n".join(frontmatter_lines)
updated_content = f"---\n{frontmatter}\n---{rest_of_content}"
with open(file_path, "w") as file:
file.write(updated_content)
files = find_files("./docs")
files.append("./index.md")
files.append("./404.html")
for file in files:
relativePath = file.replace("./docs/", "").replace("./", "").replace("index.md", "").replace(".md", "")
# The following redirects are changed because in Docusaurus a category
# doesn't necessarily have a page associated with it
if (relativePath == "introduction/"):
relativePath = "introduction/what-is-acap"
if (relativePath == "get-started/" or relativePath == "get-started/set-up-developer-environment/"):
relativePath = "get-started/set-up-developer-environment/pre-requisites"
if (relativePath == "api/"):
relativePath = "api/native-sdk-api"
if (relativePath == "service/"):
relativePath = "service/acap-service-portal"
if (relativePath == "acap-sdk-version-3/"):
relativePath = "acap-sdk-version-3/introduction"
if (relativePath == "acap-sdk-version-3/develop-applications/"):
relativePath = "acap-sdk-version-3/develop-applications/application-project-structure"
if (relativePath == "acap-sdk-version-3/services-for-partners/"):
relativePath = "acap-sdk-version-3/services-for-partners/package-signing"
# This page ios removed in the migration, redirect to the root of the ACAP
# documentation
if (relativePath == "licenses/"):
relativePath = ""
# Redirect them to the root of the ACAP documentation
if (relativePath == "404.html"):
relativePath = ""
if (not relativePath.endswith("release-notes/") and "release-notes/" in relativePath):
relativePath += "/"
url = f"https://developer.axis.com/acap/{relativePath}"
add_frontmatter_config(file, "redirect_to", url)