From 35e95aff8c30b4517bab1b7c60373e127d8858dc Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:28:45 +0000 Subject: [PATCH 1/2] fix(cli): prevent deletion of user''s docs folder during build The CLI build process was incorrectly deleting the user''s docs folder at the start and end of the build, causing loss of MDX files and content. Changes: - Use temporary directory (.dory-build-temp) when user has existing docs folder - Preserve user''s docs folder throughout the build process - Only clean up the temporary build directory, not user content Fixes #54 Co-authored-by: H --- bin/dory.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/dory.js b/bin/dory.js index 8d193ef..6d18af4 100755 --- a/bin/dory.js +++ b/bin/dory.js @@ -14,15 +14,21 @@ const commands = { build: () => { console.log('๐ŸŸ Dory is ready to build your docs!'); - // Clear the docs folder if it exists - const docsDir = resolve(__dirname, '..', 'docs'); + const currentDir = process.cwd(); + const userDocsDir = resolve(currentDir, 'docs'); + const hasUserDocs = existsSync(userDocsDir); + + // Use different temp directory if user has their own docs folder + const tempDirName = hasUserDocs ? '.dory-build-temp' : 'docs'; + const docsDir = resolve(__dirname, '..', tempDirName); + + // Clear the temp build folder if it exists if (existsSync(docsDir)) { console.log('๐Ÿงน Tidying up the workspace...'); rmSync(docsDir, { recursive: true, force: true }); } // Check if dory.json exists in current directory - const currentDir = process.cwd(); const doryConfigPath = resolve(currentDir, 'dory.json'); if (!existsSync(doryConfigPath)) { @@ -53,8 +59,9 @@ const commands = { } }; - // Copy all files and directories except node_modules, dist, and .git - const excludeDirs = ['node_modules', 'dist', '.git', 'docs', 'pnpm-lock.yaml']; + // Copy all files and directories except node_modules, dist, .git, and temp build dir + // Don't exclude 'docs' if user has their own docs folder - we need to copy it + const excludeDirs = ['node_modules', 'dist', '.git', 'pnpm-lock.yaml', tempDirName]; const items = readdirSync(currentDir); for (const item of items) { @@ -88,7 +95,7 @@ const commands = { } rmSync(distDir, { recursive: true, force: true }); - // Revert docs folder back to original state + // Clean up temp build folder (but preserve user's docs folder if it exists) console.log('๐Ÿงน Cleaning up...'); rmSync(docsDir, { recursive: true, force: true }); console.log('โœ… All done!'); From 4443e5d3a28543bd9e757a891a0146903abcb4ba Mon Sep 17 00:00:00 2001 From: Hemang Kandwal Date: Fri, 25 Jul 2025 02:08:40 +0530 Subject: [PATCH 2/2] feat(dory): fix up santizie --- package.json | 2 +- src/plugins/sanitize.ts | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b28ed17..a003f98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@clidey/dory", "private": false, - "version": "0.16.0", + "version": "0.17.0", "type": "module", "description": "A CLI tool for building and previewing documentation sites", "keywords": [ diff --git a/src/plugins/sanitize.ts b/src/plugins/sanitize.ts index 09fed56..d54a79f 100644 --- a/src/plugins/sanitize.ts +++ b/src/plugins/sanitize.ts @@ -100,21 +100,46 @@ export function preprocessMdxTags() { // Otherwise, leave as-is for proper JSX parsing return match; } - + // For unknown components, always treat as text (wrap in backticks) // If already inside backticks, do not wrap again - // Find the start of the line up to the match const before = processed.slice(0, offset); - // Count the number of backticks before this tag const backtickMatches = before.match(/`+/g); - // If the number of backticks is odd, we're inside a backtick span const insideBackticks = backtickMatches ? backtickMatches.reduce((acc, s) => acc + s.length, 0) % 2 === 1 : false; if (insideBackticks) { return match; } - // Otherwise, wrap in backticks to prevent JSX parsing return `\`<${tag}>\``; }); + // This regex finds all and occurrences + processed = processed.replace(/<\/?([a-z][a-z0-9]*)>/gi, (match, tag, offset) => { + // If inside a code block, do not touch + if (isInsideCodeBlock(processed, offset)) { + return match; + } + + // If known component, check if it has a closing tag (only for opening tags) + if (KNOWN_COMPONENTS.includes(tag)) { + // Only check for matching closing tag for opening tags + if (!match.startsWith(' acc + s.length, 0) % 2 === 1 : false; + if (insideBackticks) { + return match; + } + return `\`${match}\``; + }); + return { code: processed, map: null,