Fix broken docs language links (#6323)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f767aa13ae
commit
ec977f6ca7
32 changed files with 139 additions and 126 deletions
|
|
@ -51,20 +51,26 @@ def build_docs():
|
|||
|
||||
|
||||
def update_html_links():
|
||||
"""Update href links in HTML files to remove '.md', excluding links starting with 'https://'."""
|
||||
html_files = SITE.rglob('*.html')
|
||||
"""Update href links in HTML files to remove '.md' and '/index.md', excluding links starting with 'https://'."""
|
||||
html_files = Path(SITE).rglob('*.html')
|
||||
total_updated_links = 0
|
||||
|
||||
for html_file in html_files:
|
||||
with open(html_file, 'r+', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
# Find all links to be updated, excluding those starting with 'https://'
|
||||
links_to_update = re.findall(r'href="(?!https://)([^"]+)\.md"', content)
|
||||
links_to_update = re.findall(r'href="(?!https://)([^"]+?)(/index)?\.md"', content)
|
||||
|
||||
# Update the content and count the number of links updated
|
||||
updated_content, number_of_links_updated = re.subn(r'href="(?!https://)([^"]+)\.md"', r'href="\1"', content)
|
||||
updated_content, number_of_links_updated = re.subn(r'href="(?!https://)([^"]+?)(/index)?\.md"',
|
||||
r'href="\1"', content)
|
||||
total_updated_links += number_of_links_updated
|
||||
|
||||
# Special handling for '/index' links
|
||||
updated_content, number_of_index_links_updated = re.subn(r'href="([^"]+)/index"', r'href="\1/"',
|
||||
updated_content)
|
||||
total_updated_links += number_of_index_links_updated
|
||||
|
||||
# Write the updated content back to the file
|
||||
file.seek(0)
|
||||
file.write(updated_content)
|
||||
|
|
@ -72,7 +78,7 @@ def update_html_links():
|
|||
|
||||
# Print updated links for this file
|
||||
for link in links_to_update:
|
||||
print(f'Updated link in {html_file}: {link}')
|
||||
print(f'Updated link in {html_file}: {link[0]}')
|
||||
|
||||
print(f'Total number of links updated: {total_updated_links}')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue