Skip to content

Commit

Permalink
Adds back-to-top functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Mar 6, 2024
1 parent 743c65b commit f8d3632
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions do-markdown-magic.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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 <details> tags
content = re.sub(r'<details>.*?</details>', '', content, flags=re.DOTALL)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Home() {
description="Dashy, the self-hosted dashboard app for your homelab">
<HomePageHeader />
<HomePageFeatures />
<main>
<main id="top">
</main>
</Layout>
);
Expand Down

0 comments on commit f8d3632

Please sign in to comment.