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.
- {fr_docs-5.2.0 → fr_docs-6.1.0}/PKG-INFO +1 -1
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/build.py +195 -155
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/config.py +30 -10
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/config_accessors.py +137 -1
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/html_pipeline.py +684 -615
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/markdown.py +38 -12
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/search.py +76 -7
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/slug.py +27 -8
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/template.py +29 -24
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/PKG-INFO +1 -1
- {fr_docs-5.2.0 → fr_docs-6.1.0}/pyproject.toml +5 -1
- {fr_docs-5.2.0 → fr_docs-6.1.0}/LICENSE.md +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/README.md +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/__init__.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/__main__.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/frontmatter.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/git.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/init.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/syntax.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/update.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs/utils.py +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/SOURCES.txt +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/dependency_links.txt +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/entry_points.txt +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/requires.txt +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/fr_docs.egg-info/top_level.txt +0 -0
- {fr_docs-5.2.0 → fr_docs-6.1.0}/setup.cfg +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
|
|
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
|
-
|
|
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
|
-
#
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
"
|
|
386
|
-
|
|
387
|
-
"
|
|
388
|
-
|
|
389
|
-
"
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
"
|
|
436
|
-
"
|
|
437
|
-
"
|
|
438
|
-
"
|
|
439
|
-
"
|
|
440
|
-
"
|
|
441
|
-
"
|
|
442
|
-
"
|
|
443
|
-
"
|
|
444
|
-
"
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
667
|
+
page_slugs = get_all_slugs(config)
|
|
654
668
|
|
|
655
|
-
# Also check for any .md files not in
|
|
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
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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
|
-
|
|
695
|
-
f" Search index
|
|
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
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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,
|
|
805
|
-
|
|
806
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
"
|
|
15
|
+
"docs_dir": ".",
|
|
16
16
|
"src_dir": "src",
|
|
17
17
|
"out_dir": "site",
|
|
18
|
-
"
|
|
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
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
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":
|
|
40
|
-
"related":
|
|
49
|
+
"backlinks": False,
|
|
50
|
+
"related": False,
|
|
41
51
|
"auto_link": True,
|
|
42
|
-
"versioning":
|
|
43
|
-
"search":
|
|
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
|
-
|
|
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
|