forked from Wasted-Audio/hvcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkdocs_hooks.py
More file actions
45 lines (35 loc) · 1.64 KB
/
Copy pathmkdocs_hooks.py
File metadata and controls
45 lines (35 loc) · 1.64 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
import os
import re
def python_indent(content):
# Pattern: classic markdown indent (2 spaces) to Python-Markdown indent (4 spaces)
return re.sub(r'^(\ \ -\ .*)', r' \1', content, flags=re.MULTILINE)
def on_page_markdown(markdown, page, config, files):
if page.file.src_path == 'index.md':
readme_path = os.path.join(os.path.dirname(config['config_file_path']), 'README.md')
try:
with open(readme_path, 'r', encoding='utf-8') as f:
content = f.read()
# Rewrite links: [label](docs/...) -> [label](...)
# This handles both markdown links [text](url) and images 
# We match (docs/ and replace with (
# Pattern: parenthesis, docs/, everything else
content = content.replace('](docs/', '](')
content = content.replace('CONTRIBUTING.md', 'contributing.md')
content = content.replace('CODE_OF_CONDUCT.md', 'code_of_conduct.md')
content = python_indent(content)
return content
except Exception as e:
print(f"Error including README.md: {e}")
return markdown
# # This is not functional yet:
# if page.file.src_path == 'contributing.md':
# print(markdown)
# repo_url = config.get('repo_url', '').rstrip('/')
# markdown = markdown.replace(
# '](CHANGELOG.md)',
# f']({repo_url}/blob/develop/CHANGELOG.md)'
# )
# markdown = markdown.replace('](/docs/)', '](index.md)')
# markdown = markdown.replace('](/docs/ADRs/)', '](adr/index.md)')
markdown = python_indent(markdown)
return markdown