Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/routes/$libraryId/$version.docs.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const Route = createFileRoute('/$libraryId/$version/docs/$')({
meta: seo({
title: `${loaderData?.title} | ${library.name} Docs`,
description: loaderData?.description,
keywords: loaderData?.keywords,
noindex: library.visible === false,
}),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const Route = createFileRoute(
? `${ctx.loaderData.title} | ${tail}`
: tail,
description: ctx.loaderData?.description,
keywords: ctx.loaderData?.keywords,
noindex: library.visible === false,
}),
}
Expand Down
24 changes: 23 additions & 1 deletion src/utils/docs.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export const fetchDocs = createServerFn({ method: 'GET' })
}

const frontMatter = extractFrontMatter(file)
const description = removeMarkdown(frontMatter.excerpt ?? '')
const description =
frontMatter.userDescription ?? removeMarkdown(frontMatter.excerpt ?? '')
const keywords = extractFrontMatterKeywords(frontMatter.data.keywords)
const { contentRsc, headings } = await renderMarkdownToRsc(
frontMatter.content,
)
Expand All @@ -239,6 +241,7 @@ export const fetchDocs = createServerFn({ method: 'GET' })
contentRsc,
title: frontMatter.data?.title ?? 'Content temporarily unavailable',
description,
keywords,
filePath,
headings,
frontmatter: frontMatter.data,
Expand All @@ -253,13 +256,32 @@ export const fetchDocsPage = createServerFn({ method: 'GET' })
return {
contentRsc: doc.contentRsc,
description: doc.description,
keywords: doc.keywords,
filePath: doc.filePath,
frontmatter: doc.frontmatter,
headings: doc.headings,
title: doc.title,
}
})

function extractFrontMatterKeywords(value: unknown): string | undefined {
if (Array.isArray(value)) {
const normalized = value
.filter((item): item is string => typeof item === 'string')
.map((item) => item.trim())
.filter((item) => item.length > 0)

return normalized.length > 0 ? normalized.join(', ') : undefined
}

if (typeof value === 'string') {
const trimmed = value.trim()
return trimmed.length > 0 ? trimmed : undefined
}

return undefined
}

export const fetchFile = createServerFn({ method: 'GET' })
.inputValidator(repoFileInput)
.handler(async ({ data }: { data: RepoFileRequest }) => {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/documents.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,25 @@ export function extractFrontMatter(content: string) {
excerpt: (file: any) => (file.excerpt = createRichExcerpt(file.content)),
})
const redirectFrom = normalizeRedirectFrom(result.data.redirect_from)
const userDescription =
typeof result.data.description === 'string' &&
result.data.description.trim().length > 0
? result.data.description
: undefined

return {
...result,
data: {
...result.data,
description: createExcerpt(result.content),
description: userDescription ?? createExcerpt(result.content),
redirect_from: redirectFrom,
redirectFrom,
} as { [key: string]: any } & {
description: string
redirect_from?: Array<string>
redirectFrom?: Array<string>
},
userDescription,
}
Comment on lines +424 to 443
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Consider trimming userDescription before returning.

userDescription is validated via .trim().length > 0 but the original (untrimmed) result.data.description is returned. If authors accidentally include leading/trailing whitespace or newlines (common with YAML block scalars like description: >), that whitespace will leak into the rendered <meta name="description"> and OG/Twitter tags downstream.

Proposed fix
   const userDescription =
     typeof result.data.description === 'string' &&
     result.data.description.trim().length > 0
-      ? result.data.description
+      ? result.data.description.trim()
       : undefined
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const userDescription =
typeof result.data.description === 'string' &&
result.data.description.trim().length > 0
? result.data.description
: undefined
return {
...result,
data: {
...result.data,
description: createExcerpt(result.content),
description: userDescription ?? createExcerpt(result.content),
redirect_from: redirectFrom,
redirectFrom,
} as { [key: string]: any } & {
description: string
redirect_from?: Array<string>
redirectFrom?: Array<string>
},
userDescription,
}
const userDescription =
typeof result.data.description === 'string' &&
result.data.description.trim().length > 0
? result.data.description.trim()
: undefined
return {
...result,
data: {
...result.data,
description: userDescription ?? createExcerpt(result.content),
redirect_from: redirectFrom,
redirectFrom,
} as { [key: string]: any } & {
description: string
redirect_from?: Array<string>
redirectFrom?: Array<string>
},
userDescription,
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/documents.server.ts` around lines 424 - 443, userDescription
currently checks trimmed length but returns the original untrimmed
result.data.description; update the logic around userDescription and the
returned data.description so any validated description is trimmed before being
stored/returned. Specifically, in the block that computes userDescription
(referencing result.data.description and userDescription) set userDescription to
result.data.description.trim() when non-empty, and ensure the returned
data.description uses this trimmed userDescription (falling back to
createExcerpt(result.content) as before) so no leading/trailing whitespace leaks
into meta tags.

}

Expand Down
Loading