doccupine 0.0.134 → 0.0.135
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.
- package/README.md +10 -9
- package/dist/index.js +222 -44
- package/dist/lib/metadata.d.ts +5 -0
- package/dist/lib/metadata.js +15 -4
- package/dist/lib/rss.d.ts +24 -0
- package/dist/lib/rss.js +137 -0
- package/dist/lib/structures.js +22 -2
- package/dist/templates/app/rssRoute.d.ts +11 -0
- package/dist/templates/app/rssRoute.js +30 -0
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +5 -2
- package/dist/templates/components/MDXComponents.d.ts +1 -1
- package/dist/templates/components/MDXComponents.js +29 -0
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +5 -2
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +44 -13
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
- package/dist/templates/components/layout/ApiPlayground.js +20 -28
- package/dist/templates/components/layout/Badge.d.ts +1 -0
- package/dist/templates/components/layout/Badge.js +455 -0
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +5 -30
- package/dist/templates/components/layout/Prompt.d.ts +1 -0
- package/dist/templates/components/layout/Prompt.js +149 -0
- package/dist/templates/components/layout/Tooltip.d.ts +1 -0
- package/dist/templates/components/layout/Tooltip.js +222 -0
- package/dist/templates/components/layout/Tree.d.ts +1 -0
- package/dist/templates/components/layout/Tree.js +322 -0
- package/dist/templates/components/layout/TreeData.d.ts +1 -0
- package/dist/templates/components/layout/TreeData.js +131 -0
- package/dist/templates/components/layout/Update.d.ts +1 -1
- package/dist/templates/components/layout/Update.js +3 -0
- package/dist/templates/lib/rss.d.ts +1 -0
- package/dist/templates/lib/rss.js +78 -0
- package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
- package/dist/templates/mdx/accordion.mdx.js +1 -1
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +1 -1
- package/dist/templates/mdx/badges.mdx.d.ts +1 -0
- package/dist/templates/mdx/badges.mdx.js +237 -0
- package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
- package/dist/templates/mdx/buttons.mdx.js +1 -1
- package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
- package/dist/templates/mdx/callouts.mdx.js +1 -1
- package/dist/templates/mdx/cards.mdx.d.ts +1 -1
- package/dist/templates/mdx/cards.mdx.js +1 -1
- package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
- package/dist/templates/mdx/color-swatches.mdx.js +1 -1
- package/dist/templates/mdx/columns.mdx.d.ts +1 -1
- package/dist/templates/mdx/columns.mdx.js +1 -1
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +14 -2
- package/dist/templates/mdx/fields.mdx.d.ts +1 -1
- package/dist/templates/mdx/fields.mdx.js +1 -1
- package/dist/templates/mdx/frames.mdx.d.ts +1 -1
- package/dist/templates/mdx/frames.mdx.js +1 -1
- package/dist/templates/mdx/icons.mdx.d.ts +1 -1
- package/dist/templates/mdx/icons.mdx.js +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
- package/dist/templates/mdx/images-and-embeds.mdx.d.ts +1 -0
- package/dist/templates/mdx/images-and-embeds.mdx.js +118 -0
- package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
- package/dist/templates/mdx/mermaid.mdx.js +1 -1
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +5 -1
- package/dist/templates/mdx/prompt.mdx.d.ts +1 -0
- package/dist/templates/mdx/prompt.mdx.js +69 -0
- package/dist/templates/mdx/steps.mdx.d.ts +1 -1
- package/dist/templates/mdx/steps.mdx.js +1 -1
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +1 -1
- package/dist/templates/mdx/tooltips.mdx.d.ts +1 -0
- package/dist/templates/mdx/tooltips.mdx.js +57 -0
- package/dist/templates/mdx/tree.mdx.d.ts +1 -0
- package/dist/templates/mdx/tree.mdx.js +158 -0
- package/dist/templates/mdx/update.mdx.d.ts +1 -1
- package/dist/templates/mdx/update.mdx.js +42 -2
- package/dist/templates/package.js +1 -1
- package/package.json +2 -2
- package/dist/templates/mdx/platform/external-links.mdx.d.ts +0 -1
- package/dist/templates/mdx/platform/external-links.mdx.js +0 -47
- package/dist/templates/utils/apiAnchors.d.ts +0 -1
- package/dist/templates/utils/apiAnchors.js +0 -39
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
- **Auto-generated navigation** - sidebar built from frontmatter (`category`, `order`)
|
|
11
11
|
- **Sections** - organize docs into tabbed sections via frontmatter or `sections.json`
|
|
12
12
|
- **API reference** - point at an OpenAPI spec to generate interactive endpoint pages with a live playground
|
|
13
|
+
- **Subscribable changelogs** - pages using the `Update` component publish an RSS feed at `{page-url}/rss.xml`
|
|
13
14
|
- **Theming** - dark/light mode with customizable theme via `theme.json`
|
|
14
15
|
- **AI chat assistant** - built-in RAG-powered chat (OpenAI, Anthropic, or Google)
|
|
15
16
|
- **MCP server** - exposes `search_docs`, `get_doc`, and `list_docs` tools for AI agents
|
|
@@ -181,16 +182,16 @@ openapi: "GET /users/{id}"
|
|
|
181
182
|
|
|
182
183
|
Place these JSON files in your project root (where you run `doccupine`). They are auto-copied to the generated app and watched for changes.
|
|
183
184
|
|
|
184
|
-
| File | Purpose
|
|
185
|
-
| ----------------- |
|
|
185
|
+
| File | Purpose |
|
|
186
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
186
187
|
| `doccupine.json` | CLI config (`watchDir`, `outputDir`, `port`, `packageManager`, `openapi`). Auto-generated on first run. Paths are stored relative to the project root, so the file is safe to commit. |
|
|
187
|
-
| `config.json` | Site metadata: `name`, `description`, `icon`, `image`, `url` (public site URL for sitemap/robots)
|
|
188
|
-
| `theme.json` | Theme overrides for [cherry-styled-components](https://github.com/cherry-design-system/styled-components)
|
|
189
|
-
| `navigation.json` | Manual navigation structure (overrides auto-generated)
|
|
190
|
-
| `links.json` | Static header/footer links
|
|
191
|
-
| `fonts.json` | Font configuration (Google Fonts or local)
|
|
192
|
-
| `sections.json` | Section definitions for tabbed doc groups (see [Sections](#sections))
|
|
193
|
-
| `analytics.json` | Analytics provider configuration (PostHog supported)
|
|
188
|
+
| `config.json` | Site metadata: `name`, `description`, `icon`, `image`, `url` (public site URL for sitemap/robots) |
|
|
189
|
+
| `theme.json` | Theme overrides for [cherry-styled-components](https://github.com/cherry-design-system/styled-components) |
|
|
190
|
+
| `navigation.json` | Manual navigation structure (overrides auto-generated) |
|
|
191
|
+
| `links.json` | Static header/footer links |
|
|
192
|
+
| `fonts.json` | Font configuration (Google Fonts or local) |
|
|
193
|
+
| `sections.json` | Section definitions for tabbed doc groups (see [Sections](#sections)) |
|
|
194
|
+
| `analytics.json` | Analytics provider configuration (PostHog supported) |
|
|
194
195
|
|
|
195
196
|
## Public Directory
|
|
196
197
|
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,12 @@ import { ConfigManager, normalizeOpenApiConfig } from "./lib/config-manager.js";
|
|
|
12
12
|
import { OpenApiRegistry, DEFAULT_API_BASE_SLUG, buildEndpointDoc, } from "./lib/openapi.js";
|
|
13
13
|
import { findAvailablePort, generateSlug, getFullSlug, escapeTemplateContent, toJsStringLiteral, resolvePackageManager, } from "./lib/utils.js";
|
|
14
14
|
import { generateMetadataBlock, generateRuntimeOnlyMetadataBlock, generateJsonLdScript, } from "./lib/metadata.js";
|
|
15
|
+
import { parseUpdateBlocks } from "./lib/rss.js";
|
|
15
16
|
import { nextConfigTemplate } from "./templates/next.config.js";
|
|
16
17
|
import { pnpmWorkspaceTemplate } from "./templates/pnpmWorkspace.js";
|
|
17
18
|
import { proxyTemplate } from "./templates/proxy.js";
|
|
18
19
|
import { robotsTemplate } from "./templates/app/robots.js";
|
|
20
|
+
import { rssRouteTemplate } from "./templates/app/rssRoute.js";
|
|
19
21
|
import { sitemapTemplate } from "./templates/app/sitemap.js";
|
|
20
22
|
import { llmsIndexTemplate } from "./templates/llms/llmsIndex.js";
|
|
21
23
|
import { llmsFullTemplate, } from "./templates/llms/llmsFull.js";
|
|
@@ -36,6 +38,8 @@ class MDXToNextJSGenerator {
|
|
|
36
38
|
rootDirWatcher = null;
|
|
37
39
|
analyticsWatcher = null;
|
|
38
40
|
openApiWatcher = null;
|
|
41
|
+
doccupineConfigWatcher = null;
|
|
42
|
+
doccupineConfigFile = "doccupine.json";
|
|
39
43
|
configFiles = [
|
|
40
44
|
"theme.json",
|
|
41
45
|
"navigation.json",
|
|
@@ -57,6 +61,8 @@ class MDXToNextJSGenerator {
|
|
|
57
61
|
apiRegistry = new OpenApiRegistry();
|
|
58
62
|
/** Route slugs of the endpoint pages written last pass, for stale cleanup. */
|
|
59
63
|
generatedApiPageSlugs = new Set();
|
|
64
|
+
/** Section slugs whose index redirect we wrote this session, for cleanup. */
|
|
65
|
+
generatedSectionIndexSlugs = new Set();
|
|
60
66
|
constructor(watchDir, outputDir, openApiSpecs = []) {
|
|
61
67
|
this.watchDir = path.resolve(watchDir);
|
|
62
68
|
this.outputDir = path.resolve(outputDir);
|
|
@@ -625,20 +631,18 @@ class MDXToNextJSGenerator {
|
|
|
625
631
|
.on("error", (error) => {
|
|
626
632
|
console.error(chalk.red("❌ Analytics watcher error:"), error);
|
|
627
633
|
});
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
});
|
|
641
|
-
}
|
|
634
|
+
await this.syncOpenApiSpecWatcher();
|
|
635
|
+
const doccupineConfigPath = path.join(this.rootDir, this.doccupineConfigFile);
|
|
636
|
+
this.doccupineConfigWatcher = chokidar.watch(doccupineConfigPath, {
|
|
637
|
+
persistent: true,
|
|
638
|
+
ignoreInitial: true,
|
|
639
|
+
});
|
|
640
|
+
this.doccupineConfigWatcher
|
|
641
|
+
.on("add", () => this.handleDoccupineConfigChange())
|
|
642
|
+
.on("change", () => this.handleDoccupineConfigChange())
|
|
643
|
+
.on("error", (error) => {
|
|
644
|
+
console.error(chalk.red("❌ doccupine.json watcher error:"), error);
|
|
645
|
+
});
|
|
642
646
|
const publicDir = path.join(this.rootDir, "public");
|
|
643
647
|
if (await fs.pathExists(publicDir)) {
|
|
644
648
|
this.setupPublicWatcher();
|
|
@@ -897,42 +901,98 @@ class MDXToNextJSGenerator {
|
|
|
897
901
|
return siteLayoutTemplate(resolvedPages, this.sectionsConfig);
|
|
898
902
|
}
|
|
899
903
|
async generateSectionIndexPages(pages) {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
904
|
+
const nextSlugs = new Set();
|
|
905
|
+
if (this.sectionsConfig && this.sectionsConfig.length > 0) {
|
|
906
|
+
const resolvedPages = pages ?? (await this.buildAllPagesMeta());
|
|
907
|
+
for (const section of this.sectionsConfig) {
|
|
908
|
+
if (section.slug === "")
|
|
909
|
+
continue;
|
|
910
|
+
// Check if a page already exists at the section root
|
|
911
|
+
const hasIndex = resolvedPages.some((p) => p.slug === section.slug);
|
|
912
|
+
if (hasIndex)
|
|
913
|
+
continue;
|
|
914
|
+
// Find the first page in this section
|
|
915
|
+
const sectionPages = resolvedPages
|
|
916
|
+
.filter((p) => p.section === section.slug)
|
|
917
|
+
.sort((a, b) => {
|
|
918
|
+
if (a.categoryOrder !== b.categoryOrder)
|
|
919
|
+
return a.categoryOrder - b.categoryOrder;
|
|
920
|
+
return a.order - b.order;
|
|
921
|
+
});
|
|
922
|
+
if (sectionPages.length === 0)
|
|
923
|
+
continue;
|
|
924
|
+
const firstPage = sectionPages[0];
|
|
925
|
+
const redirectContent = `import { redirect } from "next/navigation";
|
|
922
926
|
|
|
923
927
|
export default function SectionIndex() {
|
|
924
928
|
redirect("/${firstPage.slug}");
|
|
925
929
|
}
|
|
926
930
|
`;
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
+
const pagePath = path.join(this.outputDir, "app", "(site)", section.slug, "page.tsx");
|
|
932
|
+
await fs.ensureDir(path.dirname(pagePath));
|
|
933
|
+
await fs.writeFile(pagePath, redirectContent, "utf8");
|
|
934
|
+
nextSlugs.add(section.slug);
|
|
935
|
+
console.log(chalk.blue(`🔀 Generated section index redirect: /${section.slug} -> /${firstPage.slug}`));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
await this.cleanupStaleSectionIndexPages(nextSlugs);
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Removes section index redirects written earlier in this session whose
|
|
942
|
+
* section has since disappeared (e.g. the API Reference section after the
|
|
943
|
+
* `openapi` config is removed mid-watch). Only files that still contain the
|
|
944
|
+
* generated redirect are deleted, so a hand-written page that has taken
|
|
945
|
+
* over the slug is never touched. Fresh processes start clean anyway -
|
|
946
|
+
* init() wipes app/ - so in-session tracking is enough.
|
|
947
|
+
*/
|
|
948
|
+
async cleanupStaleSectionIndexPages(nextSlugs) {
|
|
949
|
+
for (const stale of this.generatedSectionIndexSlugs) {
|
|
950
|
+
if (nextSlugs.has(stale))
|
|
951
|
+
continue;
|
|
952
|
+
const pagePath = path.join(this.outputDir, "app", "(site)", stale, "page.tsx");
|
|
953
|
+
try {
|
|
954
|
+
if (!(await fs.pathExists(pagePath)))
|
|
955
|
+
continue;
|
|
956
|
+
const content = await fs.readFile(pagePath, "utf8");
|
|
957
|
+
if (!content.includes("function SectionIndex()"))
|
|
958
|
+
continue;
|
|
959
|
+
await fs.remove(pagePath);
|
|
960
|
+
await this.removeEmptyDirsUpTo(path.dirname(pagePath), path.join(this.outputDir, "app", "(site)"));
|
|
961
|
+
console.log(chalk.blue(`🧹 Removed stale section index redirect: /${stale}`));
|
|
962
|
+
}
|
|
963
|
+
catch {
|
|
964
|
+
// ignore
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
this.generatedSectionIndexSlugs = nextSlugs;
|
|
968
|
+
}
|
|
969
|
+
/** Best-effort removal of now-empty directories up to (not incl.) stopDir. */
|
|
970
|
+
async removeEmptyDirsUpTo(dir, stopDir) {
|
|
971
|
+
const stop = path.resolve(stopDir);
|
|
972
|
+
let current = path.resolve(dir);
|
|
973
|
+
while (current !== stop && current.startsWith(stop + path.sep)) {
|
|
974
|
+
try {
|
|
975
|
+
const entries = await fs.readdir(current);
|
|
976
|
+
if (entries.length > 0)
|
|
977
|
+
return;
|
|
978
|
+
await fs.remove(current);
|
|
979
|
+
}
|
|
980
|
+
catch {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
current = path.dirname(current);
|
|
931
984
|
}
|
|
932
985
|
}
|
|
933
986
|
async generatePageFromMDX(mdxFile, options) {
|
|
934
987
|
const fm = mdxFile.frontmatter;
|
|
935
988
|
const apiOperation = options?.apiOperation;
|
|
989
|
+
// Pages containing <Update> blocks publish a subscribable changelog: an
|
|
990
|
+
// RSS feed at {page-url}/rss.xml. Synthetic OpenAPI pages never contain
|
|
991
|
+
// Update blocks, so skip the parse for them.
|
|
992
|
+
const isSynthetic = mdxFile.path.startsWith("@openapi/");
|
|
993
|
+
const updates = isSynthetic ? [] : parseUpdateBlocks(mdxFile.content);
|
|
994
|
+
const hasFeed = updates.length > 0;
|
|
995
|
+
const feedPath = `/${mdxFile.slug}/rss.xml`;
|
|
936
996
|
const metadataBlock = generateMetadataBlock({
|
|
937
997
|
title: fm.title,
|
|
938
998
|
titleFallback: "Generated with Doccupine",
|
|
@@ -942,6 +1002,7 @@ export default function SectionIndex() {
|
|
|
942
1002
|
icon: fm.icon,
|
|
943
1003
|
image: fm.image,
|
|
944
1004
|
canonicalPath: mdxFile.slug,
|
|
1005
|
+
rssPath: hasFeed ? feedPath : undefined,
|
|
945
1006
|
});
|
|
946
1007
|
const jsonLd = generateJsonLdScript({
|
|
947
1008
|
kind: "article",
|
|
@@ -984,11 +1045,26 @@ export default function SectionIndex() {
|
|
|
984
1045
|
// diagrams (which endpoint docs never contain), and its long `@openapi/...`
|
|
985
1046
|
// value would push the opening tag past 80 cols and make Prettier rewrap it.
|
|
986
1047
|
const sourcePathLiteral = JSON.stringify(mdxFile.path);
|
|
1048
|
+
// `rss: true` frontmatter opts the page into an RSS button in the action
|
|
1049
|
+
// bar (only when a feed actually exists). The playground branch keeps its
|
|
1050
|
+
// fixed JSX shape - a feed on an inline-playground page stays reachable
|
|
1051
|
+
// via autodiscovery. The buttoned form usually exceeds the 80-col print
|
|
1052
|
+
// width, so pre-wrap it in the shape Prettier produces (attributes on
|
|
1053
|
+
// their own lines) relative to its 6-space insertion indent.
|
|
1054
|
+
const showRssButton = hasFeed && fm.rss === true && !apiOperation;
|
|
1055
|
+
const docsAttrs = [
|
|
1056
|
+
`content={content}`,
|
|
1057
|
+
`sourcePath={${sourcePathLiteral}}`,
|
|
1058
|
+
...(showRssButton ? [`rssHref={${JSON.stringify(feedPath)}}`] : []),
|
|
1059
|
+
];
|
|
1060
|
+
const inlineDocs = `<Docs ${docsAttrs.join(" ")} />`;
|
|
987
1061
|
const docsElement = apiOperation
|
|
988
1062
|
? `<Docs content={content}>
|
|
989
1063
|
<ApiPlayground operation={operation} />
|
|
990
1064
|
</Docs>`
|
|
991
|
-
:
|
|
1065
|
+
: inlineDocs.length + 6 <= 80
|
|
1066
|
+
? inlineDocs
|
|
1067
|
+
: `<Docs\n${docsAttrs.map((attr) => ` ${attr}`).join("\n")}\n />`;
|
|
992
1068
|
const pageContent = `import { Metadata } from "next";
|
|
993
1069
|
import { Docs } from "@/components/Docs";
|
|
994
1070
|
import { config } from "@/utils/config";${apiImport}
|
|
@@ -1017,6 +1093,30 @@ export default function Page() {
|
|
|
1017
1093
|
const pagePath = path.join(this.outputDir, "app", "(site)", mdxFile.slug, "page.tsx");
|
|
1018
1094
|
await fs.ensureDir(path.dirname(pagePath));
|
|
1019
1095
|
await fs.writeFile(pagePath, pageContent, "utf8");
|
|
1096
|
+
// The feed route lives inside the page's directory, so a deleted page
|
|
1097
|
+
// takes its feed along (handleFileDelete removes the whole dir) and the
|
|
1098
|
+
// else-branch prunes the route when a regenerated page no longer has
|
|
1099
|
+
// Update blocks. Cross-run staleness is covered by the app/ wipe in
|
|
1100
|
+
// createNextJSStructure.
|
|
1101
|
+
if (!isSynthetic) {
|
|
1102
|
+
const rssDir = path.join(path.dirname(pagePath), "rss.xml");
|
|
1103
|
+
if (hasFeed) {
|
|
1104
|
+
await fs.ensureDir(rssDir);
|
|
1105
|
+
await fs.writeFile(path.join(rssDir, "route.ts"), rssRouteTemplate({
|
|
1106
|
+
pagePath: mdxFile.slug,
|
|
1107
|
+
title: typeof fm.title === "string" ? fm.title : null,
|
|
1108
|
+
description: typeof fm.description === "string" ? fm.description : null,
|
|
1109
|
+
items: updates.map((update) => ({
|
|
1110
|
+
title: update.label,
|
|
1111
|
+
anchor: update.anchor,
|
|
1112
|
+
description: update.description,
|
|
1113
|
+
})),
|
|
1114
|
+
}), "utf8");
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
await fs.remove(rssDir);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1020
1120
|
}
|
|
1021
1121
|
/** Parses the configured OpenAPI spec(s) into the shared registry. */
|
|
1022
1122
|
async loadOpenApiRegistry() {
|
|
@@ -1103,6 +1203,7 @@ export default function Page() {
|
|
|
1103
1203
|
const dir = path.join(this.outputDir, "app", "(site)", stale);
|
|
1104
1204
|
if (await fs.pathExists(dir)) {
|
|
1105
1205
|
await fs.remove(dir);
|
|
1206
|
+
await this.removeEmptyDirsUpTo(path.dirname(dir), path.join(this.outputDir, "app", "(site)"));
|
|
1106
1207
|
}
|
|
1107
1208
|
}
|
|
1108
1209
|
catch {
|
|
@@ -1112,13 +1213,86 @@ export default function Page() {
|
|
|
1112
1213
|
this.generatedApiPageSlugs = nextSlugs;
|
|
1113
1214
|
await this.writeApiManifest(nextSlugs);
|
|
1114
1215
|
}
|
|
1216
|
+
/**
|
|
1217
|
+
* (Re)points the spec-file watcher at the currently configured spec paths.
|
|
1218
|
+
* Called at startup and whenever doccupine.json changes the `openapi` set,
|
|
1219
|
+
* so specs added mid-session are watched without a restart.
|
|
1220
|
+
*/
|
|
1221
|
+
async syncOpenApiSpecWatcher() {
|
|
1222
|
+
if (this.openApiWatcher) {
|
|
1223
|
+
await this.openApiWatcher.close();
|
|
1224
|
+
this.openApiWatcher = null;
|
|
1225
|
+
}
|
|
1226
|
+
if (this.openApiSpecs.length === 0)
|
|
1227
|
+
return;
|
|
1228
|
+
const specPaths = this.openApiSpecs.map((spec) => path.resolve(this.rootDir, spec.file));
|
|
1229
|
+
this.openApiWatcher = chokidar.watch(specPaths, {
|
|
1230
|
+
persistent: true,
|
|
1231
|
+
ignoreInitial: true,
|
|
1232
|
+
});
|
|
1233
|
+
this.openApiWatcher
|
|
1234
|
+
.on("add", () => this.handleOpenApiChange())
|
|
1235
|
+
.on("change", () => this.handleOpenApiChange())
|
|
1236
|
+
.on("unlink", () => this.handleOpenApiChange())
|
|
1237
|
+
.on("error", (error) => {
|
|
1238
|
+
console.error(chalk.red("❌ OpenAPI watcher error:"), error);
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Reparses the spec(s) and rewrites everything derived from them: the
|
|
1243
|
+
* endpoint pages and allowlist, the sections (the "API Reference" section
|
|
1244
|
+
* appears and disappears with the registry), and the site aggregates.
|
|
1245
|
+
*/
|
|
1246
|
+
async rebuildApiReference() {
|
|
1247
|
+
await this.apiRegistry.load(this.openApiSpecs, this.rootDir, this.apiBaseSlug);
|
|
1248
|
+
this.sectionsConfig = await this.resolveSections();
|
|
1249
|
+
await this.writeApiPages();
|
|
1250
|
+
await this.refreshSiteAggregates();
|
|
1251
|
+
}
|
|
1115
1252
|
/** Reparses the spec(s) and regenerates the API reference on a watch event. */
|
|
1116
1253
|
async handleOpenApiChange() {
|
|
1117
1254
|
console.log(chalk.cyan("📘 OpenAPI spec changed - regenerating API reference"));
|
|
1118
1255
|
try {
|
|
1119
|
-
await this.
|
|
1120
|
-
|
|
1121
|
-
|
|
1256
|
+
await this.rebuildApiReference();
|
|
1257
|
+
console.log(chalk.green("✅ API reference updated"));
|
|
1258
|
+
}
|
|
1259
|
+
catch (error) {
|
|
1260
|
+
console.error(chalk.red("❌ Error updating API reference:"), error);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Applies `openapi` edits in doccupine.json without a restart: reloads the
|
|
1265
|
+
* registry, regenerates or prunes the endpoint pages and allowlist,
|
|
1266
|
+
* refreshes nav/sitemap/llms, and re-points the spec-file watcher. Other
|
|
1267
|
+
* fields (watchDir, outputDir, port) cannot be hot-applied, so a change
|
|
1268
|
+
* there only logs a restart hint. Invalid or missing JSON (e.g. a
|
|
1269
|
+
* half-written editor save) keeps the current configuration.
|
|
1270
|
+
*/
|
|
1271
|
+
async handleDoccupineConfigChange() {
|
|
1272
|
+
const configPath = path.join(this.rootDir, this.doccupineConfigFile);
|
|
1273
|
+
let config;
|
|
1274
|
+
try {
|
|
1275
|
+
config = JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
1276
|
+
}
|
|
1277
|
+
catch {
|
|
1278
|
+
console.warn(chalk.yellow("⚠️ doccupine.json is missing or invalid - keeping the current configuration"));
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if ((config.watchDir &&
|
|
1282
|
+
path.resolve(this.rootDir, config.watchDir) !== this.watchDir) ||
|
|
1283
|
+
(config.outputDir &&
|
|
1284
|
+
path.resolve(this.rootDir, config.outputDir) !== this.outputDir)) {
|
|
1285
|
+
console.log(chalk.yellow("⚠️ watchDir/outputDir changes in doccupine.json need a restart to apply"));
|
|
1286
|
+
}
|
|
1287
|
+
const nextSpecs = normalizeOpenApiConfig(config.openapi);
|
|
1288
|
+
if (JSON.stringify(nextSpecs) === JSON.stringify(this.openApiSpecs)) {
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
console.log(chalk.cyan("📘 OpenAPI configuration changed - updating API reference"));
|
|
1292
|
+
this.openApiSpecs = nextSpecs;
|
|
1293
|
+
try {
|
|
1294
|
+
await this.syncOpenApiSpecWatcher();
|
|
1295
|
+
await this.rebuildApiReference();
|
|
1122
1296
|
console.log(chalk.green("✅ API reference updated"));
|
|
1123
1297
|
}
|
|
1124
1298
|
catch (error) {
|
|
@@ -1478,6 +1652,10 @@ export default function Page() {
|
|
|
1478
1652
|
await this.openApiWatcher.close();
|
|
1479
1653
|
console.log(chalk.yellow("👋 Stopped watching for OpenAPI spec changes"));
|
|
1480
1654
|
}
|
|
1655
|
+
if (this.doccupineConfigWatcher) {
|
|
1656
|
+
await this.doccupineConfigWatcher.close();
|
|
1657
|
+
console.log(chalk.yellow("👋 Stopped watching for doccupine.json changes"));
|
|
1658
|
+
}
|
|
1481
1659
|
if (this.publicWatcher) {
|
|
1482
1660
|
await this.publicWatcher.close();
|
|
1483
1661
|
console.log(chalk.yellow("👋 Stopped watching for public directory changes"));
|
package/dist/lib/metadata.d.ts
CHANGED
|
@@ -36,6 +36,11 @@ export interface MetadataOptions {
|
|
|
36
36
|
* Resolves against `metadataBase` defined in the root layout.
|
|
37
37
|
*/
|
|
38
38
|
canonicalPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Path of this page's RSS feed, e.g. "/update/rss.xml". Emitted as an
|
|
41
|
+
* `alternates.types` entry so feed readers can autodiscover the feed.
|
|
42
|
+
*/
|
|
43
|
+
rssPath?: string;
|
|
39
44
|
}
|
|
40
45
|
export declare function generateMetadataBlock(opts: MetadataOptions): string;
|
|
41
46
|
export declare function generateRuntimeOnlyMetadataBlock(): string;
|
package/dist/lib/metadata.js
CHANGED
|
@@ -105,20 +105,31 @@ function buildTitleExpression(opts) {
|
|
|
105
105
|
: `\${config.name ? config.name + " -" : "${DEFAULT_SITE_NAME} -"}`;
|
|
106
106
|
return `${prefix} ${title}`;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function buildAlternatesBlock(canonicalPath, rssPath) {
|
|
109
109
|
if (canonicalPath === undefined)
|
|
110
110
|
return "";
|
|
111
111
|
const safePath = canonicalPath.replace(/^\/+/, "");
|
|
112
|
-
// Relative
|
|
112
|
+
// Relative paths resolve against `metadataBase` set in the root layout.
|
|
113
113
|
// Empty string means the homepage canonical equals the base URL itself.
|
|
114
|
-
|
|
114
|
+
const canonical = JSON.stringify("/" + safePath);
|
|
115
|
+
if (!rssPath)
|
|
116
|
+
return `\n alternates: { canonical: ${canonical} },`;
|
|
117
|
+
const rss = JSON.stringify(rssPath);
|
|
118
|
+
// Prettier preserves an object literal that already breaks after "{", so
|
|
119
|
+
// the expanded form is stable; only the inner `types` line can overflow
|
|
120
|
+
// the 80-col print width (long slugs) and needs the pre-wrap check.
|
|
121
|
+
const typesInline = ` types: { "application/rss+xml": ${rss} },`;
|
|
122
|
+
const typesLines = typesInline.length <= 80
|
|
123
|
+
? typesInline
|
|
124
|
+
: ` types: {\n "application/rss+xml": ${rss},\n },`;
|
|
125
|
+
return `\n alternates: {\n canonical: ${canonical},\n${typesLines}\n },`;
|
|
115
126
|
}
|
|
116
127
|
export function generateMetadataBlock(opts) {
|
|
117
128
|
const title = buildTitleExpression(opts);
|
|
118
129
|
const desc = buildFieldExpression(opts.description, "description", DEFAULT_META_DESCRIPTION);
|
|
119
130
|
const icon = buildFieldExpression(opts.icon, "icon", DEFAULT_FAVICON);
|
|
120
131
|
const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
|
|
121
|
-
const canonical =
|
|
132
|
+
const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
|
|
122
133
|
return `export const metadata: Metadata = {
|
|
123
134
|
title: \`${title}\`,
|
|
124
135
|
description: \`${desc}\`,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function slugify(text: string): string;
|
|
2
|
+
export type Slugger = (text: string) => string;
|
|
3
|
+
export declare function createSlugger(): Slugger;
|
|
4
|
+
export interface UpdateFeedItem {
|
|
5
|
+
/** The Update's `label` attribute; doubles as the feed entry title. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Anchor id the generated app assigns this entry (see parity note above). */
|
|
8
|
+
anchor: string;
|
|
9
|
+
/**
|
|
10
|
+
* Feed entry text: the `rss` attribute when present, otherwise the block's
|
|
11
|
+
* children reduced to pure Markdown (components, code, and HTML removed).
|
|
12
|
+
*/
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseUpdateBlocks(mdx: string): UpdateFeedItem[];
|
|
16
|
+
/**
|
|
17
|
+
* Reduce an Update block's children to pure Markdown for feed readers:
|
|
18
|
+
* components, code, and HTML are removed (tag children text survives),
|
|
19
|
+
* images collapse to their alt text, inline code keeps its text. Markdown
|
|
20
|
+
* inline syntax (emphasis, links, lists, headings) passes through, including
|
|
21
|
+
* autolinks - `<https://...>` never matches the tag pattern because a `:`
|
|
22
|
+
* follows the leading word characters.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toRssMarkdown(inner: string): string;
|
package/dist/lib/rss.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Feed extraction for subscribable changelogs: pages that contain <Update>
|
|
2
|
+
// blocks publish an RSS feed at {page-url}/rss.xml.
|
|
3
|
+
//
|
|
4
|
+
// Anchor parity is the load-bearing constraint here. Feed entry links are
|
|
5
|
+
// `{pageUrl}#{anchor}`, and the anchor must byte-match the id the generated
|
|
6
|
+
// app assigns: one shared slugger walks the fenced-code-stripped document
|
|
7
|
+
// collecting markdown headings AND <Update label> open tags in byte order
|
|
8
|
+
// (components/Docs.tsx `extractHeadings` + components/MDXComponents.tsx).
|
|
9
|
+
// `slugify`/`createSlugger` below are byte-exact ports of the generated
|
|
10
|
+
// app's components/layout/Slug.ts, and `parseUpdateBlocks` replays that
|
|
11
|
+
// exact walk - headings consume slugger slots too, so an `## Setup` before
|
|
12
|
+
// `<Update label="Setup">` pushes the entry's anchor to "setup-1".
|
|
13
|
+
// rss.test.ts guards both ports against template drift.
|
|
14
|
+
export function slugify(text) {
|
|
15
|
+
return (text ?? "")
|
|
16
|
+
.toLowerCase()
|
|
17
|
+
.replace(/[^\w\s-]/g, "")
|
|
18
|
+
.replace(/\s+/g, "-")
|
|
19
|
+
.trim();
|
|
20
|
+
}
|
|
21
|
+
export function createSlugger() {
|
|
22
|
+
const seen = new Map();
|
|
23
|
+
return (text) => {
|
|
24
|
+
const base = slugify(text);
|
|
25
|
+
const count = seen.get(base) ?? 0;
|
|
26
|
+
seen.set(base, count + 1);
|
|
27
|
+
return count === 0 ? base : `${base}-${count}`;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function parseUpdateBlocks(mdx) {
|
|
31
|
+
// Fenced code is stripped before any matching, mirroring extractHeadings:
|
|
32
|
+
// an <Update> example inside a fence is not an entry, and positions below
|
|
33
|
+
// are measured in the stripped string on both sides of the parity contract.
|
|
34
|
+
const content = mdx.replace(/```[\s\S]*?```/g, "");
|
|
35
|
+
const entries = [];
|
|
36
|
+
let match;
|
|
37
|
+
const headingRegex = /^(#{1,6})\s+(.+)$/gm;
|
|
38
|
+
while ((match = headingRegex.exec(content)) !== null) {
|
|
39
|
+
entries.push({
|
|
40
|
+
kind: "heading",
|
|
41
|
+
text: match[2].trim(),
|
|
42
|
+
position: match.index,
|
|
43
|
+
tag: "",
|
|
44
|
+
tagEnd: 0,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// [^>] spans newlines, so multi-line open tags match - same as the app.
|
|
48
|
+
const updateRegex = /<Update\b[^>]*?\blabel=["']([^"']+)["'][^>]*>/g;
|
|
49
|
+
while ((match = updateRegex.exec(content)) !== null) {
|
|
50
|
+
entries.push({
|
|
51
|
+
kind: "update",
|
|
52
|
+
text: match[1].trim(),
|
|
53
|
+
position: match.index,
|
|
54
|
+
tag: match[0],
|
|
55
|
+
tagEnd: match.index + match[0].length,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
entries.sort((a, b) => a.position - b.position);
|
|
59
|
+
const slug = createSlugger();
|
|
60
|
+
const items = [];
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
const anchor = slug(entry.text);
|
|
63
|
+
if (entry.kind !== "update")
|
|
64
|
+
continue;
|
|
65
|
+
const rssAttr = /\brss=["']([^"']*)["']/.exec(entry.tag)?.[1];
|
|
66
|
+
const inner = entry.tag.endsWith("/>")
|
|
67
|
+
? ""
|
|
68
|
+
: extractInner(content, entry.tagEnd);
|
|
69
|
+
items.push({
|
|
70
|
+
label: entry.text,
|
|
71
|
+
anchor,
|
|
72
|
+
description: rssAttr !== undefined ? rssAttr.trim() : toRssMarkdown(inner),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return items;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Slice out an Update block's children: scan from the end of its open tag to
|
|
79
|
+
* the matching close tag, tracking depth so nested <Update> blocks close
|
|
80
|
+
* correctly. An unclosed block runs to the end of the document (the renderer
|
|
81
|
+
* swallows the rest of the page in that case too).
|
|
82
|
+
*/
|
|
83
|
+
function extractInner(content, from) {
|
|
84
|
+
const token = /<Update\b[^>]*?>|<\/Update\s*>/g;
|
|
85
|
+
token.lastIndex = from;
|
|
86
|
+
let depth = 1;
|
|
87
|
+
let match;
|
|
88
|
+
while ((match = token.exec(content)) !== null) {
|
|
89
|
+
if (match[0].startsWith("</")) {
|
|
90
|
+
depth -= 1;
|
|
91
|
+
if (depth === 0)
|
|
92
|
+
return content.slice(from, match.index);
|
|
93
|
+
}
|
|
94
|
+
else if (!match[0].endsWith("/>")) {
|
|
95
|
+
depth += 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return content.slice(from);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Reduce an Update block's children to pure Markdown for feed readers:
|
|
102
|
+
* components, code, and HTML are removed (tag children text survives),
|
|
103
|
+
* images collapse to their alt text, inline code keeps its text. Markdown
|
|
104
|
+
* inline syntax (emphasis, links, lists, headings) passes through, including
|
|
105
|
+
* autolinks - `<https://...>` never matches the tag pattern because a `:`
|
|
106
|
+
* follows the leading word characters.
|
|
107
|
+
*/
|
|
108
|
+
export function toRssMarkdown(inner) {
|
|
109
|
+
const stripped = inner
|
|
110
|
+
.replace(/```[\s\S]*?```/g, "")
|
|
111
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
112
|
+
.replace(/<\/?[A-Za-z][a-zA-Z0-9]*(?:\s[^>]*)?\/?>/g, "")
|
|
113
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
114
|
+
.replace(/`([^`]*)`/g, "$1");
|
|
115
|
+
return dedent(stripped)
|
|
116
|
+
.replace(/[ \t]+$/gm, "")
|
|
117
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
118
|
+
.trim();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Update children are conventionally indented under the open tag; strip the
|
|
122
|
+
* common leading indentation so lists and headings arrive at column 0.
|
|
123
|
+
*/
|
|
124
|
+
function dedent(text) {
|
|
125
|
+
const lines = text.split("\n");
|
|
126
|
+
let minIndent = Infinity;
|
|
127
|
+
for (const line of lines) {
|
|
128
|
+
if (line.trim() === "")
|
|
129
|
+
continue;
|
|
130
|
+
const indent = /^ */.exec(line)[0].length;
|
|
131
|
+
if (indent < minIndent)
|
|
132
|
+
minIndent = indent;
|
|
133
|
+
}
|
|
134
|
+
if (!Number.isFinite(minIndent) || minIndent === 0)
|
|
135
|
+
return text;
|
|
136
|
+
return lines.map((line) => line.slice(minIndent)).join("\n");
|
|
137
|
+
}
|