fr-docs 3.6.0__tar.gz → 5.1.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.
Files changed (27) hide show
  1. {fr_docs-3.6.0 → fr_docs-5.1.0}/PKG-INFO +1 -2
  2. {fr_docs-3.6.0 → fr_docs-5.1.0}/README.md +0 -1
  3. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/build.py +82 -2
  4. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/config.py +1 -0
  5. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/config_accessors.py +15 -0
  6. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/html_pipeline.py +14 -8
  7. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/markdown.py +91 -0
  8. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/update.py +37 -12
  9. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/utils.py +24 -0
  10. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/PKG-INFO +1 -2
  11. {fr_docs-3.6.0 → fr_docs-5.1.0}/pyproject.toml +1 -1
  12. {fr_docs-3.6.0 → fr_docs-5.1.0}/LICENSE.md +0 -0
  13. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/__init__.py +0 -0
  14. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/__main__.py +0 -0
  15. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/frontmatter.py +0 -0
  16. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/git.py +0 -0
  17. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/init.py +0 -0
  18. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/search.py +0 -0
  19. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/slug.py +0 -0
  20. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/syntax.py +0 -0
  21. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs/template.py +0 -0
  22. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/SOURCES.txt +0 -0
  23. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/dependency_links.txt +0 -0
  24. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/entry_points.txt +0 -0
  25. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/requires.txt +0 -0
  26. {fr_docs-3.6.0 → fr_docs-5.1.0}/fr_docs.egg-info/top_level.txt +0 -0
  27. {fr_docs-3.6.0 → fr_docs-5.1.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fr-docs
3
- Version: 3.6.0
3
+ Version: 5.1.0
4
4
  Summary: Fast static documentation generator with search, versioning, and zero-config setup
5
5
  Author-email: Omena0 <omena0mc@gmail.com>
6
6
  License: # PolyForm Noncommercial License 1.0.0
@@ -204,4 +204,3 @@ Fr-docs is a generic, configurable documentation builder for Python projects. It
204
204
 
205
205
  - [Fr-docs](https://omena0.dev/fr-docs/)
206
206
  - [PyJavaBridge](https://omena0.dev/PyJavaBridge)
207
- <sub><sup>(Legacy)</sup></sub>
@@ -44,4 +44,3 @@ Fr-docs is a generic, configurable documentation builder for Python projects. It
44
44
 
45
45
  - [Fr-docs](https://omena0.dev/fr-docs/)
46
46
  - [PyJavaBridge](https://omena0.dev/PyJavaBridge)
47
- <sub><sup>(Legacy)</sup></sub>
@@ -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:
@@ -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
@@ -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
- print(f" ✓ Symlinked {symlinked} files into {prefix}/")
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
 
@@ -11,6 +11,7 @@ DEFAULT_CONFIG = {
11
11
  "project_name": "Project Name",
12
12
  "copyright_holder": "CHANGE_ME",
13
13
  "project_url": "",
14
+ "site_url": "",
14
15
  "site_path_prefix": "/",
15
16
  "src_dir": "src",
16
17
  "out_dir": "site",
@@ -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-js",
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,91 @@ 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 process_footnotes(md_text):
112
+ """Process footnote definitions and references.
113
+
114
+ Converts ``[^tag]`` references into superscript links:
115
+ <a href="url" class="footnote-ref"><sup>n</sup></a>
116
+
117
+ Returns tuple of (processed_text, footnotes) where footnotes is a list
118
+ of {tag, url, title, index} dicts in reference order.
119
+ """
120
+ definitions = _extract_footnote_definitions(md_text)
121
+ if not definitions:
122
+ return md_text, []
123
+
124
+ footnotes = []
125
+ footnote_counter = {}
126
+
127
+ def _repl(m):
128
+ tag = m.group(1).strip()
129
+ if tag not in definitions:
130
+ return m.group(0)
131
+ if tag not in footnote_counter:
132
+ footnote_counter[tag] = len(footnotes) + 1
133
+ idx = footnote_counter[tag]
134
+ # Avoid duplicate entries for the same tag
135
+ if not any(fn["tag"] == tag for fn in footnotes):
136
+ footnotes.append(
137
+ {
138
+ "tag": tag,
139
+ "url": definitions[tag]["url"],
140
+ "title": definitions[tag]["title"],
141
+ "index": idx,
142
+ }
143
+ )
144
+ return f'<a href="#fnref-{tag}" class="footnote-ref"><sup>{idx}</sup></a>'
145
+
146
+ # Remove definition lines from text before returning processed text
147
+ processed_text = FOOTNOTE_REF_RE.sub(_repl, md_text)
148
+ # Remove footnote definition lines (both inline and standalone)
149
+ processed_text = re.sub(
150
+ r"(?m)^\[([^\]]+)\]:\s*\S+.*(?:\n?)$", "", processed_text
151
+ )
152
+ processed_text = re.sub(r"\n{3,}", "\n\n", processed_text)
153
+
154
+ return processed_text, footnotes
155
+
156
+
157
+ def build_footnotes_html(footnotes):
158
+ """Build the footnotes HTML section for a page.
159
+
160
+ The section is appended before the footer content in the page body.
161
+ """
162
+ if not footnotes:
163
+ return ""
164
+ items = []
165
+ for fn in footnotes:
166
+ title = fn.get("title") or fn.get("url") or ""
167
+ items.append(
168
+ f'<li id="fnref-{fn.get("tag")}" class="footnote-item">'
169
+ f'<a href="{fn.get("url")}" class="footnote-link" title="{html.escape(title)}">'
170
+ f"{html.escape(title)}</a></li>"
171
+ )
172
+ inner = "".join(items)
173
+ return (
174
+ '<div class="footnotes">'
175
+ '<h2 class="footnotes-heading">Footnotes</h2>'
176
+ f'<ol class="footnotes-list">{inner}</ol>'
177
+ "</div>"
178
+ )
179
+
180
+
90
181
  def resolve_md_target(md_target, current_slug, slug_page_keys):
91
182
  """Resolve a markdown link target to a page-relative output HTML filename.
92
183
 
@@ -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
- with tempfile.NamedTemporaryFile(mode="w+", suffix=".js", delete=False) as tmp:
33
- tmp_path = Path(tmp.name)
34
- try:
35
- if download_file(SCRIPT_JS_URL, tmp_path):
36
- version, _ = _script_version_hash(tmp_path)
37
- content = tmp_path.read_text(encoding="utf-8")
38
- local_path = docs_path / "script.js"
39
- _write_script_js(local_path, version, content)
40
- updated.append(f"script.js (v{version})")
41
- finally:
42
- tmp_path.unlink(missing_ok=True)
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 + "/"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fr-docs
3
- Version: 3.6.0
3
+ Version: 5.1.0
4
4
  Summary: Fast static documentation generator with search, versioning, and zero-config setup
5
5
  Author-email: Omena0 <omena0mc@gmail.com>
6
6
  License: # PolyForm Noncommercial License 1.0.0
@@ -204,4 +204,3 @@ Fr-docs is a generic, configurable documentation builder for Python projects. It
204
204
 
205
205
  - [Fr-docs](https://omena0.dev/fr-docs/)
206
206
  - [PyJavaBridge](https://omena0.dev/PyJavaBridge)
207
- <sub><sup>(Legacy)</sup></sub>
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "fr-docs"
9
- version = "3.6.0"
9
+ version = "5.1.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