Skip to content

Commit 41fe20a

Browse files
committed
feat: also pass the original content as md when fetching readmeData
1 parent 7e816a6 commit 41fe20a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

app/pages/package/[...package].vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ const { data: readmeData } = useLazyFetch<ReadmeResponse>(
6767
const version = requestedVersion.value
6868
return version ? `${base}/v/${version}` : base
6969
},
70-
{ default: () => ({ html: '', playgroundLinks: [], toc: [] }) },
70+
{ default: () => ({ html: '', md: '', playgroundLinks: [], toc: [] }) },
7171
)
7272
73-
//copy README file
73+
//copy README file as Markdown
7474
const { copied: copiedReadme, copy: copyReadme } = useClipboard({
75-
source: readmeData.value?.html ?? '',
75+
source: readmeData.value?.md ?? '',
7676
copiedDuring: 2000,
7777
})
7878
@@ -1137,15 +1137,16 @@ onKeyStroke(
11371137
</h2>
11381138
<ClientOnly>
11391139
<div class="flex items-center gap-2">
1140+
<!-- Copy readme as Markdown button -->
11401141
<TooltipApp
1141-
v-if="readmeData?.html"
1142+
v-if="readmeData?.md"
11421143
:text="copiedReadme ? $t('common.copied') : $t('package.readme.copy_as_markdown')"
11431144
position="bottom"
11441145
>
11451146
<button
11461147
type="button"
11471148
@click="copyReadme()"
1148-
:disabled="!readmeData?.html"
1149+
:disabled="!readmeData?.md"
11491150
class="px-2 py-1.5 font-mono text-xs rounded transition-colors duration-150 text-fg-subtle hover:text-fg inline-flex items-center gap-1.5"
11501151
:class="
11511152
copiedReadme ? 'text-accent bg-accent/10' : 'text-fg-subtle bg-bg hover:text-fg'

server/utils/readme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export async function renderReadmeHtml(
269269
packageName: string,
270270
repoInfo?: RepositoryInfo,
271271
): Promise<ReadmeResponse> {
272-
if (!content) return { html: '', playgroundLinks: [], toc: [] }
272+
if (!content) return { html: '', md: '', playgroundLinks: [], toc: [] }
273273

274274
const shiki = await getShikiHighlighter()
275275
const renderer = new marked.Renderer()
@@ -455,6 +455,7 @@ ${html}
455455

456456
return {
457457
html: convertToEmoji(sanitized),
458+
md: content,
458459
playgroundLinks: collectedLinks,
459460
toc,
460461
}

shared/types/readme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface TocItem {
3030
export interface ReadmeResponse {
3131
/** Rendered HTML content */
3232
html: string
33+
/** Original markdown content */
34+
md: string
3335
/** Extracted playground/demo links */
3436
playgroundLinks: PlaygroundLink[]
3537
/** Table of contents extracted from headings */

0 commit comments

Comments
 (0)