Files
wehub-resource-sync 8a21a212f8
CI / Build Rust Project on Windows (push) Waiting to run
Live Provider Tests / Smoke Tests (push) Blocked by required conditions
Live Provider Tests / Smoke Tests (Code Execution) (push) Blocked by required conditions
Live Provider Tests / Compaction Tests (push) Blocked by required conditions
Deploy Documentation / deploy (push) Has been cancelled
Canary / build-cli (push) Has been skipped
Canary / Upload Install Script (push) Has been skipped
Canary / bundle-desktop (push) Has been skipped
Canary / bundle-desktop-intel (push) Has been skipped
Canary / bundle-desktop-linux (push) Has been skipped
Canary / bundle-desktop-windows (push) Has been skipped
Canary / bundle-desktop-windows-cuda (push) Has been skipped
Canary / Release (push) Has been skipped
Cargo Deny / deny (push) Has been skipped
Unused Dependencies / machete (push) Has been skipped
Canary / Prepare Version (push) Failing after 1s
Live Provider Tests / check-fork (push) Failing after 0s
Create Minor Release PR / check-version-bump-pr (push) Has been skipped
Publish Ask AI Bot Docker Image / docker (push) Failing after 1s
Live Provider Tests / changes (push) Has been skipped
Live Provider Tests / Build Binary (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Has been skipped
Publish Docker Image / docker (push) Failing after 1s
CI / changes (push) Failing after 8s
CI / Check Rust Code Format (push) Waiting to run
CI / Build and Test Rust Project (push) Waiting to run
CI / Check MSRV (push) Waiting to run
CI / Lint Rust Code (push) Waiting to run
CI / Check Generated Schemas are Up-to-Date (push) Waiting to run
CI / Test and Lint Electron Desktop App (push) Waiting to run
Create Minor Release PR / release (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:04:08 +08:00

63 lines
1.8 KiB
JavaScript

const fs = require('fs');
const path = require('path');
module.exports = function markdownExportPlugin(context, options) {
const pluginOptions = {
enabled: true,
...options,
};
return {
name: 'markdown-export',
async postBuild({ outDir }) {
if (!pluginOptions.enabled) {
return;
}
console.log('[markdown-export] Starting markdown export...');
const { globby } = await import('globby');
const docsDir = path.join(context.siteDir, 'docs');
const outputDir = path.join(outDir, 'docs');
// Get all markdown files
const files = await globby('**/*.{md,mdx}', { cwd: docsDir });
for (const file of files) {
const inputPath = path.join(docsDir, file);
const outputPath = path.join(outputDir, file.replace('.mdx', '.md'));
// Ensure output subdirectory exists
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
const content = fs.readFileSync(inputPath, 'utf-8');
// Strip frontmatter and clean up
const cleaned = stripFrontmatter(content);
// Write the cleaned markdown alongside HTML files
fs.writeFileSync(outputPath, cleaned);
}
console.log(`[markdown-export] Successfully exported ${files.length} markdown files to ${outputDir}`);
},
};
};
function stripFrontmatter(content) {
// Remove YAML frontmatter (everything between --- at the start)
const withoutFrontmatter = content.replace(/^---\s*\n[\s\S]*?\n---\s*\n/, '');
// Clean up any remaining import statements (for .mdx files)
const withoutImports = withoutFrontmatter.replace(/^import .+$/gm, '');
// Remove excessive empty lines and trim
return withoutImports
.replace(/\n{3,}/g, '\n\n')
.trim();
}