Skip to content

Commit 1d41bb3

Browse files
chore: update to content v3
1 parent 9e00d4c commit 1d41bb3

File tree

12 files changed

+6988
-4476
lines changed

12 files changed

+6988
-4476
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ web_modules/
8888
out
8989

9090
# Nuxt.js build / generate output
91+
.data
9192
.nuxt
9293
.output
9394
dist

.yarn/releases/yarn-4.5.2.cjs

Lines changed: 0 additions & 934 deletions
This file was deleted.

.yarn/releases/yarn-4.9.1.cjs

Lines changed: 948 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ enableGlobalCache: true
22

33
nodeLinker: node-modules
44

5-
yarnPath: .yarn/releases/yarn-4.5.2.cjs
5+
yarnPath: .yarn/releases/yarn-4.9.1.cjs

app/components/navbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<header class="block flex p-4">
2+
<header class="block flex px-4 py-2">
33
<nuxt-link to="/">
44
<img
55
src="https://github.com/HigherOrderLogic.png"

app/layouts/default.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="font-normal font-[Inter_Variable] prose-neutral dark:prose-invert">
33
<div>
44
<navbar />
5-
<div class="mx-a lt-md:px-4 md:prose" :class="[$style.dashed_link, $style.no_header_underline]">
5+
<div class="mx-a lt-md:px-4 md:prose" :class="[$style.dashedLink, $style.noHeaderUnderline]">
66
<slot />
77
<div class="h-8" />
88
<cd />
@@ -12,13 +12,13 @@
1212
</template>
1313

1414
<style lang="scss" module>
15-
.dashed_link {
15+
.dashedLink {
1616
a {
17-
--at-apply: 'underline-dashed hover:underline-solid'
17+
--at-apply: 'underline-dashed underline-offset-2 hover:(underline-solid underline-offset-1.5)'
1818
}
1919
}
2020
21-
.no_header_underline {
21+
.noHeaderUnderline {
2222
h1, h2, h3, h4, h5, h6 {
2323
a {
2424
--at-apply: 'no-underline'

app/pages/blogs/[...slugs].vue

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import type { MinimalNode } from '@nuxt/content'
3+
24
const ContentNotFound = defineComponent({
35
setup() {
46
showError({
@@ -10,50 +12,40 @@ const ContentNotFound = defineComponent({
1012
</script>
1113

1214
<script setup lang="ts">
13-
// eslint-disable-next-line import/first
14-
import type { MarkdownNode, ParsedContent } from '@nuxt/content'
15-
16-
function parseNode(node: MarkdownNode): number {
15+
function getWordCount(nodesList: MinimalNode[]): number {
1716
let wordCount = 0
1817
19-
if (node.type === 'text' && node.value) {
20-
wordCount += node.value.split(' ').length
21-
}
22-
23-
for (const child of node.children ?? []) {
24-
wordCount += parseNode(child)
18+
for (const node of nodesList) {
19+
if (Array.isArray(node)) {
20+
const [content, _data, ...childNode] = node
21+
wordCount += content.length + getWordCount(childNode)
22+
} else {
23+
wordCount += node.length
24+
}
2525
}
2626
2727
return wordCount
2828
}
2929
30-
function getWordCount(parsedContent: ParsedContent): number {
31-
let wordCount = 0
30+
const route = useRoute()
3231
33-
if (parsedContent.body) {
34-
for (const child of parsedContent.body.children) {
35-
wordCount += parseNode(child)
36-
}
37-
}
38-
39-
return wordCount
40-
}
32+
const { data: blog } = await useAsyncData(`blog-${route.path}`, () => queryCollection('blogs').path(route.path).first())
4133
</script>
4234

4335
<template>
44-
<content-doc>
45-
<template #default="{ doc }">
36+
<div>
37+
<template v-if="blog">
4638
<div class="pb-4">
47-
<h1>{{ doc.title }}</h1>
48-
<p class="op-70 divide-x *:px-2 first:*:pl-0">
49-
<span>{{ useDateFormat(doc.date, 'ddd, DD MMMM YYYY') }}</span>
50-
<span>{{ getWordCount(doc) }} words</span>
39+
<h1>{{ blog.title }}</h1>
40+
<p class="op-70 divide-x *:pr-2 not-first:*:pl-2">
41+
<span>{{ useDateFormat(blog.date, 'ddd, DD MMMM YYYY') }}</span>
42+
<span>{{ getWordCount(blog.body.value) }} words</span>
5143
</p>
5244
</div>
53-
<content-renderer :value="doc" />
45+
<content-renderer :value="blog" />
5446
</template>
55-
<template #not-found>
47+
<template v-else>
5648
<content-not-found />
5749
</template>
58-
</content-doc>
50+
</div>
5951
</template>

app/pages/blogs/index.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
<script setup lang="ts">
22
useSeoMeta({ title: 'Blogs' })
3+
4+
const { data: blogsList } = await useAsyncData('blogsList', () =>
5+
queryCollection('blogs').select('id', 'path', 'title', 'date').order('date', 'DESC').all())
36
</script>
47

58
<template>
69
<div>
710
<h1 class="pb-4">
811
Blogs
912
</h1>
10-
<content-list v-slot="{ list }" path="/blogs">
11-
<div class="divide-y divide-gray divide-op-20 divide-dashed dark:(divide-zinc divide-op-25)">
13+
<div class="divide-y divide-gray divide-op-20 divide-dashed dark:(divide-zinc divide-op-25)">
14+
<template v-if="blogsList?.length">
1215
<template
13-
v-for="blog in list.sort((a, b) => +new Date(b.date) - +new Date(a.date))"
14-
:key="blog._path"
16+
v-for="blog in blogsList"
17+
:key="blog.id"
1518
>
1619
<div class="flex flex-col items-start py-2 md:flex-row">
1720
<h3 class="my-2 flex-auto md:m-a">
18-
<nuxt-link :to="blog._path">
21+
<nuxt-link :to="blog.path">
1922
{{ blog.title }}
2023
</nuxt-link>
2124
</h3>
@@ -24,7 +27,12 @@ useSeoMeta({ title: 'Blogs' })
2427
</p>
2528
</div>
2629
</template>
27-
</div>
28-
</content-list>
30+
</template>
31+
<template v-else>
32+
<div class="w-full text-center text-size-lg">
33+
There is nothing here...
34+
</div>
35+
</template>
36+
</div>
2937
</div>
3038
</template>

content.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
2+
3+
export default defineContentConfig({
4+
collections: {
5+
blogs: defineCollection({
6+
type: 'page',
7+
source: 'blogs/**',
8+
schema: z.object({
9+
date: z.string(),
10+
}),
11+
}),
12+
},
13+
})

nuxt.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default defineNuxtConfig({
3333
},
3434
},
3535

36+
ssr: false,
37+
3638
modules: [
3739
'@nuxt/content',
3840
'@nuxtjs/color-mode',
@@ -59,10 +61,11 @@ export default defineNuxtConfig({
5961
},
6062

6163
pwa: {
64+
devOptions: { enabled: true },
6265
registerType: 'autoUpdate',
6366
workbox: {
6467
navigateFallback: '/',
65-
globPatterns: ['**/*.{js,css,html,woff2}', 'api/**/*.json'],
68+
globPatterns: ['**/*.{js,css,html,woff2}'],
6669
},
6770
manifest: {
6871
background_color: '#FFF',
@@ -73,4 +76,6 @@ export default defineNuxtConfig({
7376
shortcuts: [{ name: 'Blogs', url: '/blogs' }],
7477
},
7578
},
79+
80+
compatibilityDate: '2025-04-24',
7681
})

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "horu.me",
33
"type": "module",
4-
"packageManager": "yarn@4.5.2",
4+
"packageManager": "yarn@4.9.1",
55
"license": "MIT",
66
"scripts": {
77
"postinstall": "yarn run prepare",
@@ -13,22 +13,22 @@
1313
"lint": "eslint ."
1414
},
1515
"devDependencies": {
16-
"@antfu/eslint-config": "^3.9.2",
17-
"@fontsource-variable/inter": "^5.1.0",
18-
"@iconify/json": "^2.2.275",
19-
"@nuxt/content": "^2.13.4",
20-
"@nuxt/eslint": "^0.7.1",
21-
"@nuxt/image": "^1.8.1",
16+
"@antfu/eslint-config": "^4.12.0",
17+
"@fontsource-variable/inter": "^5.2.5",
18+
"@iconify/json": "^2.2.331",
19+
"@nuxt/content": "^3.5.0",
20+
"@nuxt/eslint": "^1.3.0",
21+
"@nuxt/image": "^1.10.0",
2222
"@nuxtjs/color-mode": "^3.5.2",
2323
"@types/eslint": "^9.6.1",
24-
"@unocss/eslint-plugin": "^0.64.1",
25-
"@unocss/nuxt": "^0.64.1",
26-
"@vite-pwa/nuxt": "^0.10.6",
27-
"@vueuse/nuxt": "^12.0.0",
28-
"eslint": "^9.15.0",
29-
"nuxt": "^3.14.1592",
30-
"sass-embedded": "^1.81.0",
31-
"typescript": "^5.7.2",
32-
"vue-tsc": "^2.1.10"
24+
"@unocss/eslint-plugin": "^66.0.0",
25+
"@unocss/nuxt": "^66.0.0",
26+
"@vite-pwa/nuxt": "^1.0.0",
27+
"@vueuse/nuxt": "^13.1.0",
28+
"eslint": "^9.25.1",
29+
"nuxt": "^3.16.2",
30+
"sass-embedded": "^1.87.0",
31+
"typescript": "^5.8.3",
32+
"vue-tsc": "^2.2.10"
3333
}
3434
}

0 commit comments

Comments
 (0)