fr-docs 5.2.0__tar.gz → 6.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-5.2.0 → fr_docs-6.1.0}/PKG-INFO +1 -1
  2. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/build.py +195 -155
  3. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/config.py +30 -10
  4. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/config_accessors.py +137 -1
  5. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/html_pipeline.py +684 -615
  6. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/markdown.py +38 -12
  7. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/search.py +76 -7
  8. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/slug.py +27 -8
  9. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/template.py +29 -24
  10. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/PKG-INFO +1 -1
  11. {fr_docs-5.2.0 → fr_docs-6.1.0}/pyproject.toml +5 -1
  12. {fr_docs-5.2.0 → fr_docs-6.1.0}/LICENSE.md +0 -0
  13. {fr_docs-5.2.0 → fr_docs-6.1.0}/README.md +0 -0
  14. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/__init__.py +0 -0
  15. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/__main__.py +0 -0
  16. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/frontmatter.py +0 -0
  17. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/git.py +0 -0
  18. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/init.py +0 -0
  19. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/syntax.py +0 -0
  20. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/update.py +0 -0
  21. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/utils.py +0 -0
  22. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/SOURCES.txt +0 -0
  23. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/dependency_links.txt +0 -0
  24. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/entry_points.txt +0 -0
  25. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/requires.txt +0 -0
  26. {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/top_level.txt +0 -0
  27. {fr_docs-5.2.0 → fr_docs-6.1.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fr-docs
3
- Version: 5.2.0
3
+ Version: 6.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
@@ -5,6 +5,7 @@ Converts Markdown source files into a static HTML site using configuration.
5
5
  """
6
6
 
7
7
  import argparse
8
+ import base64
8
9
  import concurrent.futures
9
10
  import contextlib
10
11
  import datetime
@@ -25,9 +26,8 @@ from .config import load_config
25
26
  from .config_accessors import (
26
27
  feature_enabled,
27
28
  out_dir,
29
+ page_sidebars,
28
30
  project_name,
29
- search_index_filename,
30
- sidebar,
31
31
  site_url,
32
32
  workers,
33
33
  zstd_level,
@@ -37,9 +37,13 @@ from .config_accessors import (
37
37
  )
38
38
  from .git import build_version_options, collect_git_metadata
39
39
  from .html_pipeline import build_page, minify_all_pages, optimize_all_pages
40
- from .search import build_search_index, search_include_config
40
+ from .search import (
41
+ build_all_page_search_indexes,
42
+ search_include_config,
43
+ )
41
44
  from .slug import (
42
45
  build_slug_page_keys,
46
+ page_slugs_from_sidebars,
43
47
  slug_output_name,
44
48
  )
45
49
  from .syntax import highlight_source_lines
@@ -346,117 +350,127 @@ def _process_pattern(pattern, search_dir, ignore_dirs, seen_paths, source_files)
346
350
  source_files[str(rel_path)] = file_path.read_text(encoding="utf-8")
347
351
 
348
352
 
349
- def collect_source_files(config):
350
- """Collect source code files for code reference feature using glob patterns."""
353
+ def collect_source_files(config) -> dict:
354
+ """Collect source code files for code reference feature using glob patterns.
355
+
356
+ Supports both the new per-page source_files format::
357
+
358
+ {"page_name": {"patterns": [...], "ignore": [...]}}
359
+
360
+ and the old flat format (single page, backward compatible)::
361
+
362
+ {"patterns": [...], "ignore_dirs": [...]}
351
363
 
352
- source_files = {}
364
+ When per-page format is used, patterns from all pages are aggregated.
365
+ """
366
+ source_files: dict = {}
353
367
  docs_path = Path(config["_docs_dir"])
354
368
  src_dir_path = Path(config["_src_dir"])
355
369
  source_config = config.get("source_files", {})
356
370
 
357
- # Resolve search directories
358
- search_dirs_raw = source_config.get("search_dirs", ["parent", "src_parent", "docs"])
359
- search_dirs = []
360
- for sd in search_dirs_raw:
361
- if sd == "parent":
362
- search_dirs.append(docs_path.parent)
363
- elif sd == "src_parent":
364
- search_dirs.append(src_dir_path.parent)
365
- elif sd == "docs":
366
- search_dirs.append(docs_path)
367
- elif Path(sd).exists():
368
- search_dirs.append(Path(sd))
369
-
370
- # Get glob patterns from config
371
- patterns = source_config.get(
372
- "patterns",
373
- [
374
- "**/*.py",
375
- "**/*.js",
376
- "**/*.ts",
377
- "**/*.tsx",
378
- "**/*.jsx",
379
- "**/*.java",
380
- "**/*.cpp",
381
- "**/*.c",
382
- "**/*.h",
383
- "**/*.hpp",
384
- "**/*.rs",
385
- "**/*.go",
386
- "**/*.rb",
387
- "**/*.php",
388
- "**/*.cs",
389
- "**/*.kt",
390
- "**/*.swift",
391
- "**/*.scala",
392
- "**/*.clj",
393
- "**/*.hs",
394
- "**/*.ml",
395
- "**/*.fs",
396
- "**/*.vim",
397
- "**/*.sh",
398
- "**/*.bash",
399
- "**/*.zsh",
400
- "**/*.fish",
401
- "**/*.ps1",
402
- "**/*.bat",
403
- "**/*.cmd",
404
- "**/*.sql",
405
- "**/*.html",
406
- "**/*.htm",
407
- "**/*.xml",
408
- "**/*.json",
409
- "**/*.yaml",
410
- "**/*.yml",
411
- "**/*.toml",
412
- "**/*.ini",
413
- "**/*.cfg",
414
- "**/*.conf",
415
- "**/*.md",
416
- "**/*.txt",
417
- "**/*.rst",
418
- "**/*.css",
419
- "**/*.scss",
420
- "**/*.sass",
421
- "**/*.less",
422
- "**/*.styl",
423
- "**/*.vue",
424
- "**/*.svelte",
425
- "**/*.astro",
426
- "**/*.mdx",
427
- ],
428
- )
429
-
430
- # Get ignore dirs from config
431
- ignore_dirs = set(
432
- source_config.get(
433
- "ignore_dirs",
434
- [
435
- "__pycache__",
436
- "node_modules",
437
- "venv",
438
- "env",
439
- ".git",
440
- "dist",
441
- "build",
442
- "target",
443
- "out",
444
- "site",
445
- ],
446
- )
447
- )
448
-
449
- seen_paths = set()
450
- for search_dir in search_dirs:
451
- if not search_dir.exists():
452
- continue
453
- with contextlib.suppress(OSError):
371
+ # Normalize to a list of (page_name, {patterns, ignore}) entries.
372
+ if isinstance(source_config, dict) and (
373
+ "patterns" in source_config
374
+ or "search_dirs" in source_config
375
+ or "ignore_dirs" in source_config
376
+ ):
377
+ # Old flat format — single page
378
+ page_configs: list[tuple[str, dict]] = [
379
+ ("default", source_config),
380
+ ]
381
+ elif isinstance(source_config, dict):
382
+ # New per-page format
383
+ page_configs = [
384
+ (page_name, pc if isinstance(pc, dict) else {})
385
+ for page_name, pc in source_config.items()
386
+ ]
387
+ else:
388
+ page_configs = [("default", {})]
389
+
390
+ seen_paths: set[str] = set()
391
+ for _page_name, page_cfg in page_configs:
392
+ patterns = page_cfg.get("patterns", [])
393
+ ignore_dirs = set(page_cfg.get("ignore", []))
394
+
395
+ # Resolve search directories
396
+ search_dirs_raw = page_cfg.get("search_dirs", ["parent", "src_parent", "docs"])
397
+ search_dirs = []
398
+ for sd in search_dirs_raw:
399
+ if sd == "parent":
400
+ search_dirs.append(docs_path.parent)
401
+ elif sd == "src_parent":
402
+ search_dirs.append(src_dir_path.parent)
403
+ elif sd == "docs":
404
+ search_dirs.append(docs_path)
405
+ elif Path(sd).exists():
406
+ search_dirs.append(Path(sd))
407
+
408
+ if not patterns:
409
+ patterns = [
410
+ "**/*.py",
411
+ "**/*.js",
412
+ "**/*.ts",
413
+ "**/*.tsx",
414
+ "**/*.jsx",
415
+ "**/*.java",
416
+ "**/*.cpp",
417
+ "**/*.c",
418
+ "**/*.h",
419
+ "**/*.hpp",
420
+ "**/*.rs",
421
+ "**/*.go",
422
+ "**/*.rb",
423
+ "**/*.php",
424
+ "**/*.cs",
425
+ "**/*.kt",
426
+ "**/*.swift",
427
+ "**/*.scala",
428
+ "**/*.clj",
429
+ "**/*.hs",
430
+ "**/*.ml",
431
+ "**/*.fs",
432
+ "**/*.vim",
433
+ "**/*.sh",
434
+ "**/*.bash",
435
+ "**/*.zsh",
436
+ "**/*.fish",
437
+ "**/*.ps1",
438
+ "**/*.bat",
439
+ "**/*.cmd",
440
+ "**/*.sql",
441
+ "**/*.html",
442
+ "**/*.htm",
443
+ "**/*.xml",
444
+ "**/*.json",
445
+ "**/*.yaml",
446
+ "**/*.yml",
447
+ "**/*.toml",
448
+ "**/*.ini",
449
+ "**/*.cfg",
450
+ "**/*.conf",
451
+ "**/*.md",
452
+ "**/*.txt",
453
+ "**/*.rst",
454
+ "**/*.css",
455
+ "**/*.scss",
456
+ "**/*.sass",
457
+ "**/*.less",
458
+ "**/*.styl",
459
+ "**/*.vue",
460
+ "**/*.svelte",
461
+ "**/*.astro",
462
+ "**/*.mdx",
463
+ ]
464
+
465
+ for search_dir in search_dirs:
466
+ if not search_dir.exists():
467
+ continue
454
468
  for pattern in patterns:
455
469
  _process_pattern(
456
470
  pattern, search_dir, ignore_dirs, seen_paths, source_files
457
471
  )
458
472
 
459
- return source_files
473
+ return source_files
460
474
 
461
475
 
462
476
  def _build_sitemap_urls(slugs, config):
@@ -650,9 +664,12 @@ def main(argv=None) -> None:
650
664
  shutil.copy2(f, out_fonts / f.name)
651
665
  print(f" Copied {len(list(out_fonts.iterdir()))} font files")
652
666
 
653
- slugs = get_all_slugs(config)
667
+ page_slugs = get_all_slugs(config)
654
668
 
655
- # Also check for any .md files not in the sidebar
669
+ # Also check for any .md files not in any sidebar (add to "default" page)
670
+ all_slugs_set: set[str] = set()
671
+ for slugs in page_slugs.values():
672
+ all_slugs_set.update(slugs)
656
673
  src_dir = Path(config["_src_dir"])
657
674
  if src_dir.is_dir():
658
675
  for dirpath, _dirnames, filenames in os.walk(src_dir):
@@ -660,42 +677,42 @@ def main(argv=None) -> None:
660
677
  if fname.endswith(".md"):
661
678
  rel = os.path.relpath(Path(dirpath, fname), src_dir)
662
679
  s = rel[:-3]
663
- if s not in slugs:
664
- slugs.append(s)
665
-
666
- config["_slug_page_keys"] = build_slug_page_keys(slugs)
667
-
668
- # Build search index
669
- search_index = []
680
+ if s not in all_slugs_set:
681
+ page_slugs.setdefault("default", []).append(s)
682
+ all_slugs_set.add(s)
683
+
684
+ # Build combined slug list and slug_page_keys for all pages
685
+ all_slugs: list[str] = []
686
+ for slugs in page_slugs.values():
687
+ all_slugs.extend(slugs)
688
+ config["_slug_page_keys"] = build_slug_page_keys(all_slugs)
689
+
690
+ # Build per-page search indexes (each page searches only its own content)
691
+ page_search_indexes: dict[str, list[dict]] = {}
670
692
  if feature_enabled(config, "search"):
671
- search_index = build_search_index(slugs, config)
672
- config["_search_index"] = search_index
673
-
674
- # Compress search index
675
- search_raw = json.dumps(search_index, separators=(",", ":")).encode("utf-8")
676
- compressed = zstandard.ZstdCompressor(
677
- level=_best_zstd_level(search_raw, zstd_level(config)), threads=16
678
- ).compress(search_raw)
679
- search_index_path = Path(config["_out_dir"], search_index_filename(config))
680
- search_index_path.parent.mkdir(parents=True, exist_ok=True)
681
- search_index_path.write_bytes(compressed)
682
-
683
- if args.production:
684
- config["_search_index_inline"] = ""
685
- else:
686
- import base64
687
-
688
- config["_search_index_inline"] = (
689
- '<script id="zstd-data" type="text/plain">'
690
- f" {base64.b64encode(compressed).decode('ascii')}"
691
- "</script>"
693
+ page_search_indexes = build_all_page_search_indexes(page_slugs, config)
694
+
695
+ # Combined global search index (all pages) for backlinks/related computation
696
+ config["_search_index"] = []
697
+ for pindex in page_search_indexes.values():
698
+ config["_search_index"].extend(pindex)
699
+
700
+ # Write per-page search index zst files
701
+ for page_name, pindex in page_search_indexes.items():
702
+ pindex_raw = json.dumps(pindex, separators=(",", ":")).encode("utf-8")
703
+ pindex_compressed = zstandard.ZstdCompressor(
704
+ level=_best_zstd_level(pindex_raw, zstd_level(config)), threads=16
705
+ ).compress(pindex_raw)
706
+ page_index_path = Path(
707
+ config["_out_dir"], f"search_index_{page_name}.zst"
692
708
  )
693
-
694
- print(
695
- f" Search index: {len(search_raw):,} bytes → {len(compressed):,} zstd ({100 * len(compressed) / len(search_raw):.1f}%)"
696
- )
709
+ page_index_path.parent.mkdir(parents=True, exist_ok=True)
710
+ page_index_path.write_bytes(pindex_compressed)
711
+ print(f" Search index ({page_name}): written → search_index_{page_name}.zst")
697
712
 
698
713
  # Save source files for code references
714
+ source_files = collect_source_files(config)
715
+ config["_source_files"] = source_files
699
716
  if (
700
717
  feature_enabled(config, "code_references")
701
718
  or (search_includes["files"] or search_includes["symbols"])
@@ -786,14 +803,30 @@ def main(argv=None) -> None:
786
803
  # Build version options
787
804
  build_version_options(git_meta, config)
788
805
 
806
+ # Build per-page inline search index data (base64) for embedding in each page's HTML
807
+ page_search_index_inline: dict[str, str] = {}
808
+ if feature_enabled(config, "search"):
809
+ for page_name, pindex in page_search_indexes.items():
810
+ pindex_raw = json.dumps(pindex, separators=(",", ":")).encode("utf-8")
811
+ pindex_compressed = zstandard.ZstdCompressor(
812
+ level=_best_zstd_level(pindex_raw, zstd_level(config)), threads=16
813
+ ).compress(pindex_raw)
814
+ page_search_index_inline[page_name] = (
815
+ '<script id="zstd-data" type="text/plain">'
816
+ f" {base64.b64encode(pindex_compressed).decode('ascii')}"
817
+ "</script>"
818
+ )
819
+
789
820
  built = 0
790
821
 
791
- # Build pages
792
- slugs_to_build = []
793
- for slug in slugs:
794
- src = Path(config["_src_dir"], f"{slug}.md")
795
- if src.exists():
796
- slugs_to_build.append(slug)
822
+ # Build pages with page-specific sidebar and per-page search index
823
+ sidebars = page_sidebars(config)
824
+ slugs_to_build: list[tuple[str, str]] = [] # (slug, page_name)
825
+ for page_name, slugs in page_slugs.items():
826
+ for slug in slugs:
827
+ src = Path(config["_src_dir"], f"{slug}.md")
828
+ if src.exists():
829
+ slugs_to_build.append((slug, page_name))
797
830
 
798
831
  if slugs_to_build:
799
832
  with concurrent.futures.ThreadPoolExecutor(
@@ -801,12 +834,17 @@ def main(argv=None) -> None:
801
834
  ) as executor:
802
835
  future_to_slug = {
803
836
  executor.submit(
804
- build_page, slug, config, config["_slug_page_keys"]
805
- ): slug
806
- for slug in slugs_to_build
837
+ build_page,
838
+ slug,
839
+ config,
840
+ page_name=page_name,
841
+ page_sidebar=sidebars.get(page_name),
842
+ search_index_inline=page_search_index_inline.get(page_name),
843
+ ): (slug, page_name)
844
+ for slug, page_name in slugs_to_build
807
845
  }
808
846
  for fut in concurrent.futures.as_completed(future_to_slug):
809
- slug = future_to_slug[fut]
847
+ slug, page_name = future_to_slug[fut]
810
848
  try:
811
849
  fut.result()
812
850
  print(f" ✓ {slug_output_name(slug, config)}")
@@ -874,17 +912,19 @@ def main(argv=None) -> None:
874
912
 
875
913
  # Generate sitemap.xml and robots.txt for production builds
876
914
  if config.get("production", False):
877
- _write_sitemap(slugs, config)
915
+ _write_sitemap(all_slugs, config)
878
916
  _write_robots(config)
879
917
 
880
918
  print(f"\n✅ Built {built} pages")
881
919
 
882
920
 
883
- def get_all_slugs(config):
884
- """Get all markdown file slugs from the sidebar definition."""
885
- slugs = []
886
- for _, pages in sidebar(config):
887
- slugs.extend(slug for slug, _ in pages)
921
+ def get_all_slugs(config: dict) -> dict[str, list[str]]:
922
+ """Get all markdown file slugs per page from the sidebar definition.
888
923
 
889
- return slugs
924
+ Supports both new dict format and old list format (single page).
925
+
926
+ :return: {page_name: [slugs]}
927
+ :rtype: dict[str, list[str]]
928
+ """
929
+ return page_slugs_from_sidebars(page_sidebars(config))
890
930
 
@@ -12,16 +12,26 @@ DEFAULT_CONFIG = {
12
12
  "copyright_holder": "CHANGE_ME",
13
13
  "project_url": "",
14
14
  "site_url": "",
15
- "site_path_prefix": "/",
15
+ "docs_dir": ".",
16
16
  "src_dir": "src",
17
17
  "out_dir": "site",
18
- "docs_dir": ".",
18
+ "site_path_prefix": "/",
19
+ "footer_text": "",
20
+ "header_links": {"Docs": "index.html"},
21
+ "custom_tags": {"ext": {"label": "Extensions", "display": "ext", "class": "ext-tag"}},
22
+ "sidebar": {
23
+ "default": {
24
+ "Getting started": {
25
+ "index": "Home",
26
+ },
27
+ },
28
+ },
19
29
  "source_files": {
20
- "search_dirs": ["parent", "src_parent", "docs"],
21
- "patterns": ["docs/src/*.md", "docs/*.js", "docs/*.css"],
22
- "ignore_dirs": [],
30
+ "default": {
31
+ "patterns": ["docs/src/*.md", "docs/*.js", "docs/*.css"],
32
+ "ignore": [],
33
+ },
23
34
  },
24
- "sidebar": [],
25
35
  "build": {
26
36
  "workers": 18,
27
37
  "minify_html": True,
@@ -36,11 +46,21 @@ DEFAULT_CONFIG = {
36
46
  "live_label": "Live",
37
47
  },
38
48
  "features": {
39
- "backlinks": True,
40
- "related": True,
49
+ "backlinks": False,
50
+ "related": False,
41
51
  "auto_link": True,
42
- "versioning": True,
43
- "search": True,
52
+ "versioning": False,
53
+ "search": {
54
+ "enabled": True,
55
+ "include": {
56
+ "pages": True,
57
+ "titles": True,
58
+ "headings": True,
59
+ "content": True,
60
+ "symbols": True,
61
+ "files": True,
62
+ },
63
+ },
44
64
  "code_references": True,
45
65
  "link_preview": True,
46
66
  "code_highlighting": True,
@@ -42,7 +42,81 @@ def site_prefix(config):
42
42
 
43
43
 
44
44
  def sidebar(config):
45
- return config.get("sidebar", [])
45
+ """Return the sidebar config for the default page as a list of
46
+ (section_name, [(slug, label), ...]) tuples.
47
+
48
+ Supports both the new dict format::
49
+
50
+ {"page_name": {"header": {"entry": "file_path"}}}
51
+
52
+ and the old list format (single page, backward compatible)::
53
+
54
+ [["header", [["entry", "file_path"]]]]
55
+ """
56
+ raw = config.get("sidebar", [])
57
+ if isinstance(raw, list):
58
+ # Old list format — treat as single "default" page
59
+ return _normalize_list_sidebar(raw)
60
+ if isinstance(raw, dict):
61
+ # New dict format — return the "default" page's sidebar
62
+ default_page = raw.get("default")
63
+ if default_page is not None:
64
+ return _normalize_dict_sections(default_page)
65
+ # Fallback: first page
66
+ for sections in raw.values():
67
+ return _normalize_dict_sections(sections)
68
+ return []
69
+
70
+
71
+ def page_sidebars(config):
72
+ """Return all page sidebars as {page_name: [(section_name, [(slug, label), ...])]}."""
73
+ raw = config.get("sidebar", [])
74
+ if isinstance(raw, list):
75
+ return {"default": _normalize_list_sidebar(raw)}
76
+ if isinstance(raw, dict):
77
+ result = {}
78
+ for page_name, sections in raw.items():
79
+ result[page_name] = _normalize_dict_sections(sections)
80
+ return result
81
+ return {"default": []}
82
+
83
+
84
+ def all_pages(config):
85
+ """Return the list of configured page names."""
86
+ raw = config.get("sidebar", [])
87
+ if isinstance(raw, list):
88
+ return ["default"]
89
+ if isinstance(raw, dict):
90
+ return list(raw.keys())
91
+ return ["default"]
92
+
93
+
94
+ def _normalize_list_sidebar(raw):
95
+ """Convert old list sidebar format to list of (section, [(slug, label)]) tuples."""
96
+ result = []
97
+ for item in raw:
98
+ if isinstance(item, (list, tuple)) and len(item) == 2:
99
+ section_name, pages = item
100
+ if isinstance(pages, (list, tuple)):
101
+ page_entries = []
102
+ for entry in pages:
103
+ if isinstance(entry, (list, tuple)) and len(entry) >= 2:
104
+ page_entries.append((str(entry[0]), str(entry[1])))
105
+ elif isinstance(entry, str):
106
+ page_entries.append((entry, entry))
107
+ result.append((str(section_name), page_entries))
108
+ return result
109
+
110
+
111
+ def _normalize_dict_sections(sections):
112
+ """Convert new dict sections format {header: {entry: file_path}} to
113
+ list of (section_name, [(slug, label)]) tuples."""
114
+ result = []
115
+ for header_name, entries in sections.items():
116
+ if isinstance(entries, dict):
117
+ page_entries = [(str(slug), str(label)) for slug, label in entries.items()]
118
+ result.append((str(header_name), page_entries))
119
+ return result
46
120
 
47
121
 
48
122
  def build_settings(config):
@@ -221,3 +295,65 @@ def site_url(config):
221
295
  def src_map_path(config) -> str:
222
296
  """Return the source markdown path pattern used in git metadata."""
223
297
  return f"{src_dir(config)}/{{slug}}.md"
298
+
299
+
300
+ def page_source_files(config, page_name="default"):
301
+ """Return source_files config for a given page.
302
+
303
+ Supports both the new per-page format::
304
+
305
+ {"page_name": {"patterns": [...], "ignore": [...]}}
306
+
307
+ and the old flat format (single page, backward compatible)::
308
+
309
+ {"patterns": [...], "ignore_dirs": [...]}
310
+
311
+ Returns a dict with ``patterns`` and ``ignore`` keys.
312
+ """
313
+ raw = config.get("source_files", {})
314
+ if not isinstance(raw, dict):
315
+ return {"patterns": [], "ignore": []}
316
+
317
+ # Old flat format: has "patterns" or "search_dirs" at top level
318
+ if "patterns" in raw or "search_dirs" in raw or "ignore_dirs" in raw:
319
+ return {
320
+ "patterns": raw.get("patterns", []),
321
+ "ignore": raw.get("ignore_dirs", []),
322
+ }
323
+
324
+ # New per-page format
325
+ page_config = raw.get(page_name)
326
+ if page_config is None:
327
+ return {"patterns": [], "ignore": []}
328
+ if isinstance(page_config, dict):
329
+ return {
330
+ "patterns": page_config.get("patterns", []),
331
+ "ignore": page_config.get("ignore", []),
332
+ }
333
+ return {"patterns": [], "ignore": []}
334
+
335
+
336
+ def page_source_files_all(config):
337
+ """Return source_files config for all pages as {page_name: {patterns, ignore}}."""
338
+ raw = config.get("source_files", {})
339
+ if not isinstance(raw, dict):
340
+ return {"default": {"patterns": [], "ignore": []}}
341
+
342
+ # Old flat format
343
+ if "patterns" in raw or "search_dirs" in raw or "ignore_dirs" in raw:
344
+ return {
345
+ "default": {
346
+ "patterns": raw.get("patterns", []),
347
+ "ignore": raw.get("ignore_dirs", []),
348
+ }
349
+ }
350
+
351
+ # New per-page format
352
+ result = {}
353
+ for page_name, page_config in raw.items():
354
+ if isinstance(page_config, dict):
355
+ result[page_name] = {
356
+ "patterns": page_config.get("patterns", []),
357
+ "ignore": page_config.get("ignore", []),
358
+ }
359
+ return result