Skip to content

Commit

Permalink
feat: auto note about automd pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 4, 2024
1 parent b774fcd commit 20c2e83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
41 changes: 14 additions & 27 deletions app/pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,12 @@ onMounted(() => {
<UContentToc title="On this page" :links="tocLinks" class="hidden lg:block" />
</template>
<!-- mobile -->
<div
v-if="tocMobileLinks.length > 1"
class="float-right mt-4 top-[calc(var(--header-height)_+_0.5rem)] z-10 flex justify-end sticky mb-2 lg:hidden"
>
<UDropdown
v-model:open="tocMobileOpen"
:items="tocMobileLinks"
:popper="{ placement: 'bottom-end' }"
:mode="isMobile ? 'click' : 'hover'"
>
<UButton
color="white"
label="On this page"
:trailing="false"
:icon="`i-heroicons-chevron-${tocMobileOpen ? 'down' : 'left'}-20-solid`"
/>
<div v-if="tocMobileLinks.length > 1"
class="float-right mt-4 top-[calc(var(--header-height)_+_0.5rem)] z-10 flex justify-end sticky mb-2 lg:hidden">
<UDropdown v-model:open="tocMobileOpen" :items="tocMobileLinks" :popper="{ placement: 'bottom-end' }"
:mode="isMobile ? 'click' : 'hover'">
<UButton color="white" label="On this page" :trailing="false"
:icon="`i-heroicons-chevron-${tocMobileOpen ? 'down' : 'left'}-20-solid`" />
</UDropdown>
</div>

Expand All @@ -105,17 +95,14 @@ onMounted(() => {
<div class="space-y-6">
<UDivider type="dashed" />
<div class="mb-4">
<UPageLinks
class="inline-block"
:links="[
{
icon: 'i-ph-pen-duotone',
label: 'Edit this page on GitHub',
to: `https://github.com/${appConfig.docs.github}/edit/${appConfig.docs.branch || 'main'}/docs/${page._file}`,
target: '_blank',
},
]"
/>
<UPageLinks class="inline-block" :links="[
{
icon: 'i-ph-pen-duotone',
label: `Edit this page ${page.automd ? '(some contents are generated with automd from source)' : ''}`,
to: `https://github.com/${appConfig.docs.github}/edit/${appConfig.docs.branch || 'main'}/docs/${page._file}`,
target: '_blank',
},
]" />
</div>
<UContentSurround v-if="surround?.length" class="mb-4" :surround="surround" />
</div>
Expand Down
13 changes: 13 additions & 0 deletions app/server/plugins/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// @ts-ignore
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('content:file:beforeParse', (file) => {
if (typeof file.body !== 'string') {
return // can be json meta
}
if (file.body.includes('<!-- automd:')) {
// Add meta
if (file.body.startsWith('---')) {
file.body = file.body.replace('---', '---\nautomd: true\n')
} else {
file.body = `---\nautomd: true\n---\n${file.body}`
}
}
})
nitroApp.hooks.hook('content:file:afterParse', (file: ContentFile) => {
// Filter out non-markdown files
if (!file._id?.endsWith('.md')) {
Expand Down
8 changes: 0 additions & 8 deletions docs/2.config/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,3 @@ It will be used as the `theme-color` meta tag and a full palette of colors will
The URL of the documentation site.

<!-- /automd -->

<!-- automd:with-automd -->

---

_🤖 auto updated with [automd](https://automd.unjs.io)_

<!-- /automd -->

0 comments on commit 20c2e83

Please sign in to comment.