@dogsbay/format-mkdocs 0.2.0-beta.173 → 0.2.0-beta.175

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.
@@ -87,9 +87,19 @@ function pageFrontmatter(page, ledger) {
87
87
  if (typeof fm.description === "string")
88
88
  entries.push(["description", fm.description]);
89
89
  const extra = [];
90
+ // An unlisted page (plans/unlisted-pages.md): out of the nav already; Material's `search:
91
+ // exclude` keeps it out of search, and its tags are not written (the tags plugin would list
92
+ // it). MkDocs has no noindex and keeps every page in its sitemap: recorded
93
+ const unlisted = fm.unlisted === true;
94
+ if (unlisted) {
95
+ extra.push("search:\n exclude: true");
96
+ ledger.record({ feature: "unlisted", action: "degraded", detail: "out of the nav and search; MkDocs keeps it in its sitemap and has no noindex" });
97
+ }
90
98
  for (const [key, value] of Object.entries(fm)) {
91
99
  if (key === "title" || key === "description")
92
100
  continue;
101
+ if (unlisted && (key === "unlisted" || key === "noindex" || key === "excludeFromSearch" || key === "search" || key === "tags"))
102
+ continue;
93
103
  if (MATERIAL_META.has(key)) {
94
104
  if (Array.isArray(value) && value.every((v) => typeof v === "string" || typeof v === "number")) {
95
105
  extra.push(`${key}:\n${value.map((v) => ` - ${yamlScalar(String(v))}`).join("\n")}`);
@@ -27,3 +27,5 @@ export declare function readMkdocsConfig(sourceDir: string): MkdocsConfig;
27
27
  * Import a MkDocs project: parse all pages and extract navigation.
28
28
  */
29
29
  export declare function importMkdocsProject(sourceDir: string, opts?: Record<string, unknown>): Promise<MkdocsImportResult>;
30
+ /** Mark the pages `pagesOutsideNav` names `unlisted: true`; returns how many. */
31
+ export declare function unlistOutsideNav(pages: ExportPage[], raw: Record<string, unknown>): number;
package/dist/importer.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * Reads a MkDocs project directory (containing mkdocs.yml) and produces
5
5
  * ExportPage[] + NavItem[] — the universal format contract.
6
6
  */
7
+ import { pagesOutsideNav } from "./nav-coverage.js";
7
8
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
8
9
  import { join, relative, basename, dirname, resolve } from "node:path";
9
10
  import MarkdownIt from "markdown-it";
@@ -166,8 +167,20 @@ export async function importMkdocsProject(sourceDir, opts = {}) {
166
167
  // where pages will actually be emitted.
167
168
  const hrefPrefix = typeof opts.hrefPrefix === "string" ? opts.hrefPrefix : "/docs";
168
169
  const nav = convertNav(config.raw.nav, hrefPrefix);
170
+ unlistOutsideNav(pages, config.raw);
169
171
  return { pages, nav, config };
170
172
  }
173
+ /** Mark the pages `pagesOutsideNav` names `unlisted: true`; returns how many. */
174
+ export function unlistOutsideNav(pages, raw) {
175
+ const out = new Set(pagesOutsideNav(pages.map((p) => p.slug), raw));
176
+ for (const page of pages)
177
+ if (out.has(page.slug))
178
+ page.frontmatter = { ...(page.frontmatter ?? {}), unlisted: true };
179
+ if (out.size > 0) {
180
+ console.log(` ${out.size} page(s) not in mkdocs.yml's nav are unlisted: built, out of the menu, and (unlike MkDocs) out of search, the sitemap and llms.txt (docs/unlisted-pages.md)`);
181
+ }
182
+ return out.size;
183
+ }
171
184
  // ── Helpers ─────────────────────────────────────────────
172
185
  /** Match a YAML frontmatter block at the start of an MD source. */
173
186
  const FRONTMATTER_RE = /^---\n([\s\S]*?)\n---\n?/;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export { parseShortcode } from "./rules/icon-shortcode.js";
8
8
  export { treeToMkdocs } from "./export/to-mkdocs.js";
9
9
  export { exportMkdocsProject } from "./export/to-mkdocs-project.js";
10
10
  export { MKDOCS_CAPABILITIES } from "./export/capabilities.js";
11
+ export { pagesOutsideNav } from "./nav-coverage.js";
11
12
  export type { MkdocsProjectOptions, MkdocsProjectExport } from "./export/to-mkdocs-project.js";
12
13
  export interface MkdocsPluginOptions {
13
14
  admonitions?: boolean;
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export { parseShortcode } from "./rules/icon-shortcode.js";
8
8
  export { treeToMkdocs } from "./export/to-mkdocs.js";
9
9
  export { exportMkdocsProject } from "./export/to-mkdocs-project.js";
10
10
  export { MKDOCS_CAPABILITIES } from "./export/capabilities.js";
11
+ export { pagesOutsideNav } from "./nav-coverage.js";
11
12
  import { admonitionPlugin } from "./rules/admonition.js";
12
13
  import { blocksPlugin } from "./rules/blocks.js";
13
14
  import { contentTabsPlugin } from "./rules/content-tabs.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Which pages an MkDocs `nav:` leaves out (no Node: the importer and `migrate-mkdocs` share it).
3
+ */
4
+ /**
5
+ * The pages (by slug) an explicit `nav:` does not list. MkDocs builds them out of its menu
6
+ * (`not_in_nav` only quiets the notice), so they are UNLISTED here (plans/unlisted-pages.md):
7
+ * built, reachable by link, out of the menu — and also out of search, the sitemap and llms.txt,
8
+ * and noindex, which MkDocs does not do. None when MkDocs lists every page or the nav is not all
9
+ * written in mkdocs.yml:
10
+ * - no `nav:` (MkDocs lists every page);
11
+ * - a plugin that builds or extends the nav (literate-nav, awesome-pages/awesome-nav, i18n,
12
+ * monorepo/multirepo), or a nav entry naming a folder (`reference/`), a glob or `...`;
13
+ * The home page (`index`) is never one: MkDocs serves it at the root whatever the nav says. A
14
+ * Material blog's posts (`blog_dir`, default `blog`) are listed by the blog's own index. An entry
15
+ * to part of a page (`a.md#part`) lists the page.
16
+ */
17
+ export declare function pagesOutsideNav(slugs: readonly string[], raw: Record<string, unknown>): string[];
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Which pages an MkDocs `nav:` leaves out (no Node: the importer and `migrate-mkdocs` share it).
3
+ */
4
+ /**
5
+ * The pages (by slug) an explicit `nav:` does not list. MkDocs builds them out of its menu
6
+ * (`not_in_nav` only quiets the notice), so they are UNLISTED here (plans/unlisted-pages.md):
7
+ * built, reachable by link, out of the menu — and also out of search, the sitemap and llms.txt,
8
+ * and noindex, which MkDocs does not do. None when MkDocs lists every page or the nav is not all
9
+ * written in mkdocs.yml:
10
+ * - no `nav:` (MkDocs lists every page);
11
+ * - a plugin that builds or extends the nav (literate-nav, awesome-pages/awesome-nav, i18n,
12
+ * monorepo/multirepo), or a nav entry naming a folder (`reference/`), a glob or `...`;
13
+ * The home page (`index`) is never one: MkDocs serves it at the root whatever the nav says. A
14
+ * Material blog's posts (`blog_dir`, default `blog`) are listed by the blog's own index. An entry
15
+ * to part of a page (`a.md#part`) lists the page.
16
+ */
17
+ export function pagesOutsideNav(slugs, raw) {
18
+ const navRaw = raw.nav;
19
+ if (!Array.isArray(navRaw) || navRaw.length === 0)
20
+ return [];
21
+ const plugins = pluginEntries(raw.plugins);
22
+ if (plugins.some(([name]) => NAV_PLUGINS.test(name)))
23
+ return [];
24
+ const listed = new Set();
25
+ let partial = false;
26
+ const add = (path) => {
27
+ const bare = path.trim();
28
+ if (bare === "..." || bare.endsWith("/") || /[*?[\]]/.test(bare.split("#")[0]))
29
+ partial = true;
30
+ else {
31
+ const slug = navPathSlug(bare);
32
+ if (slug !== undefined)
33
+ listed.add(slug);
34
+ }
35
+ };
36
+ const walk = (items) => {
37
+ for (const entry of items) {
38
+ if (typeof entry === "string")
39
+ add(entry);
40
+ else if (entry && typeof entry === "object") {
41
+ for (const value of Object.values(entry)) {
42
+ if (typeof value === "string")
43
+ add(value);
44
+ else if (Array.isArray(value))
45
+ walk(value);
46
+ }
47
+ }
48
+ }
49
+ };
50
+ walk(navRaw);
51
+ if (partial)
52
+ return [];
53
+ const blogDirs = plugins
54
+ .filter(([name]) => name === "blog" || name === "material/blog")
55
+ .map(([, cfg]) => {
56
+ const dir = cfg && typeof cfg === "object" ? cfg.blog_dir : undefined;
57
+ return typeof dir === "string" ? dir.replace(/^\.?\/+|\/+$/g, "").replace(/^\.$/, "") : "blog";
58
+ });
59
+ return slugs.filter((slug) => slug !== "index" && !listed.has(slug) && !blogDirs.some((d) => d === "" || slug === d || slug.startsWith(`${d}/`)));
60
+ }
61
+ /** Plugins that build or extend the nav from elsewhere: the `nav:` in mkdocs.yml is not all of it. */
62
+ const NAV_PLUGINS = /^(?:literate-nav|awesome-pages|awesome-nav|i18n|static-i18n|monorepo|multirepo|mkdocs-nav-weight|gen-files)$/;
63
+ /** `plugins:` as `[name, config]`, from the list form (`- blog`, `- blog: {…}`) or the mapping form. */
64
+ function pluginEntries(plugins) {
65
+ if (Array.isArray(plugins)) {
66
+ return plugins.flatMap((p) => typeof p === "string" ? [[p, undefined]] : p && typeof p === "object" ? Object.entries(p) : []);
67
+ }
68
+ return plugins && typeof plugins === "object" ? Object.entries(plugins) : [];
69
+ }
70
+ /** A nav entry's file as a page slug (`a/index.md` → `a`, `index.md` → `index`, `a.md#x` → `a`); a URL names none. */
71
+ function navPathSlug(path) {
72
+ if (/^[a-z][a-z0-9+.-]*:/i.test(path) || path.startsWith("//"))
73
+ return undefined;
74
+ const slug = path.split(/[#?]/)[0].replace(/^\.?\/+/, "").replace(/\.md$/, "").replace(/\/index$/, "").replace(/^index$/, "");
75
+ return slug || "index";
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/format-mkdocs",
3
- "version": "0.2.0-beta.173",
3
+ "version": "0.2.0-beta.175",
4
4
  "description": "MkDocs format plugin for Dogsbay — import/export MkDocs projects via TreeNode[]",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,10 +46,10 @@
46
46
  "markdown-it-deflist": "^3.0.1",
47
47
  "nunjucks": "^3.2.4",
48
48
  "yaml": "^2.9.0",
49
- "@dogsbay/autodoc-python": "0.2.0-beta.173",
50
- "@dogsbay/serialize-core": "0.2.0-beta.173",
51
- "@dogsbay/types": "0.2.0-beta.173",
52
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.173"
49
+ "@dogsbay/autodoc-python": "0.2.0-beta.175",
50
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.175",
51
+ "@dogsbay/serialize-core": "0.2.0-beta.175",
52
+ "@dogsbay/types": "0.2.0-beta.175"
53
53
  },
54
54
  "repository": {
55
55
  "type": "git",