From f8d3632615bbc18dc9b174e640fc28a96bbe699b Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 6 Mar 2024 22:26:50 +0000 Subject: [PATCH] Adds back-to-top functionality --- do-markdown-magic.py | 12 ++++++++---- src/pages/index.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/do-markdown-magic.py b/do-markdown-magic.py index 1cec57e0..2d8ef3ea 100644 --- a/do-markdown-magic.py +++ b/do-markdown-magic.py @@ -1,7 +1,13 @@ import os import re +# 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 + def process_file(file_path): + # Read the file content with open(file_path, 'r', encoding='utf-8') as file: content = file.read() @@ -14,12 +20,11 @@ def process_file(file_path): # Make each link relative, so replace ./docs with /docs content = content.replace('./docs', '/docs') - # Remove .md extension from every link while ensuring idempotency + # Remove .md extension from every relative link (ignoring http/https links) content = re.sub(r'(\[[^\]]+\]\((?!https?://)[^)#]+?)\.md(/?#?[^)]*?)(\))', r'\1\2\3', content) # Replace back to top buttons - # Assuming this pattern is correct; adjust if necessary - content = re.sub(r'\[.*Back to top.*\]', '[⬆️ Back to Top](https://riot.im/app/#)', content) + content = re.sub(r'\[\s*⬆️\s*Back to Top\s*\]\(#.*?\)', '[⬆️ Back to Top](#top)', content, flags=re.IGNORECASE) # Remove any
tags content = re.sub(r'
.*?
', '', content, flags=re.DOTALL) @@ -36,6 +41,5 @@ def process_docs_folder(folder_path): process_file(file_path) if __name__ == "__main__": - # Update this path to the correct relative path where the script will be run in the GitHub Action docs_folder_path = "./docs/" process_docs_folder(docs_folder_path) diff --git a/src/pages/index.js b/src/pages/index.js index af1fdf9a..a71c93ed 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -13,7 +13,7 @@ export default function Home() { description="Dashy, the self-hosted dashboard app for your homelab"> -
+
);