# Generates virtual doc files for the mkdocs site. # You can also run this script directly to actually write out those files, as a preview. import collections import mkdocs_gen_files root = mkdocs_gen_files.config['plugins']['mkdocstrings'].get_handler( 'crystal').collector.root for typ in root.walk_types(): filename = 'api_reference/' + '/'.join( typ.abs_id.split('::')) + '/index.md' with mkdocs_gen_files.open(filename, 'w') as f: f.write(f'# ::: {typ.abs_id}\n\n') if typ.locations: mkdocs_gen_files.set_edit_path(filename, typ.locations[0].url)
#!/usr/bin/env python from pathlib import Path import mkdocs_gen_files nav = mkdocs_gen_files.Nav() for path in sorted(Path("src").glob("**/*.py")): module_path = path.relative_to("src").with_suffix("") doc_path = path.relative_to("src", "mkdocstrings").with_suffix(".md") full_doc_path = Path("reference", doc_path) nav[module_path.parts] = doc_path with mkdocs_gen_files.open(full_doc_path, "w") as f: ident = ".".join(module_path.parts) print("::: " + ident, file=f) mkdocs_gen_files.set_edit_path(full_doc_path, path) nav["mkdocs_autorefs", "references"] = "autorefs/references.md" nav["mkdocs_autorefs", "plugin"] = "autorefs/plugin.md" with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file: nav_file.writelines(nav.build_literate_nav())
#!/usr/bin/env python from pathlib import Path import mkdocs_gen_files for path in Path("braincube_connector").glob("**/*.py"): if "__init__" in path.name: continue doc_path = Path("reference", path.relative_to(".")).with_suffix(".md") with mkdocs_gen_files.open(doc_path, "w") as f: ident = ".".join(path.relative_to(".").with_suffix("").parts) print("::: " + ident, file=f) mkdocs_gen_files.set_edit_path(doc_path, Path("..", path))
} indirect_dependencies -= direct_dependencies return { "project_name": project_name, "direct_dependencies": sorted(direct_dependencies), "indirect_dependencies": sorted(indirect_dependencies), "more_credits": "http://pawamoy.github.io/credits/", } @functools.lru_cache(maxsize=None) def get_credits(): """Return credits as Markdown. Returns: The credits page Markdown. """ jinja_env = SandboxedEnvironment(undefined=StrictUndefined) commit = "398879aba2a365049870709116a689618afeb5b7" template_url = f"https://raw.githubusercontent.com/pawamoy/jinja-templates/{commit}/credits.md" template_data = get_credits_data() template_text = urllib.request.urlopen(template_url).read().decode( "utf8") # noqa: S310 return jinja_env.from_string(template_text).render(**template_data) with mkdocs_gen_files.open("credits.md", "w") as fd: fd.write(get_credits()) mkdocs_gen_files.set_edit_path("credits.md", "gen_credits.py")
#!/usr/bin/env python from pathlib import Path import mkdocs_gen_files CODE_ROOT = "snoop" with mkdocs_gen_files.open("module-index.md", 'w') as index: print("# Module index\n", file=index) for path in Path(CODE_ROOT).glob("**/*.py"): doc_path = Path("reference", path.relative_to(".")).with_suffix(".md") ident = ".".join(path.relative_to(".").with_suffix("").parts) # skip database migraitons if ident.startswith('snoop.data.migrations.'): continue # write file with mkdocs_gen_files.open(doc_path, "w") as f: print("::: " + ident, file=f) # write entry in module index file print(f"- [`{ident}`][{ident}]", file=index) mkdocs_gen_files.set_edit_path(doc_path, Path('..', path))