Skip to content

Commit

Permalink
Prepend base path to href attributes for tag links
Browse files Browse the repository at this point in the history
  • Loading branch information
vraer committed Nov 29, 2023
1 parent cdc4227 commit 218aa66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/decision-records/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Links to records are generated on page build according to the details specified
### :green_square: Status: Adopted
<!-- TAGS='adopted' BEGIN -->
<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>
<p><a href="/tags/#adopted" class="md-tag">adopted</a></p></details>
<p><a href="/website-wiki/tags/#adopted" class="md-tag">adopted</a></p></details>

- [Standardize HTML img tag](adopted/standardize-html-img-tag.md)
- [Use merge commit for gh-pages updates](adopted/use-merge-commit-for-gh-pages-updates.md)
Expand All @@ -32,7 +32,7 @@ Links to records are generated on page build according to the details specified
### :red_square: Status: Not-implemented
<!-- TAGS='not implemented' BEGIN -->
<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>
<p><a href="/tags/#not-implemented" class="md-tag">not implemented</a></p></details>
<p><a href="/website-wiki/tags/#not-implemented" class="md-tag">not implemented</a></p></details>

- [Convert docs to markdown with existing add-on](not-implemented/convert-docs-to-markdown-with-existing-add-on.md)
- [Maintain design system webpages](not-implemented/maintain-design-system-webpages.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/roles/dev/decision-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See detailed instructions and templates for [adding new records](add-new-record.

<!-- TAGS='role: dev', 'adopted' BEGIN -->
<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>
<p><a href="/tags/#adopted" class="md-tag">adopted</a> <a href="/tags/#role-dev" class="md-tag">role: dev</a></p></details>
<p><a href="/website-wiki/tags/#role-dev" class="md-tag">role: dev</a> <a href="/website-wiki/tags/#adopted" class="md-tag">adopted</a></p></details>

- [Standardize HTML img tag](../../decision-records/adopted/standardize-html-img-tag.md)
- [Hide button on Toolkit page](../../decision-records/adopted/hide-button-on-toolkit-page.md)
Expand All @@ -27,7 +27,7 @@ See detailed instructions and templates for [adding new records](add-new-record.

<!-- TAGS='not implemented', 'role: dev' BEGIN -->
<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>
<p><a href="/tags/#not-implemented" class="md-tag">not implemented</a> <a href="/tags/#role-dev" class="md-tag">role: dev</a></p></details>
<p><a href="/website-wiki/tags/#not-implemented" class="md-tag">not implemented</a> <a href="/website-wiki/tags/#role-dev" class="md-tag">role: dev</a></p></details>

- [Prevent liquid injection attacks in markdown](../../decision-records/not-implemented/prevent-liquid-injection-attacks-in-markdown.md)
- [Fix PR GitHub Actions bug with labels and instructions](../../decision-records/not-implemented/fix-pr-github-actions-bug-with-labels-and-instructions.md)
Expand Down
20 changes: 12 additions & 8 deletions hooks/page_links_by_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import glob
import re

# Base path for the tags directory
base_path = "/website-wiki/"

# Go through each markdown file
for filepath in glob.glob("docs/**/*.md", recursive=True):
with open(filepath, "r", encoding="utf-8") as file:
Expand All @@ -20,14 +23,15 @@
required_tags = {tag.strip().strip("'") for tag in required_tags}

# Generate the heading with details and summary tags
# Use an absolute path for the href that always points to the root /tags/ directory
tag_names_with_links = " ".join(
[
f'<a href="/tags/#{tag.replace(": ", "-").replace(" ", "-")}" class="md-tag">{tag}</a>'
for tag in required_tags
]
)
heading = f'<!-- TAGS={match.group(1)} BEGIN -->\n<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>\n<p>{tag_names_with_links}</p></details>\n\n'
tag_names_with_links = []
for tag in required_tags:
# Construct the tag URL
tag_url = f'{base_path}tags/#{tag.replace(": ", "-").replace(" ", "-")}'
tag_names_with_links.append(
f'<a href="{tag_url}" class="md-tag">{tag}</a>'
)

heading = f'<!-- TAGS={match.group(1)} BEGIN -->\n<details class="md-tag-details"><summary class="md-tag-summary">Tags</summary>\n<p>{" ".join(tag_names_with_links)}</p></details>\n\n'

# List to store pages that meet the criteria
matching_pages = []
Expand Down

0 comments on commit 218aa66

Please sign in to comment.