2024-03-07 00:59:26 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2024-03-07 01:26:50 +03:00
|
|
|
# A script to update each markdown file in the docs directory
|
|
|
|
# Used to process the docs from the GitHub repo to be used for dashy.to website
|
|
|
|
# Because GH and Docusourus dashy.to expect slightly different markdown features
|
|
|
|
# Written by @CrazyWolf13
|
|
|
|
|
2024-03-07 00:59:26 +03:00
|
|
|
def process_file(file_path):
|
2024-03-07 01:26:50 +03:00
|
|
|
# Read the file content
|
2024-03-07 00:59:26 +03:00
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
|
|
content = file.read()
|
|
|
|
|
|
|
|
# Remove <!-- --> Comments
|
|
|
|
content = re.sub(r'<!--(.*?)-->', '', content, flags=re.DOTALL)
|
|
|
|
|
|
|
|
# Replace <br> with <br />
|
|
|
|
content = content.replace('<br>', '<br />')
|
|
|
|
|
|
|
|
# Make each link relative, so replace ./docs with /docs
|
|
|
|
content = content.replace('./docs', '/docs')
|
|
|
|
|
2024-03-07 01:26:50 +03:00
|
|
|
# Remove .md extension from every relative link (ignoring http/https links)
|
2024-03-07 00:59:26 +03:00
|
|
|
content = re.sub(r'(\[[^\]]+\]\((?!https?://)[^)#]+?)\.md(/?#?[^)]*?)(\))', r'\1\2\3', content)
|
|
|
|
|
|
|
|
# Replace back to top buttons
|
2024-03-07 01:26:50 +03:00
|
|
|
content = re.sub(r'\[\s*⬆️\s*Back to Top\s*\]\(#.*?\)', '[⬆️ Back to Top](#top)', content, flags=re.IGNORECASE)
|
2024-03-07 00:59:26 +03:00
|
|
|
|
|
|
|
# Remove any <details> tags
|
|
|
|
content = re.sub(r'<details>.*?</details>', '', content, flags=re.DOTALL)
|
|
|
|
|
|
|
|
# Save the processed content back to the file
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as file:
|
|
|
|
file.write(content)
|
|
|
|
|
|
|
|
def process_docs_folder(folder_path):
|
|
|
|
for root, dirs, files in os.walk(folder_path):
|
|
|
|
for file in files:
|
|
|
|
if file.endswith('.md'):
|
|
|
|
file_path = os.path.join(root, file)
|
|
|
|
process_file(file_path)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
docs_folder_path = "./docs/"
|
|
|
|
process_docs_folder(docs_folder_path)
|