Skip to content

Commit c6e5798

Browse files
carwackghostdevv
andauthored
feat: add copy readme as markdown button on package page (#1058)
Co-authored-by: Willow (GHOST) <git@willow.sh>
1 parent 3d3fb2a commit c6e5798

File tree

16 files changed

+89
-20
lines changed

16 files changed

+89
-20
lines changed

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

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ const { data: readmeData } = useLazyFetch<ReadmeResponse>(
6262
const version = requestedVersion.value
6363
return version ? `${base}/v/${version}` : base
6464
},
65-
{ default: () => ({ html: '', playgroundLinks: [], toc: [] }) },
65+
{ default: () => ({ html: '', md: '', playgroundLinks: [], toc: [] }) },
6666
)
6767
68+
//copy README file as Markdown
69+
const { copied: copiedReadme, copy: copyReadme } = useClipboard({
70+
source: () => readmeData.value?.md ?? '',
71+
copiedDuring: 2000,
72+
})
73+
6874
// Track active TOC item based on scroll position
6975
const tocItems = computed(() => readmeData.value?.toc ?? [])
7076
const { activeId: activeTocId, scrollToHeading } = useActiveTocItem(tocItems)
@@ -1136,12 +1142,39 @@ onKeyStroke(
11361142
</a>
11371143
</h2>
11381144
<ClientOnly>
1139-
<ReadmeTocDropdown
1140-
v-if="readmeData?.toc && readmeData.toc.length > 1"
1141-
:toc="readmeData.toc"
1142-
:active-id="activeTocId"
1143-
:scroll-to-heading="scrollToHeading"
1144-
/>
1145+
<div class="flex items-center gap-2">
1146+
<!-- Copy readme as Markdown button -->
1147+
<TooltipApp
1148+
v-if="readmeData?.md"
1149+
:text="$t('package.readme.copy_as_markdown')"
1150+
position="bottom"
1151+
>
1152+
<button
1153+
type="button"
1154+
@click="copyReadme()"
1155+
class="px-2 py-1.5 font-mono text-xs rounded transition-colors duration-150 inline-flex items-center gap-1.5"
1156+
:class="
1157+
copiedReadme ? 'text-accent bg-accent/10' : 'text-fg-subtle bg-bg hover:text-fg'
1158+
"
1159+
:aria-label="
1160+
copiedReadme ? $t('common.copied') : $t('package.readme.copy_as_markdown')
1161+
"
1162+
>
1163+
<span
1164+
:class="copiedReadme ? 'i-carbon:checkmark' : 'i-simple-icons:markdown'"
1165+
class="size-3"
1166+
aria-hidden="true"
1167+
/>
1168+
{{ copiedReadme ? $t('common.copied') : $t('common.copy') }}
1169+
</button>
1170+
</TooltipApp>
1171+
<ReadmeTocDropdown
1172+
v-if="readmeData?.toc && readmeData.toc.length > 1"
1173+
:toc="readmeData.toc"
1174+
:active-id="activeTocId"
1175+
:scroll-to-heading="scrollToHeading"
1176+
/>
1177+
</div>
11451178
</ClientOnly>
11461179
</div>
11471180

i18n/locales/de-DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Wichtig",
222222
"warning": "Warnung",
223223
"caution": "Vorsicht"
224-
}
224+
},
225+
"copy_as_markdown": "README als Markdown kopieren"
225226
},
226227
"provenance_section": {
227228
"title": "Herkunft",

i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Important",
222222
"warning": "Warning",
223223
"caution": "Caution"
224-
}
224+
},
225+
"copy_as_markdown": "Copy README as Markdown"
225226
},
226227
"provenance_section": {
227228
"title": "Provenance",

i18n/locales/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@
208208
"title": "Léeme",
209209
"no_readme": "No hay README disponible.",
210210
"view_on_github": "Ver en GitHub",
211-
"toc_title": "Índice"
211+
"toc_title": "Índice",
212+
"copy_as_markdown": "Copiar README como Markdown"
212213
},
213214
"keywords_title": "Palabras clave",
214215
"compatibility": "Compatibilidad",

i18n/locales/fr-FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@
206206
"title": "Readme",
207207
"no_readme": "Aucun README disponible.",
208208
"view_on_github": "Voir sur GitHub",
209-
"toc_title": "Sommaire"
209+
"toc_title": "Sommaire",
210+
"copy_as_markdown": "Copier le README en markdown"
210211
},
211212
"keywords_title": "Mots-clés",
212213
"compatibility": "Compatibilité",

i18n/locales/it-IT.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Importante",
222222
"warning": "Avvertenza",
223223
"caution": "Cautela"
224-
}
224+
},
225+
"copy_as_markdown": "Copia README come Markdown"
225226
},
226227
"provenance_section": {
227228
"title": "Provenienza",

lunaria/files/de-DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Wichtig",
222222
"warning": "Warnung",
223223
"caution": "Vorsicht"
224-
}
224+
},
225+
"copy_as_markdown": "README als Markdown kopieren"
225226
},
226227
"provenance_section": {
227228
"title": "Herkunft",

lunaria/files/en-GB.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Important",
222222
"warning": "Warning",
223223
"caution": "Caution"
224-
}
224+
},
225+
"copy_as_markdown": "Copy README as Markdown"
225226
},
226227
"provenance_section": {
227228
"title": "Provenance",

lunaria/files/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"important": "Important",
222222
"warning": "Warning",
223223
"caution": "Caution"
224-
}
224+
},
225+
"copy_as_markdown": "Copy README as Markdown"
225226
},
226227
"provenance_section": {
227228
"title": "Provenance",

lunaria/files/es-419.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@
208208
"title": "Léame",
209209
"no_readme": "No hay README disponible.",
210210
"view_on_github": "Ver en GitHub",
211-
"toc_title": "Índice"
211+
"toc_title": "Índice",
212+
"copy_as_markdown": "Copiar README como Markdown"
212213
},
213214
"keywords_title": "Palabras clave",
214215
"compatibility": "Compatibilidad",

0 commit comments

Comments
 (0)