Skip to content

Commit a6b2b0d

Browse files
committed
Remove trailing slash in docs
1 parent f2188df commit a6b2b0d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docs/hooks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import gzip
2+
import json
3+
import re
14
from datetime import date
25
from pathlib import Path
36
from urllib.request import urlretrieve
@@ -8,6 +11,29 @@
811
}
912

1013

14+
def on_post_build(config):
15+
site_dir = Path(config.site_dir)
16+
pattern = re.compile(r'(href="[^"]*)\.html(?=["#?])')
17+
for html_file in site_dir.rglob("*.html"):
18+
content = html_file.read_text()
19+
updated = pattern.sub(r"\1", content)
20+
if content != updated:
21+
html_file.write_text(updated)
22+
sitemap = site_dir / "sitemap.xml"
23+
if sitemap.exists():
24+
content = sitemap.read_text()
25+
sitemap.write_text(content.replace(".html</loc>", "</loc>"))
26+
sitemap_gz = site_dir / "sitemap.xml.gz"
27+
if sitemap_gz.exists():
28+
sitemap_gz.write_bytes(gzip.compress(sitemap.read_bytes()))
29+
search_index = site_dir / "search" / "search_index.json"
30+
if search_index.exists():
31+
data = json.loads(search_index.read_text())
32+
for doc in data.get("docs", []):
33+
doc["location"] = re.sub(r"\.html(?=[#?]|$)", "", doc.get("location", ""))
34+
search_index.write_text(json.dumps(data, separators=(",", ":")))
35+
36+
1137
def on_config(config):
1238
config.copyright = f"Copyright &copy; 2019-{date.today().year} MrNaif2018"
1339
img_dir = Path(config.theme.custom_dir) / "images"

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repo_name: bitcart/bitcart-sdk
66
site_dir: site
77
watch: [docs, mkdocs.yml, bitcart]
88
copyright: "Copyright &copy; 2019 MrNaif2018"
9+
use_directory_urls: false
910
hooks:
1011
- docs/hooks.py
1112

0 commit comments

Comments
 (0)