-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_links.py
More file actions
27 lines (21 loc) · 1014 Bytes
/
generate_links.py
File metadata and controls
27 lines (21 loc) · 1014 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
from pathlib import Path
PROJECT_URL = "https://gasinan.github.io/AdvForNotes"
ADD_LINK_START_SYMBOL, ADD_LINK_END_SYMBOL = "<!--", "-->"
md_paths = [path for path in Path(".").rglob("*.md")]
for md_path in md_paths:
with open(md_path, "r") as f:
md_contents = f.readlines()
for i in range(len(md_contents)):
md_content = md_contents[i][:-1]
if (md_content.startswith(ADD_LINK_START_SYMBOL) and
md_content.endswith(ADD_LINK_END_SYMBOL)):
link_name = (md_content
.replace(ADD_LINK_START_SYMBOL, "")
.replace(ADD_LINK_END_SYMBOL, ""))
link_url = f"{PROJECT_URL}/{link_name}"
with open(f"{link_name}.md", "r") as md:
link_title = md.readlines()[0].replace("#", "").strip()
link = f"- [{link_title}]({link_url})\n"
md_contents[i+1] = link
with open(md_path, "w") as f:
f.write("".join(md_contents))