From c02891dd6a7bb4f91d45a13bb293643c6ce3fdfa Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 29 Jan 2026 10:48:38 -0500 Subject: [PATCH] chore: adapted inject.ts pattern --- packages/cli/src/commands/inject.ts | 31 +++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/inject.ts b/packages/cli/src/commands/inject.ts index 85ba38a..937ce16 100644 --- a/packages/cli/src/commands/inject.ts +++ b/packages/cli/src/commands/inject.ts @@ -43,18 +43,45 @@ export const injectCommand = command({ // Load state to get atUri mappings const state = await loadState(configDir); + // Generic filenames where the slug is the parent directory, not the filename + // Covers: SvelteKit (+page), Astro/Hugo (index), Next.js (page), etc. + const genericFilenames = new Set([ + "+page", + "index", + "_index", + "page", + "readme", + ]); + // Build a map of slug/path to atUri from state const pathToAtUri = new Map(); for (const [filePath, postState] of Object.entries(state.posts)) { if (postState.atUri) { // Extract slug from file path (e.g., ./content/blog/my-post.md -> my-post) - const basename = path.basename(filePath, path.extname(filePath)); + let basename = path.basename(filePath, path.extname(filePath)); + + // If the filename is a generic convention name, use the parent directory as slug + if (genericFilenames.has(basename.toLowerCase())) { + // Split path and filter out route groups like (blog-article) + const pathParts = filePath + .split(/[/\\]/) + .filter((p) => p && !(p.startsWith("(") && p.endsWith(")"))); + // The slug should be the second-to-last part (last is the filename) + if (pathParts.length >= 2) { + const slug = pathParts[pathParts.length - 2]; + if (slug && slug !== "." && slug !== "content" && slug !== "routes" && slug !== "src") { + basename = slug; + } + } + } + pathToAtUri.set(basename, postState.atUri); // Also add variations that might match HTML file paths // e.g., /blog/my-post, /posts/my-post, my-post/index const dirName = path.basename(path.dirname(filePath)); - if (dirName !== "." && dirName !== "content") { + // Skip route groups and common directory names + if (dirName !== "." && dirName !== "content" && !(dirName.startsWith("(") && dirName.endsWith(")"))) { pathToAtUri.set(`${dirName}/${basename}`, postState.atUri); } } -- 2.54.0