doccupine 0.0.134 → 0.0.136
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 +11 -9
- package/dist/index.js +282 -46
- 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 +83 -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
|
|
@@ -88,6 +89,7 @@ updated: "2025-02-01" # Last-modified date (JSON-LD dateModified)
|
|
|
88
89
|
section: "API Reference" # Section this page belongs to
|
|
89
90
|
sectionOrder: 1 # Sort order for the section in the tab bar
|
|
90
91
|
openapi: "GET /users/{id}" # Embed an API playground for this endpoint (see API Reference)
|
|
92
|
+
rss: true # Show an RSS button linking to the page's feed (pages with Update components)
|
|
91
93
|
---
|
|
92
94
|
```
|
|
93
95
|
|
|
@@ -181,16 +183,16 @@ openapi: "GET /users/{id}"
|
|
|
181
183
|
|
|
182
184
|
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
185
|
|
|
184
|
-
| File | Purpose
|
|
185
|
-
| ----------------- |
|
|
186
|
+
| File | Purpose |
|
|
187
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
186
188
|
| `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)
|
|
189
|
+
| `config.json` | Site metadata: `name`, `description`, `icon`, `image`, `url` (public site URL for sitemap/robots) |
|
|
190
|
+
| `theme.json` | Theme overrides for [cherry-styled-components](https://github.com/cherry-design-system/styled-components) |
|
|
191
|
+
| `navigation.json` | Manual navigation structure (overrides auto-generated) |
|
|
192
|
+
| `links.json` | Static header/footer links |
|
|
193
|
+
| `fonts.json` | Font configuration (Google Fonts or local) |
|
|
194
|
+
| `sections.json` | Section definitions for tabbed doc groups (see [Sections](#sections)) |
|
|
195
|
+
| `analytics.json` | Analytics provider configuration (PostHog supported) |
|
|
194
196
|
|
|
195
197
|
## Public Directory
|
|
196
198
|
|
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) {
|
|
@@ -1147,10 +1321,17 @@ export default function Page() {
|
|
|
1147
1321
|
openapi: typeof frontmatter.openapi === "string"
|
|
1148
1322
|
? frontmatter.openapi
|
|
1149
1323
|
: undefined,
|
|
1324
|
+
rss: frontmatter.rss === true,
|
|
1150
1325
|
};
|
|
1151
1326
|
break;
|
|
1152
1327
|
}
|
|
1153
1328
|
}
|
|
1329
|
+
// The homepage publishes the same subscribable changelog as any other
|
|
1330
|
+
// page (see generatePageFromMDX): <Update> blocks feed the site-root
|
|
1331
|
+
// /rss.xml, and `rss: true` frontmatter opts into the RSS button.
|
|
1332
|
+
const updates = indexMDX ? parseUpdateBlocks(indexMDX.content) : [];
|
|
1333
|
+
const hasFeed = updates.length > 0;
|
|
1334
|
+
const feedPath = "/rss.xml";
|
|
1154
1335
|
const metadataBlock = indexMDX
|
|
1155
1336
|
? generateMetadataBlock({
|
|
1156
1337
|
title: indexMDX.title,
|
|
@@ -1161,6 +1342,7 @@ export default function Page() {
|
|
|
1161
1342
|
icon: indexMDX.icon,
|
|
1162
1343
|
image: indexMDX.image,
|
|
1163
1344
|
canonicalPath: "",
|
|
1345
|
+
rssPath: hasFeed ? feedPath : undefined,
|
|
1164
1346
|
})
|
|
1165
1347
|
: generateRuntimeOnlyMetadataBlock();
|
|
1166
1348
|
const homeJsonLd = generateJsonLdScript({
|
|
@@ -1187,11 +1369,18 @@ export default function Page() {
|
|
|
1187
1369
|
const apiConst = apiOperation
|
|
1188
1370
|
? `\nconst operation = JSON.parse(${JSON.stringify(JSON.stringify(apiOperation))});\n`
|
|
1189
1371
|
: "";
|
|
1372
|
+
// Same gating as generatePageFromMDX: the playground branch keeps its
|
|
1373
|
+
// fixed JSX shape, so a feed on a playground homepage stays reachable via
|
|
1374
|
+
// autodiscovery. The buttoned inline form stays within the 80-col print
|
|
1375
|
+
// width at its 6-space insertion indent, so it is Prettier-stable as is.
|
|
1376
|
+
const showRssButton = hasFeed && indexMDX?.rss === true && !apiOperation;
|
|
1190
1377
|
const docsElement = apiOperation
|
|
1191
1378
|
? `<Docs content={content} sourcePath="index.mdx">
|
|
1192
1379
|
<ApiPlayground operation={operation} />
|
|
1193
1380
|
</Docs>`
|
|
1194
|
-
:
|
|
1381
|
+
: showRssButton
|
|
1382
|
+
? `<Docs content={content} sourcePath="index.mdx" rssHref={"/rss.xml"} />`
|
|
1383
|
+
: `<Docs content={content} sourcePath="index.mdx" />`;
|
|
1195
1384
|
const indexContent = `import { Metadata } from "next";
|
|
1196
1385
|
import { Docs } from "@/components/Docs";
|
|
1197
1386
|
import { config } from "@/utils/config";${apiImport}
|
|
@@ -1217,8 +1406,38 @@ export default function Home() {
|
|
|
1217
1406
|
const homePath = path.join(this.outputDir, "app", "(site)", "page.tsx");
|
|
1218
1407
|
await fs.ensureDir(path.dirname(homePath));
|
|
1219
1408
|
await fs.writeFile(homePath, indexContent, "utf8");
|
|
1409
|
+
// Same lifecycle as the per-page feeds in generatePageFromMDX: write the
|
|
1410
|
+
// root feed route while the homepage has Update blocks, prune it when
|
|
1411
|
+
// they go away or index.mdx is deleted (this runs on every aggregate
|
|
1412
|
+
// refresh, including the delete path).
|
|
1413
|
+
const rssDir = path.join(this.outputDir, "app", "(site)", "rss.xml");
|
|
1414
|
+
if (hasFeed && indexMDX) {
|
|
1415
|
+
await fs.ensureDir(rssDir);
|
|
1416
|
+
await fs.writeFile(path.join(rssDir, "route.ts"), rssRouteTemplate({
|
|
1417
|
+
pagePath: "",
|
|
1418
|
+
title: indexMDX.title,
|
|
1419
|
+
description: indexMDX.description || null,
|
|
1420
|
+
items: updates.map((update) => ({
|
|
1421
|
+
title: update.label,
|
|
1422
|
+
anchor: update.anchor,
|
|
1423
|
+
description: update.description,
|
|
1424
|
+
})),
|
|
1425
|
+
}), "utf8");
|
|
1426
|
+
}
|
|
1427
|
+
else {
|
|
1428
|
+
await fs.remove(rssDir);
|
|
1429
|
+
}
|
|
1220
1430
|
}
|
|
1221
1431
|
async updateSectionIndex(sectionSlug, frontmatter, mdxContent, sourcePath) {
|
|
1432
|
+
// This overwrites the page generatePageFromMDX just wrote for the same
|
|
1433
|
+
// slug (section landings compose their metadata name-first), so the RSS
|
|
1434
|
+
// state must be re-derived here or the overwrite silently drops the
|
|
1435
|
+
// button and autodiscovery - the feed route survives either way since it
|
|
1436
|
+
// lives in a sibling rss.xml/ dir.
|
|
1437
|
+
const updates = parseUpdateBlocks(mdxContent);
|
|
1438
|
+
const hasFeed = updates.length > 0;
|
|
1439
|
+
const feedPath = `/${sectionSlug}/rss.xml`;
|
|
1440
|
+
const showRssButton = hasFeed && frontmatter.rss === true;
|
|
1222
1441
|
const metadataBlock = generateMetadataBlock({
|
|
1223
1442
|
title: frontmatter.title,
|
|
1224
1443
|
titleFallback: "Section",
|
|
@@ -1228,6 +1447,7 @@ export default function Home() {
|
|
|
1228
1447
|
icon: frontmatter.icon,
|
|
1229
1448
|
image: frontmatter.image,
|
|
1230
1449
|
canonicalPath: sectionSlug,
|
|
1450
|
+
rssPath: hasFeed ? feedPath : undefined,
|
|
1231
1451
|
});
|
|
1232
1452
|
const sectionJsonLd = generateJsonLdScript({
|
|
1233
1453
|
kind: "article",
|
|
@@ -1242,6 +1462,18 @@ export default function Home() {
|
|
|
1242
1462
|
: undefined,
|
|
1243
1463
|
image: frontmatter.image,
|
|
1244
1464
|
});
|
|
1465
|
+
// Same Prettier pre-wrap contract as generatePageFromMDX: the buttoned
|
|
1466
|
+
// form usually pushes the line past the 80-col print width, so emit it
|
|
1467
|
+
// with attributes on their own lines relative to the 6-space indent.
|
|
1468
|
+
const docsAttrs = [
|
|
1469
|
+
`content={content}`,
|
|
1470
|
+
`sourcePath={${JSON.stringify(sourcePath ?? `${sectionSlug}/index.mdx`)}}`,
|
|
1471
|
+
...(showRssButton ? [`rssHref={${JSON.stringify(feedPath)}}`] : []),
|
|
1472
|
+
];
|
|
1473
|
+
const inlineDocs = `<Docs ${docsAttrs.join(" ")} />`;
|
|
1474
|
+
const docsElement = inlineDocs.length + 6 <= 80
|
|
1475
|
+
? inlineDocs
|
|
1476
|
+
: `<Docs\n${docsAttrs.map((attr) => ` ${attr}`).join("\n")}\n />`;
|
|
1245
1477
|
const indexContent = `import { Metadata } from "next";
|
|
1246
1478
|
import { Docs } from "@/components/Docs";
|
|
1247
1479
|
import { config } from "@/utils/config";
|
|
@@ -1259,7 +1491,7 @@ export default function Page() {
|
|
|
1259
1491
|
return (
|
|
1260
1492
|
<>
|
|
1261
1493
|
${sectionJsonLd.element}
|
|
1262
|
-
|
|
1494
|
+
${docsElement}
|
|
1263
1495
|
</>
|
|
1264
1496
|
);
|
|
1265
1497
|
}
|
|
@@ -1478,6 +1710,10 @@ export default function Page() {
|
|
|
1478
1710
|
await this.openApiWatcher.close();
|
|
1479
1711
|
console.log(chalk.yellow("👋 Stopped watching for OpenAPI spec changes"));
|
|
1480
1712
|
}
|
|
1713
|
+
if (this.doccupineConfigWatcher) {
|
|
1714
|
+
await this.doccupineConfigWatcher.close();
|
|
1715
|
+
console.log(chalk.yellow("👋 Stopped watching for doccupine.json changes"));
|
|
1716
|
+
}
|
|
1481
1717
|
if (this.publicWatcher) {
|
|
1482
1718
|
await this.publicWatcher.close();
|
|
1483
1719
|
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;
|