fr-docs 4.6.0__tar.gz → 5.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fr_docs-4.6.0 → fr_docs-5.2.0}/PKG-INFO +1 -1
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/build.py +87 -7
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/config.py +1 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/config_accessors.py +15 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/html_pipeline.py +14 -8
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/markdown.py +120 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/update.py +37 -12
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/utils.py +24 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/PKG-INFO +1 -1
- {fr_docs-4.6.0 → fr_docs-5.2.0}/pyproject.toml +1 -1
- {fr_docs-4.6.0 → fr_docs-5.2.0}/LICENSE.md +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/README.md +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/__init__.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/__main__.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/frontmatter.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/git.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/init.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/search.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/slug.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/syntax.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs/template.py +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/SOURCES.txt +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/dependency_links.txt +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/entry_points.txt +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/requires.txt +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/fr_docs.egg-info/top_level.txt +0 -0
- {fr_docs-4.6.0 → fr_docs-5.2.0}/setup.cfg +0 -0
|
@@ -7,6 +7,7 @@ Converts Markdown source files into a static HTML site using configuration.
|
|
|
7
7
|
import argparse
|
|
8
8
|
import concurrent.futures
|
|
9
9
|
import contextlib
|
|
10
|
+
import datetime
|
|
10
11
|
import glob
|
|
11
12
|
import json
|
|
12
13
|
import os
|
|
@@ -27,6 +28,7 @@ from .config_accessors import (
|
|
|
27
28
|
project_name,
|
|
28
29
|
search_index_filename,
|
|
29
30
|
sidebar,
|
|
31
|
+
site_url,
|
|
30
32
|
workers,
|
|
31
33
|
zstd_level,
|
|
32
34
|
)
|
|
@@ -41,7 +43,7 @@ from .slug import (
|
|
|
41
43
|
slug_output_name,
|
|
42
44
|
)
|
|
43
45
|
from .syntax import highlight_source_lines
|
|
44
|
-
from .utils import normalized_site_prefix
|
|
46
|
+
from .utils import canonical_url, normalized_site_prefix
|
|
45
47
|
|
|
46
48
|
|
|
47
49
|
def _compute_hash(data: str) -> str:
|
|
@@ -60,9 +62,9 @@ def _best_zstd_level(raw: bytes, configured: int) -> int:
|
|
|
60
62
|
if len(raw) < 1024:
|
|
61
63
|
return min(configured, 19)
|
|
62
64
|
|
|
63
|
-
best_level, best_size = 1, len(zstandard.ZstdCompressor(level=1).compress(raw))
|
|
65
|
+
best_level, best_size = 1, len(zstandard.ZstdCompressor(level=1, threads=16).compress(raw))
|
|
64
66
|
for level in range(2, configured + 1):
|
|
65
|
-
size = len(zstandard.ZstdCompressor(level=level).compress(raw))
|
|
67
|
+
size = len(zstandard.ZstdCompressor(level=level, threads=16).compress(raw))
|
|
66
68
|
if size < best_size:
|
|
67
69
|
best_level, best_size = level, size
|
|
68
70
|
return best_level
|
|
@@ -305,7 +307,7 @@ def _write_zstd_json(config, filename, value):
|
|
|
305
307
|
return len(raw), src.stat().st_size
|
|
306
308
|
|
|
307
309
|
compressed = zstandard.ZstdCompressor(
|
|
308
|
-
level=_best_zstd_level(raw, zstd_level(config))
|
|
310
|
+
level=_best_zstd_level(raw, zstd_level(config)), threads=16
|
|
309
311
|
).compress(raw)
|
|
310
312
|
path = Path(config["_out_dir"]) / filename
|
|
311
313
|
path.write_bytes(compressed)
|
|
@@ -457,6 +459,76 @@ def collect_source_files(config):
|
|
|
457
459
|
return source_files
|
|
458
460
|
|
|
459
461
|
|
|
462
|
+
def _build_sitemap_urls(slugs, config):
|
|
463
|
+
"""Build a list of canonical sitemap URLs for all pages.
|
|
464
|
+
|
|
465
|
+
Each URL ends with a trailing slash so it matches the canonical URL
|
|
466
|
+
served by static hosting (e.g. GitHub Pages rewrites ``/fr-os`` to
|
|
467
|
+
``/fr-os/``, and a sitemap URL without the trailing slash would
|
|
468
|
+
trigger a redirect — which Google rejects).
|
|
469
|
+
"""
|
|
470
|
+
site_url_val = site_url(config) or ""
|
|
471
|
+
if not site_url_val:
|
|
472
|
+
return []
|
|
473
|
+
|
|
474
|
+
urls = []
|
|
475
|
+
for slug in slugs:
|
|
476
|
+
canonical = canonical_url(slug, config)
|
|
477
|
+
if canonical:
|
|
478
|
+
urls.append(canonical)
|
|
479
|
+
return urls
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _write_sitemap(slugs, config):
|
|
483
|
+
"""Write sitemap.xml to the output directory.
|
|
484
|
+
|
|
485
|
+
Only generated when ``site_url`` is configured; otherwise there is
|
|
486
|
+
no canonical origin to report to crawlers.
|
|
487
|
+
"""
|
|
488
|
+
if not config.get("production", False):
|
|
489
|
+
return
|
|
490
|
+
site_url_val = site_url(config) or ""
|
|
491
|
+
out_dir = Path(config["_out_dir"])
|
|
492
|
+
sitemap_path = out_dir / "sitemap.xml"
|
|
493
|
+
|
|
494
|
+
if not site_url_val:
|
|
495
|
+
sitemap_path.unlink(missing_ok=True)
|
|
496
|
+
return
|
|
497
|
+
|
|
498
|
+
urls = _build_sitemap_urls(slugs, config)
|
|
499
|
+
now = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%S+00:00")
|
|
500
|
+
|
|
501
|
+
parts = [
|
|
502
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
503
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
504
|
+
*[f" <url><loc>{url}</loc><lastmod>{now}</lastmod></url>" for url in urls],
|
|
505
|
+
"</urlset>",
|
|
506
|
+
]
|
|
507
|
+
|
|
508
|
+
sitemap_path.write_text("\n".join(parts), encoding="utf-8")
|
|
509
|
+
print(f" Sitemap: {len(urls)} URLs → sitemap.xml")
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def _write_robots(config):
|
|
513
|
+
"""Write robots.txt to the output directory.
|
|
514
|
+
|
|
515
|
+
If ``docs/robots.txt`` exists it is copied verbatim. Otherwise a
|
|
516
|
+
default permissive policy is written to ``site/robots.txt``.
|
|
517
|
+
"""
|
|
518
|
+
out_dir = Path(config["_out_dir"])
|
|
519
|
+
docs_path = Path(config["_docs_dir"])
|
|
520
|
+
robots_path = out_dir / "robots.txt"
|
|
521
|
+
|
|
522
|
+
src_robots = docs_path / "robots.txt"
|
|
523
|
+
if src_robots.is_file():
|
|
524
|
+
shutil.copyfile(src_robots, robots_path)
|
|
525
|
+
print(" robots.txt: copied from docs/")
|
|
526
|
+
return
|
|
527
|
+
|
|
528
|
+
robots_path.write_text("User-agent: *\nAllow: /\n", encoding="utf-8")
|
|
529
|
+
print(" robots.txt: default allow-all")
|
|
530
|
+
|
|
531
|
+
|
|
460
532
|
def main(argv=None) -> None:
|
|
461
533
|
if argv is not None and argv and argv[0] == "build":
|
|
462
534
|
argv = argv[1:]
|
|
@@ -528,6 +600,7 @@ def main(argv=None) -> None:
|
|
|
528
600
|
"symbol_index.json",
|
|
529
601
|
):
|
|
530
602
|
Path(config["_out_dir"], legacy_name).unlink(missing_ok=True)
|
|
603
|
+
|
|
531
604
|
for name in ("favicon.svg", "fonts.css", "style.css"):
|
|
532
605
|
src = docs_path / name
|
|
533
606
|
dst = Path(config["_out_dir"]) / name
|
|
@@ -601,7 +674,7 @@ def main(argv=None) -> None:
|
|
|
601
674
|
# Compress search index
|
|
602
675
|
search_raw = json.dumps(search_index, separators=(",", ":")).encode("utf-8")
|
|
603
676
|
compressed = zstandard.ZstdCompressor(
|
|
604
|
-
level=_best_zstd_level(search_raw, zstd_level(config))
|
|
677
|
+
level=_best_zstd_level(search_raw, zstd_level(config)), threads=16
|
|
605
678
|
).compress(search_raw)
|
|
606
679
|
search_index_path = Path(config["_out_dir"], search_index_filename(config))
|
|
607
680
|
search_index_path.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -659,7 +732,7 @@ def main(argv=None) -> None:
|
|
|
659
732
|
"utf-8"
|
|
660
733
|
)
|
|
661
734
|
compressed = zstandard.ZstdCompressor(
|
|
662
|
-
level=_best_zstd_level(raw, zstd_level(config))
|
|
735
|
+
level=_best_zstd_level(raw, zstd_level(config)), threads=16
|
|
663
736
|
).compress(raw)
|
|
664
737
|
highlight_cache_file.parent.mkdir(parents=True, exist_ok=True)
|
|
665
738
|
highlight_cache_file.write_bytes(compressed)
|
|
@@ -793,10 +866,17 @@ def main(argv=None) -> None:
|
|
|
793
866
|
link_path.unlink()
|
|
794
867
|
link_path.symlink_to(f.resolve())
|
|
795
868
|
symlinked += 1
|
|
796
|
-
|
|
869
|
+
gitignore_path = prefix_dir / ".gitignore"
|
|
870
|
+
gitignore_path.write_text("*\n!.gitignore\n", encoding="utf-8")
|
|
871
|
+
print(f" ✓ Created .gitignore in {prefix}/")
|
|
797
872
|
except OSError as e:
|
|
798
873
|
print(f" ✗ Failed to create {prefix}/ symlinks: {e}")
|
|
799
874
|
|
|
875
|
+
# Generate sitemap.xml and robots.txt for production builds
|
|
876
|
+
if config.get("production", False):
|
|
877
|
+
_write_sitemap(slugs, config)
|
|
878
|
+
_write_robots(config)
|
|
879
|
+
|
|
800
880
|
print(f"\n✅ Built {built} pages")
|
|
801
881
|
|
|
802
882
|
|
|
@@ -203,6 +203,21 @@ def project_url(config):
|
|
|
203
203
|
return config.get("project_url", "")
|
|
204
204
|
|
|
205
205
|
|
|
206
|
+
def site_url(config):
|
|
207
|
+
"""Return the canonical site URL (with trailing slash).
|
|
208
|
+
|
|
209
|
+
Used to build sitemap URLs. Must be explicitly configured in
|
|
210
|
+
``config.json`` as ``"site_url": "https://example.com/"``.
|
|
211
|
+
Falls back to empty string when not set.
|
|
212
|
+
"""
|
|
213
|
+
url = str(config.get("site_url", "")).strip()
|
|
214
|
+
if not url:
|
|
215
|
+
return ""
|
|
216
|
+
if not url.endswith("/"):
|
|
217
|
+
url += "/"
|
|
218
|
+
return url
|
|
219
|
+
|
|
220
|
+
|
|
206
221
|
def src_map_path(config) -> str:
|
|
207
222
|
"""Return the source markdown path pattern used in git metadata."""
|
|
208
223
|
return f"{src_dir(config)}/{{slug}}.md"
|
|
@@ -30,8 +30,10 @@ from .frontmatter import parse_frontmatter
|
|
|
30
30
|
from .markdown import (
|
|
31
31
|
auto_link_filenames,
|
|
32
32
|
auto_link_markdown,
|
|
33
|
+
build_footnotes_html,
|
|
33
34
|
convert_markdown,
|
|
34
35
|
process_code_references_html,
|
|
36
|
+
process_footnotes,
|
|
35
37
|
rewrite_md_links,
|
|
36
38
|
)
|
|
37
39
|
from .search import search_include_config
|
|
@@ -221,14 +223,10 @@ def minify_html(html_input, config):
|
|
|
221
223
|
cmd = [
|
|
222
224
|
"npx",
|
|
223
225
|
"html-minifier-next",
|
|
224
|
-
"--minify-css",
|
|
225
|
-
"true",
|
|
226
|
-
"--minify-
|
|
227
|
-
"true",
|
|
228
|
-
"--minify-svg",
|
|
229
|
-
"true",
|
|
230
|
-
"--minify-urls",
|
|
231
|
-
"true",
|
|
226
|
+
"--minify-css", "true",
|
|
227
|
+
"--minify-js", "true",
|
|
228
|
+
"--minify-svg", "true",
|
|
229
|
+
"--minify-urls", "true",
|
|
232
230
|
"--remove-attribute-quotes",
|
|
233
231
|
"--collapse-whitespace",
|
|
234
232
|
"--remove-tag-whitespace",
|
|
@@ -328,6 +326,9 @@ def build_page(slug, config, slug_page_keys) -> None:
|
|
|
328
326
|
if config.get("search_map") and feature_enabled(config, "auto_link"):
|
|
329
327
|
body_md = auto_link_markdown(body_md, config["search_map"])
|
|
330
328
|
|
|
329
|
+
# Process footnote definitions and references before markdown conversion
|
|
330
|
+
body_md, footnotes = process_footnotes(body_md)
|
|
331
|
+
|
|
331
332
|
body_html, toc_tokens = convert_markdown(body_md)
|
|
332
333
|
body_html = rewrite_md_links(body_html, slug, slug_page_keys)
|
|
333
334
|
|
|
@@ -345,6 +346,11 @@ def build_page(slug, config, slug_page_keys) -> None:
|
|
|
345
346
|
body_md, body_html, slug, config, search_index
|
|
346
347
|
)
|
|
347
348
|
|
|
349
|
+
# Append footnotes section before footer
|
|
350
|
+
footnotes_html = build_footnotes_html(footnotes)
|
|
351
|
+
if footnotes_html:
|
|
352
|
+
body_html += footnotes_html
|
|
353
|
+
|
|
348
354
|
subtitle_html = f'<p class="subtitle">{subtitle}</p>' if subtitle else ""
|
|
349
355
|
tagged_sections = _determine_tagged_sections(config)
|
|
350
356
|
sidebar_html = build_toc_sidebar(
|
|
@@ -20,6 +20,12 @@ _DECORATORS_DEST = "decorators"
|
|
|
20
20
|
|
|
21
21
|
_MD_LOCAL = threading.local()
|
|
22
22
|
|
|
23
|
+
# Footnote reference pattern: [^tag]
|
|
24
|
+
FOOTNOTE_REF_RE = re.compile(r"\[\^([^\]]+)\]")
|
|
25
|
+
|
|
26
|
+
# Footnote definition pattern: [tag]: URL "title"
|
|
27
|
+
FOOTNOTE_DEF_RE = re.compile(r"^\[([^\]]+)\]:\s*(\S+)(?:\s+\"([^\"]*)\")?\s*$", re.MULTILINE)
|
|
28
|
+
|
|
23
29
|
CODE_REF_TARGET = r"(?::(?P<location>[^)]+))?"
|
|
24
30
|
CODE_REF_RE = re.compile(
|
|
25
31
|
r"\[(?P<link_text>[^\]]+)\]\((?P<file>[a-zA-Z0-9_./\\-]+\.(?:py|js|ts|tsx|jsx|java|cpp|c|h|hpp|rs|go|rb|php|cs|kt|swift|scala|clj|hs|ml|fs|vim|sh|bash|zsh|fish|ps1|bat|cmd|sql|xml|json|yaml|yml|toml|ini|cfg|conf|css|scss|sass|less|styl|vue|svelte|astro|mdx))"
|
|
@@ -87,6 +93,120 @@ def convert_markdown(text):
|
|
|
87
93
|
return html_out, toc_tokens
|
|
88
94
|
|
|
89
95
|
|
|
96
|
+
def _extract_footnote_definitions(md_text):
|
|
97
|
+
"""Extract footnote definitions from markdown text.
|
|
98
|
+
|
|
99
|
+
Definitions look like: [tag]: https://example.com/ "Title"
|
|
100
|
+
Returns a dict mapping tag -> {"url": ..., "title": ...}
|
|
101
|
+
"""
|
|
102
|
+
definitions = {}
|
|
103
|
+
for m in FOOTNOTE_DEF_RE.finditer(md_text):
|
|
104
|
+
tag = m.group(1).strip()
|
|
105
|
+
url = m.group(2)
|
|
106
|
+
title = (m.group(3) or "").strip()
|
|
107
|
+
definitions[tag] = {"url": url, "title": title}
|
|
108
|
+
return definitions
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _add_footnote_commas(html_text):
|
|
112
|
+
"""Add commas between consecutive footnote reference links.
|
|
113
|
+
|
|
114
|
+
``[^tag1][^tag2]`` renders as ``<a>2</a><a>3</a>`` which reads as "23";
|
|
115
|
+
insert a comma so it reads "2,3".
|
|
116
|
+
"""
|
|
117
|
+
return re.sub(
|
|
118
|
+
r'(<sup>\d+</sup></a>)(<a href="#fnref-[^"]+" class="footnote-ref">)',
|
|
119
|
+
r'\1,\2',
|
|
120
|
+
html_text,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def process_footnotes(md_text):
|
|
125
|
+
"""Process footnote definitions and references.
|
|
126
|
+
|
|
127
|
+
Converts ``[^tag]`` references into superscript links:
|
|
128
|
+
<a href="url" class="footnote-ref"><sup>n</sup></a>
|
|
129
|
+
|
|
130
|
+
Returns tuple of (processed_text, footnotes) where footnotes is a list
|
|
131
|
+
of {tag, url, title, index} dicts in reference order.
|
|
132
|
+
"""
|
|
133
|
+
definitions = _extract_footnote_definitions(md_text)
|
|
134
|
+
if not definitions:
|
|
135
|
+
return md_text, []
|
|
136
|
+
|
|
137
|
+
footnotes = []
|
|
138
|
+
footnote_counter = {}
|
|
139
|
+
|
|
140
|
+
def _repl(m):
|
|
141
|
+
tag = m.group(1).strip()
|
|
142
|
+
if tag not in definitions:
|
|
143
|
+
return m.group(0)
|
|
144
|
+
if tag not in footnote_counter:
|
|
145
|
+
footnote_counter[tag] = len(footnotes) + 1
|
|
146
|
+
idx = footnote_counter[tag]
|
|
147
|
+
# Avoid duplicate entries for the same tag
|
|
148
|
+
if not any(fn["tag"] == tag for fn in footnotes):
|
|
149
|
+
footnotes.append(
|
|
150
|
+
{
|
|
151
|
+
"tag": tag,
|
|
152
|
+
"url": definitions[tag]["url"],
|
|
153
|
+
"title": definitions[tag]["title"],
|
|
154
|
+
"index": idx,
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
return f'<a href="#fnref-{tag}" class="footnote-ref"><sup>{idx}</sup></a>'
|
|
158
|
+
|
|
159
|
+
# Replace footnote references [^tag] with HTML links
|
|
160
|
+
processed_text = FOOTNOTE_REF_RE.sub(_repl, md_text)
|
|
161
|
+
|
|
162
|
+
# Only remove definition lines for tags that are actually footnote tags
|
|
163
|
+
# (referenced with [^tag]). Keep standard markdown reference link
|
|
164
|
+
# definitions ([ref]: URL ...) intact so [text][ref] links resolve.
|
|
165
|
+
footnote_ref_tags = set(FOOTNOTE_REF_RE.findall(md_text))
|
|
166
|
+
|
|
167
|
+
def _remove_fn_def(m):
|
|
168
|
+
tag = m.group(1)
|
|
169
|
+
if tag in footnote_ref_tags:
|
|
170
|
+
return ""
|
|
171
|
+
return m.group(0)
|
|
172
|
+
|
|
173
|
+
processed_text = re.sub(
|
|
174
|
+
r"(?m)^\[([^\]]+)\]:\s*\S+.*(?:\n?)$",
|
|
175
|
+
_remove_fn_def,
|
|
176
|
+
processed_text,
|
|
177
|
+
)
|
|
178
|
+
processed_text = re.sub(r"\n{3,}", "\n\n", processed_text)
|
|
179
|
+
|
|
180
|
+
# Add commas between consecutive footnote references
|
|
181
|
+
processed_text = _add_footnote_commas(processed_text)
|
|
182
|
+
|
|
183
|
+
return processed_text, footnotes
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def build_footnotes_html(footnotes):
|
|
187
|
+
"""Build the footnotes HTML section for a page.
|
|
188
|
+
|
|
189
|
+
The section is appended before the footer content in the page body.
|
|
190
|
+
"""
|
|
191
|
+
if not footnotes:
|
|
192
|
+
return ""
|
|
193
|
+
items = []
|
|
194
|
+
for fn in footnotes:
|
|
195
|
+
title = fn.get("title") or fn.get("url") or ""
|
|
196
|
+
items.append(
|
|
197
|
+
f'<li id="fnref-{fn.get("tag")}" class="footnote-item">'
|
|
198
|
+
f'<a href="{fn.get("url")}" class="footnote-link" title="{html.escape(title)}">'
|
|
199
|
+
f"{html.escape(title)}</a></li>"
|
|
200
|
+
)
|
|
201
|
+
inner = "".join(items)
|
|
202
|
+
return (
|
|
203
|
+
'<div class="footnotes">'
|
|
204
|
+
'<h2 class="footnotes-heading">Footnotes</h2>'
|
|
205
|
+
f'<ol class="footnotes-list">{inner}</ol>'
|
|
206
|
+
"</div>"
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
|
|
90
210
|
def resolve_md_target(md_target, current_slug, slug_page_keys):
|
|
91
211
|
"""Resolve a markdown link target to a page-relative output HTML filename.
|
|
92
212
|
|
|
@@ -4,6 +4,7 @@ import tempfile
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
6
|
from .build import (
|
|
7
|
+
_git_script_versions,
|
|
7
8
|
_script_version_hash,
|
|
8
9
|
_write_script_js,
|
|
9
10
|
)
|
|
@@ -18,6 +19,29 @@ from .init import (
|
|
|
18
19
|
)
|
|
19
20
|
|
|
20
21
|
|
|
22
|
+
def _script_update_needed(local_path, remote_version):
|
|
23
|
+
"""Return True if local script.js should be updated to the given version.
|
|
24
|
+
|
|
25
|
+
Mirrors the version logic:
|
|
26
|
+
- If local has no version but matches a known historical blob, adopt that version.
|
|
27
|
+
- Update if the local version is missing or lower than the latest (remote_version).
|
|
28
|
+
- Never update if the latest version is identical to the local version (no-op).
|
|
29
|
+
"""
|
|
30
|
+
local_version, local_hash = _script_version_hash(local_path)
|
|
31
|
+
effective_local_version = local_version
|
|
32
|
+
|
|
33
|
+
if local_version == 0:
|
|
34
|
+
docs_dir = local_path.parent.parent
|
|
35
|
+
script_rel = str(local_path.relative_to(docs_dir)) + "/script.js"
|
|
36
|
+
hist = _git_script_versions(docs_dir, script_rel)
|
|
37
|
+
for ver, h in hist:
|
|
38
|
+
if h == local_hash and ver > 0:
|
|
39
|
+
effective_local_version = ver
|
|
40
|
+
break
|
|
41
|
+
|
|
42
|
+
return remote_version > effective_local_version
|
|
43
|
+
|
|
44
|
+
|
|
21
45
|
def update_resources(config):
|
|
22
46
|
"""Update script.js, style.css, favicon.svg, and fonts from the fr-docs upstream repo.
|
|
23
47
|
|
|
@@ -29,17 +53,19 @@ def update_resources(config):
|
|
|
29
53
|
updated = []
|
|
30
54
|
|
|
31
55
|
# Update script.js
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
local_script = docs_path / "script.js"
|
|
57
|
+
if local_script.exists():
|
|
58
|
+
with tempfile.NamedTemporaryFile(mode="w+", suffix=".js", delete=False) as tmp:
|
|
59
|
+
tmp_path = Path(tmp.name)
|
|
60
|
+
try:
|
|
61
|
+
if download_file(SCRIPT_JS_URL, tmp_path):
|
|
62
|
+
remote_version, _ = _script_version_hash(tmp_path)
|
|
63
|
+
if _script_update_needed(local_script, remote_version):
|
|
64
|
+
content = tmp_path.read_text(encoding="utf-8")
|
|
65
|
+
_write_script_js(local_script, remote_version, content)
|
|
66
|
+
updated.append(f"script.js (v{remote_version})")
|
|
67
|
+
finally:
|
|
68
|
+
tmp_path.unlink(missing_ok=True)
|
|
43
69
|
|
|
44
70
|
# Update style.css
|
|
45
71
|
local_style = docs_path / "style.css"
|
|
@@ -81,7 +107,6 @@ def main(argv=None) -> None:
|
|
|
81
107
|
help="Path to the configuration JSON file.",
|
|
82
108
|
)
|
|
83
109
|
args = parser.parse_args(argv)
|
|
84
|
-
|
|
85
110
|
config = load_config(args.config)
|
|
86
111
|
print(f"🔄 Updating {project_name(config)} resources...")
|
|
87
112
|
update_resources(config)
|
|
@@ -33,3 +33,27 @@ def output_asset_href(path, config):
|
|
|
33
33
|
clean = str(path or "").lstrip("/")
|
|
34
34
|
prefix = normalized_site_prefix(config)
|
|
35
35
|
return prefix + clean if prefix else "/" + clean
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def canonical_url(slug, config):
|
|
39
|
+
"""Return the canonical URL for a page slug with a trailing slash.
|
|
40
|
+
|
|
41
|
+
Used for sitemaps and ``<link rel="canonical">``. Each URL ends with
|
|
42
|
+
a trailing slash so it matches the canonical URL served by static
|
|
43
|
+
hosting (e.g. GitHub Pages rewrites ``/fr-os`` to ``/fr-os/``, and a
|
|
44
|
+
sitemap URL without the trailing slash would trigger a redirect —
|
|
45
|
+
which Google rejects).
|
|
46
|
+
|
|
47
|
+
The ``site_url`` config value should be the full base URL including any
|
|
48
|
+
path prefix (e.g. ``https://example.com/docs/``).
|
|
49
|
+
"""
|
|
50
|
+
site_url = str(config.get("site_url", "")).strip()
|
|
51
|
+
if not site_url:
|
|
52
|
+
return ""
|
|
53
|
+
if not site_url.endswith("/"):
|
|
54
|
+
site_url += "/"
|
|
55
|
+
|
|
56
|
+
clean = str(slug or "").lstrip("/")
|
|
57
|
+
if clean in ("", "index"):
|
|
58
|
+
return site_url
|
|
59
|
+
return site_url + clean + "/"
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "fr-docs"
|
|
9
|
-
version = "
|
|
9
|
+
version = "5.2.0"
|
|
10
10
|
description = "Fast static documentation generator with search, versioning, and zero-config setup"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.14"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|