doccupine 0.0.147 → 0.0.149

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.
Files changed (55) hide show
  1. package/dist/generator/app-scaffolder.js +1 -0
  2. package/dist/generator/icon-asset-manager.d.ts +13 -0
  3. package/dist/generator/icon-asset-manager.js +87 -0
  4. package/dist/generator/page-renderer.js +14 -3
  5. package/dist/generator/project-config-repository.d.ts +3 -1
  6. package/dist/generator/project-config-repository.js +9 -1
  7. package/dist/generator/public-asset-manager.d.ts +1 -0
  8. package/dist/generator/public-asset-manager.js +11 -0
  9. package/dist/generator/watch-coordinator.d.ts +2 -0
  10. package/dist/generator/watch-coordinator.js +31 -2
  11. package/dist/lib/generated-artifacts.d.ts +3 -0
  12. package/dist/lib/generated-artifacts.js +23 -0
  13. package/dist/lib/layout.js +14 -4
  14. package/dist/lib/metadata.js +8 -8
  15. package/dist/lib/output-safety.js +1 -0
  16. package/dist/lib/structures.js +2 -2
  17. package/dist/mdx-to-nextjs-generator.d.ts +2 -0
  18. package/dist/mdx-to-nextjs-generator.js +10 -1
  19. package/dist/templates/app/theme.d.ts +1 -1
  20. package/dist/templates/app/theme.js +1 -2
  21. package/dist/templates/components/Chat.d.ts +1 -1
  22. package/dist/templates/components/Chat.js +235 -795
  23. package/dist/templates/components/SearchDocs.d.ts +1 -1
  24. package/dist/templates/components/SearchDocs.js +20 -15
  25. package/dist/templates/components/SearchModalContent.d.ts +1 -1
  26. package/dist/templates/components/SearchModalContent.js +7 -1
  27. package/dist/templates/components/layout/CherryThemeProvider.d.ts +1 -1
  28. package/dist/templates/components/layout/CherryThemeProvider.js +33 -30
  29. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  30. package/dist/templates/components/layout/DocsComponents.js +9 -8
  31. package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
  32. package/dist/templates/components/layout/DocsNavigation.js +2 -3
  33. package/dist/templates/components/layout/Footer.d.ts +1 -1
  34. package/dist/templates/components/layout/Footer.js +2 -4
  35. package/dist/templates/components/layout/Header.d.ts +1 -1
  36. package/dist/templates/components/layout/Header.js +3 -3
  37. package/dist/templates/components/layout/StaticLinks.d.ts +1 -1
  38. package/dist/templates/components/layout/StaticLinks.js +2 -3
  39. package/dist/templates/env.example.d.ts +1 -1
  40. package/dist/templates/env.example.js +8 -0
  41. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  42. package/dist/templates/mdx/commands.mdx.js +17 -1
  43. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  44. package/dist/templates/mdx/globals.mdx.js +27 -4
  45. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  46. package/dist/templates/mdx/media-and-assets.mdx.js +3 -7
  47. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  48. package/dist/templates/mdx/theme.mdx.js +2 -0
  49. package/dist/templates/next.config.js +40 -0
  50. package/dist/templates/package.js +11 -11
  51. package/dist/templates/utils/icons.d.ts +1 -0
  52. package/dist/templates/utils/icons.js +44 -0
  53. package/package.json +4 -4
  54. package/dist/templates/components/ChatStyles.d.ts +0 -1
  55. package/dist/templates/components/ChatStyles.js +0 -695
@@ -27,6 +27,7 @@ export class AppScaffolder {
27
27
  "proxy.ts": proxyTemplate(analyticsConfig),
28
28
  "analytics.json": `{}\n`,
29
29
  "config.json": `{}\n`,
30
+ "icons.json": `{}\n`,
30
31
  "links.json": `[]\n`,
31
32
  "navigation.json": `[]\n`,
32
33
  "sections.json": `[]\n`,
@@ -0,0 +1,13 @@
1
+ import { GeneratedArtifacts } from "../lib/generated-artifacts.js";
2
+ import { SecureSourceFs } from "./secure-source-fs.js";
3
+ export declare const ICON_SOURCE_FILES: readonly ["icon.png", "icon-dark.png", "apple-icon.png"];
4
+ export declare class IconAssetManager {
5
+ private readonly rootDir;
6
+ private readonly outputDir;
7
+ private readonly artifacts;
8
+ private readonly sourceFs;
9
+ private readonly readIconSourceFile;
10
+ constructor(rootDir: string, outputDir: string, artifacts: GeneratedArtifacts, sourceFs: SecureSourceFs, readIconSourceFile: (fileName: string) => Promise<Buffer | null>);
11
+ private outputPath;
12
+ syncIconFiles(): Promise<void>;
13
+ }
@@ -0,0 +1,87 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs-extra";
3
+ import { createHash } from "node:crypto";
4
+ import path from "node:path";
5
+ import { resolveOutputPath } from "../lib/output-safety.js";
6
+ import { writeFileAtomic } from "../lib/utils.js";
7
+ // Next.js-style icon file conventions, read from the project root. The files
8
+ // are copied to the generated public/ directory and referenced through
9
+ // icons.json instead of Next's app/ file convention, because file-based icons
10
+ // override config-based metadata entirely and have no dark-variant form.
11
+ export const ICON_SOURCE_FILES = [
12
+ "icon.png",
13
+ "icon-dark.png",
14
+ "apple-icon.png",
15
+ ];
16
+ const ICON_MANIFEST_KEYS = {
17
+ "icon.png": "icon",
18
+ "icon-dark.png": "iconDark",
19
+ "apple-icon.png": "appleIcon",
20
+ };
21
+ const ICONS_JSON_FILE = "icons.json";
22
+ export class IconAssetManager {
23
+ rootDir;
24
+ outputDir;
25
+ artifacts;
26
+ sourceFs;
27
+ readIconSourceFile;
28
+ constructor(rootDir, outputDir, artifacts, sourceFs, readIconSourceFile) {
29
+ this.rootDir = rootDir;
30
+ this.outputDir = outputDir;
31
+ this.artifacts = artifacts;
32
+ this.sourceFs = sourceFs;
33
+ this.readIconSourceFile = readIconSourceFile;
34
+ }
35
+ outputPath(...segments) {
36
+ return resolveOutputPath(this.outputDir, ...segments);
37
+ }
38
+ async syncIconFiles() {
39
+ console.log(chalk.blue(`🔍 Checking for icon files...`));
40
+ const sources = new Map();
41
+ for (const fileName of ICON_SOURCE_FILES) {
42
+ const data = await this.readIconSourceFile(fileName);
43
+ if (data !== null)
44
+ sources.set(fileName, data);
45
+ }
46
+ // A root icon file and a user public/ file would publish the same URL.
47
+ // Refuse before writing anything so a failed sync leaves output untouched.
48
+ for (const fileName of sources.keys()) {
49
+ const publicSource = await this.sourceFs.findPublicAsset(fileName);
50
+ if (publicSource !== null) {
51
+ throw new Error(`Conflicting icon sources: ${path.join(this.rootDir, fileName)} ` +
52
+ `and ${publicSource} both publish public/${fileName}. ` +
53
+ `Remove one of them.`);
54
+ }
55
+ }
56
+ if (sources.has("icon-dark.png") && !sources.has("icon.png")) {
57
+ console.warn(chalk.yellow(`⚠️ icon-dark.png found without icon.png - the dark variant only ` +
58
+ `applies alongside a light icon, skipping it`));
59
+ sources.delete("icon-dark.png");
60
+ }
61
+ const manifest = {};
62
+ const nextFiles = new Set();
63
+ for (const fileName of ICON_SOURCE_FILES) {
64
+ const data = sources.get(fileName);
65
+ if (!data)
66
+ continue;
67
+ const hash = createHash("sha256").update(data).digest("hex").slice(0, 8);
68
+ await writeFileAtomic(this.outputPath("public", fileName), data);
69
+ manifest[ICON_MANIFEST_KEYS[fileName]] = `/${fileName}?v=${hash}`;
70
+ nextFiles.add(fileName);
71
+ }
72
+ await writeFileAtomic(this.outputPath(ICONS_JSON_FILE), nextFiles.size > 0 ? `${JSON.stringify(manifest, null, 2)}\n` : `{}\n`);
73
+ for (const stale of this.artifacts.iconFiles()) {
74
+ if (!nextFiles.has(stale)) {
75
+ await fs.remove(this.outputPath("public", stale));
76
+ }
77
+ }
78
+ this.artifacts.replaceIconFiles(nextFiles);
79
+ await this.artifacts.save();
80
+ if (nextFiles.size > 0) {
81
+ console.log(chalk.green(` ✓ Copied ${[...nextFiles].join(", ")} to Next.js app`));
82
+ }
83
+ else {
84
+ console.log(chalk.gray(` ✗ no icon files found, skipping`));
85
+ }
86
+ }
87
+ }
@@ -68,9 +68,10 @@ export function renderMdxPage(mdxFile, options) {
68
68
  : inlineDocs.length + 6 <= 80
69
69
  ? inlineDocs
70
70
  : `<Docs\n${docsAttrs.map((attr) => ` ${attr}`).join("\n")}\n />`;
71
+ const iconsImport = iconsImportLine(metadataBlock, jsonLd.declarations);
71
72
  const pageContent = `import { Metadata } from "next";
72
73
  import { Docs } from "@/components/Docs";
73
- import { config } from "@/utils/config";${apiImport}
74
+ import { config } from "@/utils/config";${iconsImport}${apiImport}
74
75
 
75
76
  const content = \`${escapeTemplateContent(mdxFile.content)}\`;
76
77
  ${apiConst}
@@ -112,6 +113,14 @@ export default function Page() {
112
113
  : { action: "remove" };
113
114
  return { pageContent, rssRoute };
114
115
  }
116
+ // Pages with a frontmatter icon and image reference neither export; scanning
117
+ // only the generated metadata/JSON-LD code keeps their imports unused-free.
118
+ function iconsImportLine(...codeBlocks) {
119
+ const names = ["primaryIconUrl", "siteIcons"].filter((name) => codeBlocks.some((block) => block.includes(name)));
120
+ return names.length > 0
121
+ ? `\nimport { ${names.join(", ")} } from "@/utils/icons";`
122
+ : "";
123
+ }
115
124
  export function renderHomepage(indexMDX, apiOperation) {
116
125
  const updates = indexMDX ? parseUpdateBlocks(indexMDX.content) : [];
117
126
  const hasFeed = updates.length > 0;
@@ -150,9 +159,10 @@ export function renderHomepage(indexMDX, apiOperation) {
150
159
  : showRssButton
151
160
  ? `<Docs content={content} sourcePath="index.mdx" rssHref={"/rss.xml"} />`
152
161
  : `<Docs content={content} sourcePath="index.mdx" />`;
162
+ const iconsImport = iconsImportLine(metadataBlock, homeJsonLd.declarations);
153
163
  const pageContent = `import { Metadata } from "next";
154
164
  import { Docs } from "@/components/Docs";
155
- import { config } from "@/utils/config";${apiImport}
165
+ import { config } from "@/utils/config";${iconsImport}${apiImport}
156
166
 
157
167
  ${indexMDX ? `const content = \`${escapeTemplateContent(indexMDX.content)}\`;` : `const content = null;`}
158
168
  ${apiConst}
@@ -227,9 +237,10 @@ export function renderSectionPage(sectionSlug, frontmatter, mdxContent, sourcePa
227
237
  const docsElement = inlineDocs.length + 6 <= 80
228
238
  ? inlineDocs
229
239
  : `<Docs\n${docsAttrs.map((attr) => ` ${attr}`).join("\n")}\n />`;
240
+ const iconsImport = iconsImportLine(metadataBlock, sectionJsonLd.declarations);
230
241
  const pageContent = `import { Metadata } from "next";
231
242
  import { Docs } from "@/components/Docs";
232
- import { config } from "@/utils/config";
243
+ import { config } from "@/utils/config";${iconsImport}
233
244
 
234
245
  const content = \`${escapeTemplateContent(mdxContent)}\`;
235
246
 
@@ -7,14 +7,16 @@ export declare class ProjectConfigRepository {
7
7
  private readonly configFiles;
8
8
  private readonly fontConfigFile;
9
9
  private readonly analyticsConfigFile;
10
+ private readonly iconFiles;
10
11
  private sourceSnapshot;
11
- constructor(rootDir: string, outputDir: string, sourceFs: SecureSourceFs, configFiles: readonly string[], fontConfigFile: string, analyticsConfigFile: string);
12
+ constructor(rootDir: string, outputDir: string, sourceFs: SecureSourceFs, configFiles: readonly string[], fontConfigFile: string, analyticsConfigFile: string, iconFiles?: readonly string[]);
12
13
  private outputPath;
13
14
  private hasRootSourceFile;
14
15
  private readRootSourceFile;
15
16
  private copyRootSourceFile;
16
17
  private readOptionalRootSourceFile;
17
18
  readConfigFile(): Promise<string | null>;
19
+ readOptionalRootBinaryFile(fileName: string, label: string): Promise<Buffer | null>;
18
20
  preflightSourceFiles(): Promise<void>;
19
21
  sourceSnapshotStates(): Record<string, string>;
20
22
  clearSourceSnapshot(): void;
@@ -18,14 +18,16 @@ export class ProjectConfigRepository {
18
18
  configFiles;
19
19
  fontConfigFile;
20
20
  analyticsConfigFile;
21
+ iconFiles;
21
22
  sourceSnapshot = null;
22
- constructor(rootDir, outputDir, sourceFs, configFiles, fontConfigFile, analyticsConfigFile) {
23
+ constructor(rootDir, outputDir, sourceFs, configFiles, fontConfigFile, analyticsConfigFile, iconFiles = []) {
23
24
  this.rootDir = rootDir;
24
25
  this.outputDir = outputDir;
25
26
  this.sourceFs = sourceFs;
26
27
  this.configFiles = configFiles;
27
28
  this.fontConfigFile = fontConfigFile;
28
29
  this.analyticsConfigFile = analyticsConfigFile;
30
+ this.iconFiles = iconFiles;
29
31
  }
30
32
  outputPath(...segments) {
31
33
  return resolveOutputPath(this.outputDir, ...segments);
@@ -61,11 +63,17 @@ export class ProjectConfigRepository {
61
63
  async readConfigFile() {
62
64
  return this.readOptionalRootSourceFile("config.json", "config source");
63
65
  }
66
+ async readOptionalRootBinaryFile(fileName, label) {
67
+ if (!(await this.hasRootSourceFile(fileName)))
68
+ return null;
69
+ return this.readRootSourceFile(path.join(this.rootDir, fileName), label);
70
+ }
64
71
  async preflightSourceFiles() {
65
72
  const sources = [
66
73
  ...this.configFiles.map((fileName) => [fileName, "config source"]),
67
74
  [this.fontConfigFile, "font source"],
68
75
  [this.analyticsConfigFile, "analytics source"],
76
+ ...this.iconFiles.map((fileName) => [fileName, "icon source"]),
69
77
  ];
70
78
  const snapshot = new Map();
71
79
  for (const [fileName, label] of sources) {
@@ -10,6 +10,7 @@ export declare class PublicAssetManager {
10
10
  private outputPath;
11
11
  publicOutputFilePath(relativePath: string): string;
12
12
  copyRegularPublicFile(sourcePath: string, destPath: string): Promise<void>;
13
+ private assertNotTrackedIconFile;
13
14
  copyPublicFiles(): Promise<void>;
14
15
  handlePublicFileChange(filePath: string, restoreGeneratedArtifacts: () => Promise<void>): Promise<void>;
15
16
  handlePublicFileDelete(filePath: string, copyCurrentSource: () => Promise<void>, restoreGeneratedArtifacts: () => Promise<void>): Promise<void>;
@@ -51,6 +51,15 @@ export class PublicAssetManager {
51
51
  const { data } = await this.sourceFs.readPublicSourceFile(sourcePath);
52
52
  await writeFileAtomic(destPath, data);
53
53
  }
54
+ // A tracked root icon file already publishes this URL. Refuse the copy so
55
+ // the two sources cannot silently overwrite each other.
56
+ assertNotTrackedIconFile(destRelativePath, relativePath) {
57
+ if (this.artifacts.iconFiles().has(destRelativePath)) {
58
+ throw new Error(`Conflicting icon sources: ${path.join(this.rootDir, destRelativePath)} ` +
59
+ `and ${path.join(this.rootDir, "public", relativePath)} both ` +
60
+ `publish public/${destRelativePath}. Remove one of them.`);
61
+ }
62
+ }
54
63
  async copyPublicFiles() {
55
64
  const publicDir = path.join(this.rootDir, "public");
56
65
  const previousFiles = this.artifacts.publicFiles();
@@ -69,6 +78,7 @@ export class PublicAssetManager {
69
78
  const nextByFoldedPath = new Map();
70
79
  for (const relativePath of files) {
71
80
  const destRelativePath = publicDestinationRelativePath(relativePath);
81
+ this.assertNotTrackedIconFile(destRelativePath, relativePath);
72
82
  nextFiles.add(destRelativePath);
73
83
  nextByFoldedPath.set(destRelativePath.toLowerCase(), destRelativePath);
74
84
  }
@@ -101,6 +111,7 @@ export class PublicAssetManager {
101
111
  const destRelativePath = publicDestinationRelativePath(relativePath);
102
112
  const destPath = this.publicOutputFilePath(destRelativePath);
103
113
  try {
114
+ this.assertNotTrackedIconFile(destRelativePath, relativePath);
104
115
  await this.copyRegularPublicFile(filePath, destPath);
105
116
  const publicFiles = this.artifacts.publicFiles();
106
117
  publicFiles.add(destRelativePath);
@@ -15,6 +15,7 @@ interface WatchCoordinatorCallbacks {
15
15
  copyPublicFiles(): Promise<void>;
16
16
  handlePublicFileChange(filePath: string): Promise<void>;
17
17
  handlePublicFileDelete(filePath: string): Promise<void>;
18
+ syncIconFiles(): Promise<void>;
18
19
  processAllMDXFiles(): Promise<void>;
19
20
  }
20
21
  interface WatchCoordinatorOptions {
@@ -24,6 +25,7 @@ interface WatchCoordinatorOptions {
24
25
  fontConfigFile: string;
25
26
  analyticsConfigFile: string;
26
27
  doccupineConfigFile: string;
28
+ iconFiles: readonly string[];
27
29
  sourceFs: SecureSourceFs;
28
30
  getOpenApiSpecs(): readonly NormalizedOpenApiSpec[];
29
31
  getOpenApiSourceFiles(): readonly string[];
@@ -92,11 +92,15 @@ export class WatchCoordinator {
92
92
  }
93
93
  }
94
94
  async captureSourceSnapshot() {
95
- const { analyticsConfigFile, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, getOpenApiSourceFiles, rootDir, sourceFs, watchDir, } = this.options;
95
+ const { analyticsConfigFile, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, getOpenApiSourceFiles, iconFiles, rootDir, sourceFs, watchDir, } = this.options;
96
96
  const configs = Object.fromEntries(await Promise.all(configFiles.map(async (fileName) => [
97
97
  fileName,
98
98
  await sourceFs.pathState(path.join(rootDir, fileName), true),
99
99
  ])));
100
+ const icons = Object.fromEntries(await Promise.all(iconFiles.map(async (fileName) => [
101
+ fileName,
102
+ await sourceFs.pathState(path.join(rootDir, fileName), true),
103
+ ])));
100
104
  const openApiSourceFiles = getOpenApiSourceFiles();
101
105
  const openapi = (await Promise.all((openApiSourceFiles.length > 0
102
106
  ? openApiSourceFiles
@@ -111,6 +115,7 @@ export class WatchCoordinator {
111
115
  doccupine: await sourceFs.pathState(path.join(rootDir, doccupineConfigFile), true),
112
116
  public: await sourceFs.treeState(path.join(rootDir, "public"), () => true),
113
117
  openapi,
118
+ icons,
114
119
  };
115
120
  }
116
121
  async establishSourceSnapshot(projectSourceStates = {}, openApiSourceState, doccupineSourceState) {
@@ -120,6 +125,11 @@ export class WatchCoordinator {
120
125
  snapshot.configs[fileName] = projectSourceStates[fileName];
121
126
  }
122
127
  }
128
+ for (const fileName of this.options.iconFiles) {
129
+ if (projectSourceStates[fileName] !== undefined) {
130
+ snapshot.icons[fileName] = projectSourceStates[fileName];
131
+ }
132
+ }
123
133
  snapshot.font =
124
134
  projectSourceStates[this.options.fontConfigFile] ?? snapshot.font;
125
135
  snapshot.analytics =
@@ -130,7 +140,7 @@ export class WatchCoordinator {
130
140
  this.sourceSnapshot = snapshot;
131
141
  }
132
142
  async reconcileWatchedSources(previous, current) {
133
- const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, rootDir, } = this.options;
143
+ const { analyticsConfigFile, callbacks, configFiles, doccupineConfigFile, fontConfigFile, getOpenApiSpecs, iconFiles, rootDir, } = this.options;
134
144
  const doccupineConfigPath = path.join(rootDir, doccupineConfigFile);
135
145
  const doccupineChanged = previous === null || previous.doccupine !== current.doccupine;
136
146
  if (doccupineChanged && (await fs.pathExists(doccupineConfigPath))) {
@@ -181,6 +191,10 @@ export class WatchCoordinator {
181
191
  }
182
192
  await callbacks.copyPublicFiles();
183
193
  }
194
+ if (previous === null ||
195
+ iconFiles.some((fileName) => previous.icons[fileName] !== current.icons[fileName])) {
196
+ await callbacks.syncIconFiles();
197
+ }
184
198
  if (getOpenApiSpecs().length > 0 &&
185
199
  (previous === null || previous.openapi !== current.openapi)) {
186
200
  await callbacks.handleOpenApiChange();
@@ -366,6 +380,11 @@ export class WatchCoordinator {
366
380
  }
367
381
  });
368
382
  };
383
+ const isRootIconFile = (filePath) => this.options.iconFiles.includes(path.basename(filePath)) &&
384
+ path.dirname(filePath) === rootDir;
385
+ const queueIconSync = () => {
386
+ this.enqueueMutation("Error syncing icon files", () => callbacks.syncIconFiles());
387
+ };
369
388
  this.rootDirWatcher
370
389
  .on("addDir", (dirPath) => {
371
390
  if (path.basename(dirPath) === "public" &&
@@ -376,6 +395,16 @@ export class WatchCoordinator {
376
395
  .on("add", (filePath) => {
377
396
  if (isPathInside(publicDir, filePath))
378
397
  queuePublicWatcherStart();
398
+ if (isRootIconFile(filePath))
399
+ queueIconSync();
400
+ })
401
+ .on("change", (filePath) => {
402
+ if (isRootIconFile(filePath))
403
+ queueIconSync();
404
+ })
405
+ .on("unlink", (filePath) => {
406
+ if (isRootIconFile(filePath))
407
+ queueIconSync();
379
408
  })
380
409
  .on("unlinkDir", (dirPath) => {
381
410
  if (path.basename(dirPath) !== "public" ||
@@ -9,6 +9,7 @@ export declare class GeneratedArtifacts {
9
9
  private routes;
10
10
  private llmsFiles;
11
11
  private publicFilePaths;
12
+ private iconFilePaths;
12
13
  constructor(outputDir: string);
13
14
  private manifestPath;
14
15
  private routeKey;
@@ -30,6 +31,8 @@ export declare class GeneratedArtifacts {
30
31
  replaceLlmsPageFiles(files: Iterable<string>): void;
31
32
  publicFiles(): Set<string>;
32
33
  replacePublicFiles(files: Iterable<string>): void;
34
+ iconFiles(): Set<string>;
35
+ replaceIconFiles(files: Iterable<string>): void;
33
36
  private writeManifest;
34
37
  save(): Promise<void>;
35
38
  }
@@ -47,6 +47,7 @@ export class GeneratedArtifacts {
47
47
  routes = new Map();
48
48
  llmsFiles = new Set();
49
49
  publicFilePaths = new Set();
50
+ iconFilePaths = new Set();
50
51
  constructor(outputDir) {
51
52
  this.outputDir = outputDir;
52
53
  }
@@ -60,6 +61,7 @@ export class GeneratedArtifacts {
60
61
  this.routes.clear();
61
62
  this.llmsFiles.clear();
62
63
  this.publicFilePaths.clear();
64
+ this.iconFilePaths.clear();
63
65
  const manifestContent = await readOutputFileIfPresent(this.outputDir, MANIFEST_FILE);
64
66
  if (manifestContent !== null) {
65
67
  try {
@@ -85,6 +87,13 @@ export class GeneratedArtifacts {
85
87
  this.publicFilePaths.add(file);
86
88
  }
87
89
  }
90
+ if (Array.isArray(parsed.iconFiles)) {
91
+ for (const value of parsed.iconFiles) {
92
+ const file = normalizePublicFile(value);
93
+ if (file)
94
+ this.iconFilePaths.add(file);
95
+ }
96
+ }
88
97
  }
89
98
  catch {
90
99
  // A corrupt manifest owns nothing. Generated output is rebuilt safely.
@@ -177,12 +186,26 @@ export class GeneratedArtifacts {
177
186
  }
178
187
  this.publicFilePaths = next;
179
188
  }
189
+ iconFiles() {
190
+ return new Set(this.iconFilePaths);
191
+ }
192
+ replaceIconFiles(files) {
193
+ const next = new Set();
194
+ for (const value of files) {
195
+ const file = normalizePublicFile(value);
196
+ if (!file)
197
+ throw new Error("Refusing to record an unsafe icon path");
198
+ next.add(file);
199
+ }
200
+ this.iconFilePaths = next;
201
+ }
180
202
  async writeManifest(routes) {
181
203
  const manifest = {
182
204
  schemaVersion: 2,
183
205
  routes: [...routes.values()].sort((a, b) => `${a.kind}:${a.source}`.localeCompare(`${b.kind}:${b.source}`)),
184
206
  llmsPageFiles: [...this.llmsFiles].sort(),
185
207
  publicFiles: [...this.publicFilePaths].sort(),
208
+ iconFiles: [...this.iconFilePaths].sort(),
186
209
  };
187
210
  await writeFileAtomic(this.manifestPath(MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
188
211
  }
@@ -1,4 +1,4 @@
1
- import { DEFAULT_DESCRIPTION, DEFAULT_FAVICON, DEFAULT_OG_IMAGE, DEFAULT_SITE_NAME, } from "./constants.js";
1
+ import { DEFAULT_DESCRIPTION, DEFAULT_OG_IMAGE, DEFAULT_SITE_NAME, } from "./constants.js";
2
2
  function formatObjectArray(items) {
3
3
  const MAX_WIDTH = 80;
4
4
  const formatted = items.map((item) => {
@@ -89,7 +89,16 @@ function fontDeclLine(fontConfig) {
89
89
  // The mode comes from the "theme" cookie, falling back to the OS preference
90
90
  // and seeding the cookie so Cherry's ClientThemeProvider reconciles against
91
91
  // the same answer on mount instead of flipping the class back.
92
- const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(function(s){return s.trim();}).find(function(s){return s.indexOf("theme=")===0;});var v=c?c.split("=")[1]:null;var d=v?v==="dark":(window.matchMedia&&window.matchMedia("(prefers-color-scheme:dark)").matches);if(!v){document.cookie="theme="+(d?"dark":"light")+";path=/;max-age=31536000;SameSite=Lax";}var r=document.documentElement;r.dataset.theme=d?"dark":"light";if(d){r.classList.add("dark");}}catch(e){}})();`;
92
+ //
93
+ // The script also writes the theme-color meta from the resolved mode. It
94
+ // cannot be emitted as OS-scheme-scoped SSR metas (Next's viewport export):
95
+ // the site's mode is cookie-based, so a dark site on a light-OS device would
96
+ // show the wrong browser chrome until hydration - a visible flash on every
97
+ // load. The \${...} palette interpolations below are escaped so they resolve
98
+ // in the generated layout, at app build time, from the imported theme
99
+ // palettes. The token must match the provider's $themeColor (primary), so
100
+ // the pre-paint chrome color equals what Cherry syncs after hydration.
101
+ const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(function(s){return s.trim();}).find(function(s){return s.indexOf("theme=")===0;});var v=c?c.split("=")[1]:null;var d=v?v==="dark":(window.matchMedia&&window.matchMedia("(prefers-color-scheme:dark)").matches);if(!v){document.cookie="theme="+(d?"dark":"light")+";path=/;max-age=31536000;SameSite=Lax";}var r=document.documentElement;r.dataset.theme=d?"dark":"light";if(d){r.classList.add("dark");}var m=document.querySelector('meta[name="theme-color"]');if(!m){m=document.createElement("meta");m.name="theme-color";document.head.appendChild(m);}m.content=d?"\${colorsDark.primary}":"\${colorsLight.primary}";}catch(e){}})();`;
93
102
  /**
94
103
  * Root layout ("app/layout.tsx"). Minimal shell: html/body, fonts, the theme
95
104
  * provider stack, and (optionally) PostHog. It renders `children` directly so
@@ -103,9 +112,10 @@ export const rootLayoutTemplate = (fontConfig, analyticsEnabled = false) => {
103
112
  return `import type { Metadata } from "next";
104
113
  ${fontImportLine(fontConfig)}
105
114
  import { StyledComponentsRegistry } from "cherry-styled-components";
106
- import { theme, themeDark } from "@/app/theme";
115
+ import { colorsDark, colorsLight, theme, themeDark } from "@/app/theme";
107
116
  import { CherryThemeProvider } from "@/components/layout/CherryThemeProvider";
108
117
  import { config } from "@/utils/config";
118
+ import { siteIcons } from "@/utils/icons";
109
119
  ${analyticsEnabled ? `import { PostHogProvider } from "@/components/PostHogProvider";\n` : ""}
110
120
  ${fontDeclLine(fontConfig)}
111
121
 
@@ -125,7 +135,7 @@ export const metadata: Metadata = {
125
135
  description:
126
136
  config.description ||
127
137
  "${DEFAULT_DESCRIPTION}",
128
- icons: config.icon || "${DEFAULT_FAVICON}",
138
+ icons: siteIcons,
129
139
  openGraph: {
130
140
  title: config.name || "${DEFAULT_SITE_NAME}",
131
141
  description:
@@ -1,4 +1,4 @@
1
- import { DEFAULT_FAVICON, DEFAULT_META_DESCRIPTION, DEFAULT_OG_IMAGE, DEFAULT_SITE_NAME, } from "./constants.js";
1
+ import { DEFAULT_META_DESCRIPTION, DEFAULT_OG_IMAGE, DEFAULT_SITE_NAME, } from "./constants.js";
2
2
  /**
3
3
  * Returns a code snippet that:
4
4
  * - declares a `jsonLd` object at runtime using the site's config,
@@ -18,13 +18,11 @@ export function generateJsonLdScript(opts) {
18
18
  : opts.date
19
19
  ? JSON.stringify(opts.date)
20
20
  : "undefined";
21
- const defaultFaviconLiteral = JSON.stringify(DEFAULT_FAVICON);
22
- // When the page declares an image, it always wins - emitting a `||` chain
23
- // after a string literal makes TypeScript fail the build with
24
- // "This kind of expression is always truthy".
21
+ // When the page declares an image, it always wins; otherwise the site-wide
22
+ // primary icon (root icon files > config.icon > default) supplies the logo.
25
23
  const faviconLine = opts.image
26
24
  ? `const faviconUrl = ${JSON.stringify(opts.image)};`
27
- : `const faviconUrl = config.icon || ${defaultFaviconLiteral};`;
25
+ : `const faviconUrl = primaryIconUrl;`;
28
26
  // Indent 10 + "description: ".length(13) + ",".length(1) = 24. Prettier
29
27
  // wraps the value to the next line (indent 12) once total exceeds 80.
30
28
  const descriptionLine = descLiteral.length > 56
@@ -139,7 +137,9 @@ function buildAlternatesBlock(canonicalPath, rssPath) {
139
137
  export function generateMetadataBlock(opts) {
140
138
  const title = buildTitleExpression(opts);
141
139
  const desc = buildFieldExpression(opts.description, "description", DEFAULT_META_DESCRIPTION);
142
- const icon = buildFieldExpression(opts.icon, "icon", DEFAULT_FAVICON);
140
+ // Frontmatter icon wins as a literal; otherwise the site-wide icon set
141
+ // built by utils/icons.ts (root icon files > config.icon > default) applies.
142
+ const icon = opts.icon ? JSON.stringify(String(opts.icon)) : "siteIcons";
143
143
  const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
144
144
  const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
145
145
  const inlineTitleDeclaration = `const pageTitle = ${title};`;
@@ -166,7 +166,7 @@ ${imageLine}
166
166
  export function generateRuntimeOnlyMetadataBlock() {
167
167
  const title = `config.name || ${JSON.stringify(DEFAULT_SITE_NAME)}`;
168
168
  const desc = `config.description || ${JSON.stringify(DEFAULT_META_DESCRIPTION)}`;
169
- const icon = `config.icon || ${JSON.stringify(DEFAULT_FAVICON)}`;
169
+ const icon = "siteIcons";
170
170
  const image = `config.image || ${JSON.stringify(DEFAULT_OG_IMAGE)}`;
171
171
  const descriptionLine = formatProperty(2, "description", desc);
172
172
  const iconLine = formatProperty(2, "icons", icon);
@@ -24,6 +24,7 @@ const GENERATED_TOP_LEVEL_FILES = new Set([
24
24
  "config.json",
25
25
  "eslint.config.mjs",
26
26
  "fonts.json",
27
+ "icons.json",
27
28
  "links.json",
28
29
  "navigation.json",
29
30
  "next.config.ts",
@@ -14,7 +14,6 @@ import { searchRoutesTemplate } from "../templates/app/api/search/route.js";
14
14
  import { notFoundTemplate } from "../templates/app/not-found.js";
15
15
  import { themeTemplate } from "../templates/app/theme.js";
16
16
  import { chatTemplate } from "../templates/components/Chat.js";
17
- import { chatStylesTemplate } from "../templates/components/ChatStyles.js";
18
17
  import { lockBodyScrollTemplate } from "../templates/components/LockBodyScroll.js";
19
18
  import { docsTemplate } from "../templates/components/Docs.js";
20
19
  import { docsSideBarTemplate } from "../templates/components/DocsSideBar.js";
@@ -91,6 +90,7 @@ import { orderNavItemsTemplate } from "../templates/utils/orderNavItems.js";
91
90
  import { rateLimitTemplate } from "../templates/utils/rateLimit.js";
92
91
  import { brandingTemplate } from "../templates/utils/branding.js";
93
92
  import { configTemplate } from "../templates/utils/config.js";
93
+ import { iconsTemplate } from "../templates/utils/icons.js";
94
94
  import { playgroundAllowlistTemplate } from "../templates/utils/playgroundAllowlist.js";
95
95
  import { ssrfGuardTemplate } from "../templates/utils/ssrfGuard.js";
96
96
  import { apiSnippetsTemplate } from "../templates/utils/apiSnippets.js";
@@ -206,13 +206,13 @@ export const appStructure = {
206
206
  "utils/rateLimit.ts": rateLimitTemplate,
207
207
  "utils/rehypeCodeMeta.ts": rehypeCodeMetaTemplate,
208
208
  "utils/config.ts": configTemplate,
209
+ "utils/icons.ts": iconsTemplate,
209
210
  "utils/playgroundAllowlist.ts": playgroundAllowlistTemplate,
210
211
  "utils/ssrfGuard.ts": ssrfGuardTemplate,
211
212
  "utils/apiSnippets.ts": apiSnippetsTemplate,
212
213
  "utils/apiPlayground.ts": apiPlaygroundUtilsTemplate,
213
214
  "utils/requestBody.ts": requestBodyTemplate,
214
215
  "components/Chat.tsx": chatTemplate,
215
- "components/ChatStyles.ts": chatStylesTemplate,
216
216
  "components/LockBodyScroll.ts": lockBodyScrollTemplate,
217
217
  "components/Docs.tsx": docsTemplate,
218
218
  "components/DocsSideBar.tsx": docsSideBarTemplate,
@@ -28,6 +28,7 @@ export declare class MDXToNextJSGenerator {
28
28
  private sectionIndexGenerator;
29
29
  private projectConfigRepository;
30
30
  private publicAssetManager;
31
+ private iconAssetManager;
31
32
  private watchCoordinator;
32
33
  constructor(watchDir: string, outputDir: string, openApiSpecs?: NormalizedOpenApiSpec[], rootDir?: string);
33
34
  private outputPath;
@@ -63,6 +64,7 @@ export declare class MDXToNextJSGenerator {
63
64
  handleAnalyticsConfigChange(): Promise<void>;
64
65
  handleAnalyticsConfigDelete(): Promise<void>;
65
66
  copyPublicFiles(): Promise<void>;
67
+ syncIconFiles(): Promise<void>;
66
68
  handlePublicFileChange(filePath: string): Promise<void>;
67
69
  handlePublicFileDelete(filePath: string): Promise<void>;
68
70
  startWatching(): Promise<void>;
@@ -18,6 +18,7 @@ import { GeneratedRouteManager } from "./generator/generated-route-manager.js";
18
18
  import { MdxReconciliationCoordinator } from "./generator/mdx-reconciliation-coordinator.js";
19
19
  import { ProjectConfigRepository } from "./generator/project-config-repository.js";
20
20
  import { PublicAssetManager } from "./generator/public-asset-manager.js";
21
+ import { ICON_SOURCE_FILES, IconAssetManager, } from "./generator/icon-asset-manager.js";
21
22
  import { WatchCoordinator } from "./generator/watch-coordinator.js";
22
23
  import { SectionIndexGenerator } from "./generator/section-index-generator.js";
23
24
  import { OpenApiRefreshCoordinator, } from "./generator/openapi-refresh-coordinator.js";
@@ -56,6 +57,7 @@ export class MDXToNextJSGenerator {
56
57
  sectionIndexGenerator;
57
58
  projectConfigRepository;
58
59
  publicAssetManager;
60
+ iconAssetManager;
59
61
  watchCoordinator;
60
62
  constructor(watchDir, outputDir, openApiSpecs = [], rootDir = process.cwd()) {
61
63
  this.watchDir = path.resolve(watchDir);
@@ -97,8 +99,9 @@ export class MDXToNextJSGenerator {
97
99
  maybeUpdateSections: () => this.maybeUpdateSections(),
98
100
  removeOwnedRoute: (slug) => this.removeOwnedRoute(slug),
99
101
  });
100
- this.projectConfigRepository = new ProjectConfigRepository(this.rootDir, this.outputDir, this.sourceFs, this.configFiles, this.fontConfigFile, this.analyticsConfigFile);
102
+ this.projectConfigRepository = new ProjectConfigRepository(this.rootDir, this.outputDir, this.sourceFs, this.configFiles, this.fontConfigFile, this.analyticsConfigFile, ICON_SOURCE_FILES);
101
103
  this.publicAssetManager = new PublicAssetManager(this.rootDir, this.outputDir, this.artifacts, this.sourceFs);
104
+ this.iconAssetManager = new IconAssetManager(this.rootDir, this.outputDir, this.artifacts, this.sourceFs, (fileName) => this.projectConfigRepository.readOptionalRootBinaryFile(fileName, "icon source"));
102
105
  this.watchCoordinator = new WatchCoordinator({
103
106
  watchDir: this.watchDir,
104
107
  rootDir: this.rootDir,
@@ -106,6 +109,7 @@ export class MDXToNextJSGenerator {
106
109
  fontConfigFile: this.fontConfigFile,
107
110
  analyticsConfigFile: this.analyticsConfigFile,
108
111
  doccupineConfigFile: this.doccupineConfigFile,
112
+ iconFiles: ICON_SOURCE_FILES,
109
113
  sourceFs: this.sourceFs,
110
114
  getOpenApiSpecs: () => this.openApiSpecs,
111
115
  getOpenApiSourceFiles: () => this.apiRegistry.sourceFiles,
@@ -124,6 +128,7 @@ export class MDXToNextJSGenerator {
124
128
  copyPublicFiles: () => this.copyPublicFiles(),
125
129
  handlePublicFileChange: (filePath) => this.handlePublicFileChange(filePath),
126
130
  handlePublicFileDelete: (filePath) => this.handlePublicFileDelete(filePath),
131
+ syncIconFiles: () => this.syncIconFiles(),
127
132
  processAllMDXFiles: () => this.reconcileMdxSources(),
128
133
  },
129
134
  });
@@ -201,6 +206,7 @@ export class MDXToNextJSGenerator {
201
206
  await this.copyFontConfig();
202
207
  await this.copyAnalyticsConfig();
203
208
  await this.copyPublicFiles();
209
+ await this.syncIconFiles();
204
210
  if (this.sectionsConfig) {
205
211
  console.log(chalk.blue(`📑 Found ${this.sectionsConfig.length} section(s): ${this.sectionsConfig.map((s) => s.label).join(", ")}`));
206
212
  }
@@ -408,6 +414,9 @@ export class MDXToNextJSGenerator {
408
414
  async copyPublicFiles() {
409
415
  return this.publicAssetManager.copyPublicFiles();
410
416
  }
417
+ async syncIconFiles() {
418
+ return this.iconAssetManager.syncIconFiles();
419
+ }
411
420
  async handlePublicFileChange(filePath) {
412
421
  return this.publicAssetManager.handlePublicFileChange(filePath, () => this.updateLlmsFiles());
413
422
  }