-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_post.py
More file actions
29 lines (21 loc) · 837 Bytes
/
_post.py
File metadata and controls
29 lines (21 loc) · 837 Bytes
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
import os
import re
# Directory paths
SOURCE_DIR = "./website/_build/html/content"
skip_dirs = ["_build"]
def replace_colab_link(file_path):
with open(file_path, "r") as f:
content = f.read()
pattern = r"https://colab\.research\.google\.com/github/([^/]+)/([^/]+)/blob/master/website/(.+)"
replacement = r"https://colab.research.google.com/github/\1/\2/blob/gh-pages/_sources/\3"
replaced = re.sub(pattern, replacement, content)
with open(file_path, "w") as f:
f.write(replaced)
def build():
for root, dirs, files in os.walk(SOURCE_DIR):
for file in files:
if file.endswith(".html"):
print('replace colab link in', os.path.join(root, file))
replace_colab_link(os.path.join(root, file))
if __name__ == '__main__':
build()