@knowcode/doc-builder 1.10.5 → 1.10.6
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/lib/core-builder.js +37 -16
- package/package.json +1 -1
package/lib/core-builder.js
CHANGED
|
@@ -349,21 +349,16 @@ function processMarkdownContent(content, config = {}) {
|
|
|
349
349
|
|
|
350
350
|
// Parse the markdown
|
|
351
351
|
let html = marked.parse(processedContent);
|
|
352
|
-
|
|
352
|
+
|
|
353
353
|
// Replace placeholders with actual mermaid blocks
|
|
354
354
|
mermaidBlocks.forEach((block, index) => {
|
|
355
355
|
html = html.replace(`<p>MERMAID_BLOCK_${index}</p>`, block);
|
|
356
356
|
html = html.replace(`MERMAID_BLOCK_${index}`, block);
|
|
357
357
|
});
|
|
358
|
-
|
|
359
|
-
// Convert internal .md links to .html links
|
|
360
|
-
// Matches href="...md" or href='...md' and converts to .html
|
|
361
|
-
// Handles: file.md, path/file.md, file.md#anchor, file.md?query
|
|
362
|
-
html = html.replace(/href=(["'])([^"']*?)\.md((?:#[^"']*)?(?:\?[^"']*)?)\1/gi, 'href=$1$2.html$3$1');
|
|
363
|
-
|
|
358
|
+
|
|
364
359
|
// Replace emojis with Phosphor icons if enabled
|
|
365
360
|
html = replaceEmojisWithIcons(html, config);
|
|
366
|
-
|
|
361
|
+
|
|
367
362
|
return html;
|
|
368
363
|
}
|
|
369
364
|
|
|
@@ -418,7 +413,12 @@ function generateHTML(title, content, navigation, currentPath = '', config = {},
|
|
|
418
413
|
// Get doc-builder version from package.json
|
|
419
414
|
const packageJson = require('../package.json');
|
|
420
415
|
const docBuilderVersion = packageJson.version;
|
|
421
|
-
|
|
416
|
+
|
|
417
|
+
// Extract source metadata if available
|
|
418
|
+
const sourceMetadata = config._sourceMetadata || {};
|
|
419
|
+
const sourcePath = sourceMetadata.sourcePath || '';
|
|
420
|
+
const generatedAt = sourceMetadata.generatedAt || new Date().toISOString();
|
|
421
|
+
|
|
422
422
|
// SEO preparation
|
|
423
423
|
let seoTags = '';
|
|
424
424
|
let jsonLd = '';
|
|
@@ -503,7 +503,11 @@ function generateHTML(title, content, navigation, currentPath = '', config = {},
|
|
|
503
503
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
504
504
|
<meta name="description" content="${escapeHtml(pageDescription || generateDescription(originalContent || content) || siteDescription)}">
|
|
505
505
|
<title>${escapeHtml(finalSeoTitle || `${title} - ${siteName}`)}</title>
|
|
506
|
-
|
|
506
|
+
|
|
507
|
+
<!-- Source metadata -->
|
|
508
|
+
${sourcePath ? `<meta name="md-source" content="${escapeHtml(sourcePath)}">` : ''}
|
|
509
|
+
<meta name="doc-generated" content="${escapeHtml(generatedAt)}">
|
|
510
|
+
|
|
507
511
|
${seoTags}
|
|
508
512
|
|
|
509
513
|
<!-- Fonts -->
|
|
@@ -838,6 +842,13 @@ ${seoTags}
|
|
|
838
842
|
mermaidEnhanced: ${config.features?.mermaidEnhanced !== false}
|
|
839
843
|
}
|
|
840
844
|
};
|
|
845
|
+
|
|
846
|
+
// Source metadata for JS consumers
|
|
847
|
+
window.__DOC_SOURCE__ = {
|
|
848
|
+
mdSource: ${sourcePath ? `"${escapeHtml(sourcePath)}"` : 'null'},
|
|
849
|
+
generatedAt: "${escapeHtml(generatedAt)}",
|
|
850
|
+
docBuilderVersion: "${docBuilderVersion}"
|
|
851
|
+
};
|
|
841
852
|
</script>
|
|
842
853
|
<script src="${resourcePath}js/main.js"></script>
|
|
843
854
|
${(config.features?.authentication === 'supabase' || config.features?.privateDirectoryAuth === true) ? `<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
|
|
@@ -1145,16 +1156,26 @@ async function processMarkdownFile(filePath, outputPath, allFiles, config, useSt
|
|
|
1145
1156
|
|
|
1146
1157
|
// Process content
|
|
1147
1158
|
const htmlContent = processMarkdownContent(content, config);
|
|
1148
|
-
|
|
1159
|
+
|
|
1160
|
+
// Create config with source metadata for HTML generation
|
|
1161
|
+
const generationTimestamp = new Date().toISOString();
|
|
1162
|
+
const htmlConfig = {
|
|
1163
|
+
...config,
|
|
1164
|
+
_sourceMetadata: {
|
|
1165
|
+
sourcePath: relativePath, // e.g., "docs/technical/local-dev-troubleshooting.md"
|
|
1166
|
+
generatedAt: generationTimestamp
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1149
1170
|
// Build navigation - pass config to handle private file filtering
|
|
1150
1171
|
// For static HTML, we need to build navigation with relative paths
|
|
1151
|
-
const navConfig = useStaticHTML ? { ...
|
|
1172
|
+
const navConfig = useStaticHTML ? { ...htmlConfig, isStaticOutput: true } : htmlConfig;
|
|
1152
1173
|
const navigation = buildNavigationStructure(allFiles, urlPath, navConfig);
|
|
1153
|
-
|
|
1174
|
+
|
|
1154
1175
|
// Generate full HTML (pass original content and front matter for SEO)
|
|
1155
|
-
const html = useStaticHTML
|
|
1156
|
-
? generateStaticHTML(title, htmlContent, navigation, urlPath,
|
|
1157
|
-
: generateHTML(title, htmlContent, navigation, urlPath,
|
|
1176
|
+
const html = useStaticHTML
|
|
1177
|
+
? generateStaticHTML(title, htmlContent, navigation, urlPath, htmlConfig, content, frontMatter)
|
|
1178
|
+
: generateHTML(title, htmlContent, navigation, urlPath, htmlConfig, content, frontMatter);
|
|
1158
1179
|
|
|
1159
1180
|
// Write file
|
|
1160
1181
|
await fs.ensureDir(path.dirname(outputPath));
|