FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: more rendering fixes · unjs/unifont@10c52e4 · GitHub

/ unifont Public

Commit 10c52e4

Browse files
committed
docs: more rendering fixes
1 parent 7ebd676 commit 10c52e4

6 files changed

Lines changed: 50 additions & 17 deletions

File tree

‎docs/app/app.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if (import.meta.client) {
8686
>
8787
<NuxtPage />
8888
</main>
89-
<LazySiteFooter hydrate-never />
89+
<LazySiteFooter hydrate-on-visible />
9090
</div>
9191
</template>
9292

‎docs/app/components/SiteFooter.vue‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<script setup lang="ts">
22
import type { ContributorsResponse } from '#shared/types'
33
4-
// Server-rendered: a client-only avatar row lands after hydration and pushes the colophon down.
5-
const { data: credits } = await useFetch<ContributorsResponse>('/api/v1/contributors', {
4+
// Server-rendered: a client-only credit line lands after hydration and pushes the colophon down.
5+
// Only the count survives into the payload; the avatars and profiles are not drawn here.
6+
const { data: credits } = await useFetch('/api/v1/contributors', {
67
key: 'footer-contributors',
7-
// The colophon never hydrates, so the avatar list need not go into the payload.
8-
serialize: false,
8+
/** Named in the template: danielroe, qwerzl, florian-lefebvre. Zero when GitHub is rate-limited. */
9+
transform: (response: ContributorsResponse) => ({ others: Math.max(0, (response.contributors?.length ?? 0) - 3) }),
910
})
1011
11-
const contributors = computed(() => credits.value?.contributors ?? [])
12-
13-
/** Named above: danielroe, qwerzl, florian-lefebvre. Zero when GitHub is rate-limited. */
14-
const others = computed(() => Math.max(0, contributors.value.length - 3))
12+
const others = computed(() => credits.value?.others ?? 0)
1513
</script>
1614

1715
<template>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { createContentClient } from 'comark-content/client'
22

33
export const clientContent = createContentClient({
4-
fetch: $fetch,
4+
/*
5+
* `responseType: 'json'` rather than a bare `$fetch`: the endpoints are prerendered to
6+
* extensionless files, and a page whose own prerender runs after one of them is handed that
7+
* file with no content type, which `ofetch` leaves as a string.
8+
*/
9+
fetch: (request, options) => $fetch(request as string, { ...options, responseType: 'json' }),
510
})

‎docs/app/error.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ usePageSeo({
5454
>Back to the start</NuxtLink>
5555
</div>
5656
</main>
57-
<LazySiteFooter hydrate-never />
57+
<LazySiteFooter hydrate-on-visible />
5858
</div>
5959
</template>
6060

‎docs/nuxt.config.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,14 @@ export default defineNuxtConfig({
211211
'prerender:routes': async ({ routes }) => {
212212
const { content } = await import('./server/utils/content.ts')
213213
const pages = new Set(proseRoutes)
214-
for (const { path } of await content.list()) {
214+
const paths = (await content.list()).map((file: { path: string }) => file.path)
215+
for (const path of paths) {
215216
routes.add(path)
216-
routes.add(`/api/content/get/${path.replace(/^\//, '')}`)
217+
// Each endpoint is prerendered to a file, so `/docs`, which is also the parent of every
218+
// chapter, would have to be a file and a directory at once. It is left to the server.
219+
if (!paths.some((other: string) => other.startsWith(`${path}/`))) {
220+
routes.add(`/api/content/get/${path.replace(/^\//, '')}`)
221+
}
217222
pages.add(path)
218223
}
219224
for (const page of pages) {

‎docs/server/utils/content.ts‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
import { existsSync } from 'node:fs'
2+
import { fileURLToPath } from 'node:url'
3+
import type { Driver } from 'unstorage'
14
import { comarkContent } from 'comark-content'
2-
import fs from 'comark-content/sources/fs'
5+
import fsSource from 'comark-content/sources/fs'
6+
import unstorageSource from 'comark-content/sources/unstorage'
7+
import { useStorage } from 'nitro/storage'
38

4-
export const content = comarkContent({
5-
source: fs('./content'),
6-
})
9+
/**
10+
* `content/` is next to this module only when it is loaded from source, which is how
11+
* `nuxt.config.ts` lists the pages to prerender before nitro exists. Anywhere the server has been
12+
* bundled the markdown is read back from the `content` server asset instead, because a deployment
13+
* has no `content/` directory.
14+
*/
15+
const contentDir = fileURLToPath(new URL('../../content', import.meta.url))
16+
17+
/** The `content` server asset, as the driver `unstorageSource` wants rather than a `Storage`. */
18+
function assetDriver(): Driver {
19+
const storage = useStorage('assets:content')
20+
return {
21+
name: 'server-assets',
22+
options: {},
23+
getKeys: () => storage.getKeys(),
24+
hasItem: key => storage.hasItem(key),
25+
getItem: key => storage.getItem(key),
26+
}
27+
}
28+
29+
const source = existsSync(contentDir) ? fsSource(contentDir) : unstorageSource({ driver: assetDriver() })
30+
31+
export const content = comarkContent({ source })

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL