Skip to content

Commit 91266e0

Browse files
authored
fix: unable to create buffer from empty readme (#39)
* fix: unable to create buffer from empty readme * fix: narrow `remarkPlugins` type
1 parent d0497a0 commit 91266e0

File tree

4 files changed

+401
-361
lines changed

4 files changed

+401
-361
lines changed

playground/pages/readme.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ const qRepo = ref('supabase-module')
66
<template>
77
<div>
88
<GithubReadme v-slot="{ readme, refresh }" :query="{ owner: qOwner, repo: qRepo }">
9-
Fetch readme from query:
9+
Fetch README from query:
1010
<input v-model="qOwner" style="margin-left: 1rem;" type="text"> /
1111
<input v-model="qRepo" type="text">
1212
<button style="margin-left: 1rem;" @click="refresh">
1313
Search
1414
</button>
15-
<ContentRenderer :value="readme" />
15+
<ContentRenderer :value="readme">
16+
<template #empty>
17+
<div style="margin: 1rem 0">
18+
README not found
19+
</div>
20+
</template>
21+
</ContentRenderer>
1622
</GithubReadme>
1723
</div>
1824
</template>

src/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ export default defineNuxtModule<ModuleOptions>({
8383
if (options.remarkPlugin) {
8484
// @ts-ignore
8585
nuxt.hook('content:context', (context) => {
86-
context.markdown.remarkPlugins = context.markdown.remarkPlugins || {}
87-
context.markdown.remarkPlugins['remark-github'] = { repository: `${options.owner}/${options.repo}` }
86+
context.markdown.remarkPlugins ??= {}
87+
88+
if (!Array.isArray(context.markdown.remarkPlugins)) {
89+
context.markdown.remarkPlugins['remark-github'] = { repository: `${options.owner}/${options.repo}` }
90+
}
8891
})
8992
}
9093

src/runtime/server/api/readme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default handler(
3333
const readme = await fetchReadme(githubConfig) as GithubRepositoryReadme
3434

3535
// Readme readable content
36-
const content = Buffer.from(readme.content, 'base64').toString()
36+
const content = Buffer.from(readme.content ?? '', 'base64').toString()
3737

3838
// Parse contents with @nuxt/content if enabled
3939
if (moduleConfig.parseContents) {

0 commit comments

Comments
 (0)