create-knit 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +17 -2
- package/index.mjs +248 -0
- package/package.json +32 -3
- package/template/base/.claude/skills/knit-add-api/SKILL.md +41 -0
- package/template/base/.claude/skills/knit-add-model/SKILL.md +31 -0
- package/template/base/.cursor/mcp.json +24 -0
- package/template/base/.mcp.json +25 -0
- package/template/base/.vscode/mcp.json +25 -0
- package/template/base/AGENTS.md +76 -0
- package/template/base/CLAUDE.md +9 -0
- package/template/base/_gitignore +13 -0
- package/template/base/apps/web/.env.example +124 -0
- package/template/base/apps/web/app/app.vue +7 -0
- package/template/base/apps/web/app/pages/index.vue +20 -0
- package/template/base/apps/web/tsconfig.json +9 -0
- package/template/base/docker/.env.production.example +21 -0
- package/template/base/docker/Dockerfile +64 -0
- package/template/base/docker/Dockerfile.dockerignore +16 -0
- package/template/base/docker/dev.Dockerfile +10 -0
- package/template/base/docker/dev.Dockerfile.dockerignore +2 -0
- package/template/base/docker/docker-compose.prod.yml +44 -0
- package/template/base/docker-compose.yml +71 -0
- package/template/examples/apps/web/app/pages/platform.vue +94 -0
- package/template/examples/apps/web/server/api/demo/flash.post.ts +5 -0
- package/template/examples/layers/example-blog/admin.ts +126 -0
- package/template/examples/layers/example-blog/app/pages/blog/[slug].vue +169 -0
- package/template/examples/layers/example-blog/app/pages/blog/index.vue +73 -0
- package/template/examples/layers/example-blog/app/pages/blog/stats.vue +33 -0
- package/template/examples/layers/example-blog/commands/publishpost.ts +23 -0
- package/template/examples/layers/example-blog/i18n/locales/de.json +140 -0
- package/template/examples/layers/example-blog/i18n/locales/en.json +33 -0
- package/template/examples/layers/example-blog/i18n/locales/es.json +140 -0
- package/template/examples/layers/example-blog/nuxt.config.ts +9 -0
- package/template/examples/layers/example-blog/package.json +18 -0
- package/template/examples/layers/example-blog/server/api/blog/posts/[slug].get.ts +15 -0
- package/template/examples/layers/example-blog/server/api/blog/posts.get.ts +14 -0
- package/template/examples/layers/example-blog/server/api/blog/word-count.post.ts +23 -0
- package/template/examples/layers/example-blog/server/channels/comments.ts +39 -0
- package/template/examples/layers/example-blog/server/database/schema.ts +160 -0
- package/template/examples/layers/example-blog/server/database/seed.ts +24 -0
- package/template/examples/layers/example-blog/server/feeds/blog.ts +26 -0
- package/template/examples/layers/example-blog/server/resources/comments.ts +78 -0
- package/template/examples/layers/example-blog/server/resources/posts.ts +25 -0
- package/template/examples/layers/example-blog/server/routes/blog/atom.xml.ts +4 -0
- package/template/examples/layers/example-blog/server/routes/blog/feed.xml.ts +4 -0
- package/template/examples/layers/example-blog/server/sitemaps/blog.ts +14 -0
- package/template/examples/layers/example-blog/server/tasks/blog.ts +49 -0
- package/template/examples/layers/example-blog/test/blog.test.ts +46 -0
- package/template/examples/layers/example-blog/test/i18n.test.ts +27 -0
- package/template/examples/layers/example-blog/tsconfig.json +9 -0
- package/template/examples/layers/example-dashboard/app/pages/dashboard.vue +67 -0
- package/template/examples/layers/example-dashboard/i18n/locales/de.json +12 -0
- package/template/examples/layers/example-dashboard/i18n/locales/en.json +12 -0
- package/template/examples/layers/example-dashboard/i18n/locales/es.json +12 -0
- package/template/examples/layers/example-dashboard/nuxt.config.ts +12 -0
- package/template/examples/layers/example-dashboard/package.json +16 -0
- package/template/examples/layers/example-dashboard/tsconfig.json +9 -0
- package/template/versions.json +13 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { fileUrl } from '#framework/files-types'
|
|
3
|
+
import { resourceParseError } from '#framework/resources-types'
|
|
4
|
+
import type { comment } from '../../../server/database/schema'
|
|
5
|
+
|
|
6
|
+
const route = useRoute()
|
|
7
|
+
const { t, locale } = useI18n()
|
|
8
|
+
const slug = computed(() => String(route.params.slug))
|
|
9
|
+
const { data: post, error } = await useFetch(() => `/api/blog/posts/${slug.value}`)
|
|
10
|
+
if (error.value) throw createError({ statusCode: 404, statusMessage: t('blog.notFound'), fatal: true })
|
|
11
|
+
|
|
12
|
+
useHead({ title: () => post.value?.title ?? t('blog.post') })
|
|
13
|
+
|
|
14
|
+
// Comments come from the public `comments` resource (layers/example-blog/server/resources/comments.ts):
|
|
15
|
+
// visitors see approved comments, authors also their own pending ones.
|
|
16
|
+
const { user, loggedIn, ready, fetchSession } = useAuth()
|
|
17
|
+
if (!ready.value) await fetchSession()
|
|
18
|
+
|
|
19
|
+
const comments = useResource<typeof comment, { author: { id: string, name: string } }>('comments')
|
|
20
|
+
const { items, total, refresh } = comments.list({
|
|
21
|
+
key: `blog-comments:${slug.value}`,
|
|
22
|
+
filters: () => ({ postId: post.value?.id }),
|
|
23
|
+
perPage: 50,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Live updates: `broadcastModel(comment, …)` publishes every comment write on
|
|
27
|
+
// `comments:post:<id>` (server/channels/comments.ts decides who hears what); the list re-reads
|
|
28
|
+
// through the resource, so moderation and scoping apply exactly as on the first load.
|
|
29
|
+
const live = useRealtimeModel({ refresh }, () => (post.value ? `comments:post:${post.value.id}` : null))
|
|
30
|
+
|
|
31
|
+
const toast = useToast()
|
|
32
|
+
const editing = ref<number | null>(null)
|
|
33
|
+
const removing = ref<number | null>(null)
|
|
34
|
+
|
|
35
|
+
async function onSaved(_row: Record<string, unknown>, created: boolean): Promise<void> {
|
|
36
|
+
editing.value = null
|
|
37
|
+
await refresh()
|
|
38
|
+
toast.add({
|
|
39
|
+
title: created ? t('blog.thanks') : t('blog.updated'),
|
|
40
|
+
description: created ? t('blog.thanksDescription') : undefined,
|
|
41
|
+
color: 'success',
|
|
42
|
+
icon: 'i-lucide-check',
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function remove(id: number): Promise<void> {
|
|
47
|
+
removing.value = id
|
|
48
|
+
try {
|
|
49
|
+
await comments.remove(id)
|
|
50
|
+
await refresh()
|
|
51
|
+
toast.add({ title: t('blog.deleted'), color: 'neutral', icon: 'i-lucide-trash-2' })
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
toast.add({ title: t('blog.deleteFailed'), description: resourceParseError(e).message, color: 'error' })
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
removing.value = null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const loginUrl = computed(() => `/accounts/login?redirect=${encodeURIComponent(route.fullPath)}`)
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<UContainer v-if="post" class="space-y-6 py-12">
|
|
66
|
+
<UButton to="/blog" icon="i-lucide-arrow-left" color="neutral" :label="t('blog.allPosts')" variant="link" class="px-0" />
|
|
67
|
+
<article class="space-y-4">
|
|
68
|
+
<img
|
|
69
|
+
v-if="post.cover"
|
|
70
|
+
:src="fileUrl(post.cover)"
|
|
71
|
+
:alt="post.title"
|
|
72
|
+
class="aspect-[2/1] w-full rounded-lg object-cover"
|
|
73
|
+
>
|
|
74
|
+
<h1 class="text-3xl font-bold text-highlighted">
|
|
75
|
+
{{ post.title }}
|
|
76
|
+
</h1>
|
|
77
|
+
<p class="text-sm text-muted">
|
|
78
|
+
<span v-if="post.publishedAt">{{ naturalday(post.publishedAt) }}</span>
|
|
79
|
+
<span v-if="post.author"> · {{ post.author.name }}</span>
|
|
80
|
+
<span v-if="post.category"> · {{ post.category.name }}</span>
|
|
81
|
+
</p>
|
|
82
|
+
<p class="whitespace-pre-line text-default">
|
|
83
|
+
{{ post.body }}
|
|
84
|
+
</p>
|
|
85
|
+
</article>
|
|
86
|
+
|
|
87
|
+
<USeparator />
|
|
88
|
+
|
|
89
|
+
<section class="space-y-6" aria-labelledby="comments-heading">
|
|
90
|
+
<div class="flex items-center gap-3">
|
|
91
|
+
<h2 id="comments-heading" class="text-xl font-semibold text-highlighted">
|
|
92
|
+
{{ t('blog.comments') }} <span class="text-muted">({{ total }})</span>
|
|
93
|
+
</h2>
|
|
94
|
+
<UBadge
|
|
95
|
+
v-if="live.status.value === 'open'"
|
|
96
|
+
color="success"
|
|
97
|
+
variant="subtle"
|
|
98
|
+
size="sm"
|
|
99
|
+
icon="i-lucide-radio"
|
|
100
|
+
:label="t('blog.live')"
|
|
101
|
+
data-testid="comments-live"
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<ul v-if="items.length" class="space-y-4">
|
|
106
|
+
<li v-for="c in items" :key="c.id" class="space-y-2 rounded-lg border border-default bg-elevated/40 p-4">
|
|
107
|
+
<div class="flex flex-wrap items-center gap-2 text-sm">
|
|
108
|
+
<UAvatar :alt="c.author.name" size="xs" />
|
|
109
|
+
<span class="font-medium text-highlighted">{{ c.author.name }}</span>
|
|
110
|
+
<span class="text-muted">· <NuxtTime :datetime="c.createdAt" :locale="locale" relative /></span>
|
|
111
|
+
<UBadge v-if="!c.approved" color="warning" variant="subtle" size="sm" :label="t('blog.pending')" />
|
|
112
|
+
<div v-if="user && c.authorId === user.id && editing !== c.id" class="ms-auto flex gap-1">
|
|
113
|
+
<UButton size="xs" color="neutral" variant="ghost" icon="i-lucide-pencil" :label="t('blog.edit')" @click="editing = c.id" />
|
|
114
|
+
<UButton
|
|
115
|
+
size="xs"
|
|
116
|
+
color="error"
|
|
117
|
+
variant="ghost"
|
|
118
|
+
icon="i-lucide-trash-2"
|
|
119
|
+
:label="t('blog.delete')"
|
|
120
|
+
:loading="removing === c.id"
|
|
121
|
+
@click="remove(c.id)"
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
<KnitModelForm
|
|
126
|
+
v-if="editing === c.id"
|
|
127
|
+
resource="comments"
|
|
128
|
+
:id="c.id"
|
|
129
|
+
:fields="['body']"
|
|
130
|
+
hide-labels
|
|
131
|
+
cancelable
|
|
132
|
+
@saved="onSaved"
|
|
133
|
+
@cancel="editing = null"
|
|
134
|
+
/>
|
|
135
|
+
<p v-else class="whitespace-pre-line text-default">
|
|
136
|
+
{{ c.body }}
|
|
137
|
+
</p>
|
|
138
|
+
</li>
|
|
139
|
+
</ul>
|
|
140
|
+
<p v-else class="text-sm text-muted">
|
|
141
|
+
{{ t('blog.noComments') }}
|
|
142
|
+
</p>
|
|
143
|
+
|
|
144
|
+
<div class="space-y-3">
|
|
145
|
+
<h3 class="font-medium text-highlighted">
|
|
146
|
+
{{ t('blog.leaveComment') }}
|
|
147
|
+
</h3>
|
|
148
|
+
<KnitModelForm
|
|
149
|
+
v-if="loggedIn"
|
|
150
|
+
resource="comments"
|
|
151
|
+
:initial="{ postId: post.id }"
|
|
152
|
+
:fields="['body']"
|
|
153
|
+
:placeholders="{ body: t('blog.placeholder') }"
|
|
154
|
+
:labels="{ create: t('blog.submit') }"
|
|
155
|
+
hide-labels
|
|
156
|
+
@saved="onSaved"
|
|
157
|
+
/>
|
|
158
|
+
<UAlert
|
|
159
|
+
v-else
|
|
160
|
+
color="neutral"
|
|
161
|
+
variant="subtle"
|
|
162
|
+
icon="i-lucide-message-square"
|
|
163
|
+
:title="t('blog.signInPrompt')"
|
|
164
|
+
:actions="[{ label: t('blog.signIn'), to: loginUrl, color: 'neutral', variant: 'outline' }]"
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
</section>
|
|
168
|
+
</UContainer>
|
|
169
|
+
</template>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const { data: posts } = await useFetch('/api/blog/posts')
|
|
3
|
+
const { loggedIn, fetchSession } = useAuth()
|
|
4
|
+
const { t } = useI18n()
|
|
5
|
+
await fetchSession()
|
|
6
|
+
|
|
7
|
+
useHead({
|
|
8
|
+
title: () => t('blog.title'),
|
|
9
|
+
link: [
|
|
10
|
+
{ rel: 'alternate', type: 'application/rss+xml', title: t('blog.feed', { format: 'RSS' }), href: '/blog/feed.xml' },
|
|
11
|
+
{ rel: 'alternate', type: 'application/atom+xml', title: t('blog.feed', { format: 'Atom' }), href: '/blog/atom.xml' },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const counting = ref<number | null>(null)
|
|
16
|
+
async function countWords(postId: number): Promise<void> {
|
|
17
|
+
counting.value = postId
|
|
18
|
+
try {
|
|
19
|
+
await $fetch('/api/blog/word-count', { method: 'POST', body: { postId } })
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
counting.value = null
|
|
23
|
+
// The handler called flash(); show it now instead of on the next page.
|
|
24
|
+
useFlash().check()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<UContainer class="space-y-6 py-12">
|
|
31
|
+
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
32
|
+
<h1 class="text-3xl font-bold text-highlighted">
|
|
33
|
+
{{ t('blog.title') }}
|
|
34
|
+
</h1>
|
|
35
|
+
<div class="flex gap-2">
|
|
36
|
+
<UButton to="/blog/feed.xml" external target="_blank" icon="i-lucide-rss" color="neutral" variant="outline" label="RSS" />
|
|
37
|
+
<UButton to="/blog/atom.xml" external target="_blank" icon="i-lucide-rss" color="neutral" variant="outline" label="Atom" />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<p v-if="!posts?.length" class="text-muted">
|
|
42
|
+
{{ t('blog.empty') }}
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
<UCard v-for="post in posts" :key="post.id">
|
|
46
|
+
<div class="flex flex-wrap items-start justify-between gap-3">
|
|
47
|
+
<div class="min-w-0 space-y-1">
|
|
48
|
+
<ULink :to="`/blog/${post.slug}`" class="text-lg font-semibold text-highlighted">
|
|
49
|
+
{{ post.title }}
|
|
50
|
+
</ULink>
|
|
51
|
+
<p class="text-sm text-muted">
|
|
52
|
+
<span v-if="post.publishedAt">{{ naturalday(post.publishedAt) }}</span>
|
|
53
|
+
<span v-if="post.author"> · {{ post.author.name }}</span>
|
|
54
|
+
<span v-if="post.category"> · {{ post.category.name }}</span>
|
|
55
|
+
</p>
|
|
56
|
+
<p class="text-sm text-toned">
|
|
57
|
+
{{ truncatewords(post.body, 30) }}
|
|
58
|
+
</p>
|
|
59
|
+
</div>
|
|
60
|
+
<UButton
|
|
61
|
+
v-if="loggedIn"
|
|
62
|
+
icon="i-lucide-hash"
|
|
63
|
+
size="sm"
|
|
64
|
+
color="neutral"
|
|
65
|
+
variant="soft"
|
|
66
|
+
:label="t('blog.countWords')"
|
|
67
|
+
:loading="counting === post.id"
|
|
68
|
+
@click="countWords(post.id)"
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</UCard>
|
|
72
|
+
</UContainer>
|
|
73
|
+
</template>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { post } from '../../../server/database/schema'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Route-level opt-out: only this page skips server-side rendering. The rest of /blog stays
|
|
6
|
+
* server-rendered. (Equivalent to `routeRules: { '/blog/stats': { ssr: false } }`.)
|
|
7
|
+
*/
|
|
8
|
+
defineRouteRules({ ssr: false })
|
|
9
|
+
|
|
10
|
+
const { t } = useI18n()
|
|
11
|
+
useHead({ title: () => t('blog.stats.title') })
|
|
12
|
+
|
|
13
|
+
const posts = useResource<typeof post>('posts').list({ perPage: 100, key: 'blog-stats' })
|
|
14
|
+
const words = computed(() => posts.items.value.reduce((sum, p) => sum + String(p.body ?? '').split(/\s+/).filter(Boolean).length, 0))
|
|
15
|
+
// Read from the browser: something the server could not know.
|
|
16
|
+
const readingSpeed = ref(Number(localStorage.getItem('knit:wpm')) || 230)
|
|
17
|
+
watch(readingSpeed, v => localStorage.setItem('knit:wpm', String(v)))
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<UContainer class="space-y-6 py-12">
|
|
22
|
+
<UButton to="/blog" icon="i-lucide-arrow-left" color="neutral" variant="link" :label="t('blog.allPosts')" class="px-0" />
|
|
23
|
+
<h1 class="text-3xl font-bold text-highlighted">
|
|
24
|
+
{{ t('blog.stats.title') }}
|
|
25
|
+
</h1>
|
|
26
|
+
<p class="text-muted" data-testid="stats-summary">
|
|
27
|
+
{{ t('blog.stats.summary', { posts: posts.total.value, words, minutes: Math.max(1, Math.round(words / readingSpeed)) }) }}
|
|
28
|
+
</p>
|
|
29
|
+
<UFormField :label="t('blog.stats.speed')" :help="t('blog.stats.speedHelp')">
|
|
30
|
+
<UInputNumber v-model="readingSpeed" :min="50" :max="1000" :step="10" />
|
|
31
|
+
</UFormField>
|
|
32
|
+
</UContainer>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pnpm manage publishpost <slug> [--unpublish]`: an example per-app management command.
|
|
3
|
+
* Goes through the model service, so validation, `clean()` and signals all apply.
|
|
4
|
+
*/
|
|
5
|
+
import { defineManageCommand } from '@knit-framework/core/commands'
|
|
6
|
+
import { useModel } from '@knit-framework/core/models'
|
|
7
|
+
import { post } from '../server/database/schema'
|
|
8
|
+
|
|
9
|
+
export default defineManageCommand({
|
|
10
|
+
meta: { description: 'Publish (or unpublish) a blog post by slug' },
|
|
11
|
+
args: {
|
|
12
|
+
slug: { type: 'positional', description: 'Slug of the post', required: true },
|
|
13
|
+
unpublish: { type: 'boolean', description: 'Unpublish instead', default: false },
|
|
14
|
+
},
|
|
15
|
+
async run({ args, db }) {
|
|
16
|
+
const posts = useModel(post, { db })
|
|
17
|
+
const target = await posts.get({ slug: args.slug })
|
|
18
|
+
const updated = await posts.update(target.id, args.unpublish
|
|
19
|
+
? { published: false, publishedAt: null }
|
|
20
|
+
: { published: true })
|
|
21
|
+
console.log(`${updated.title}: ${updated.published ? `published (${updated.publishedAt?.toISOString()})` : 'unpublished'}`)
|
|
22
|
+
},
|
|
23
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"knit": {
|
|
3
|
+
"groups": {
|
|
4
|
+
"blog": "Blog"
|
|
5
|
+
},
|
|
6
|
+
"models": {
|
|
7
|
+
"blog_category": {
|
|
8
|
+
"label": "Kategorie",
|
|
9
|
+
"labelPlural": "Kategorien",
|
|
10
|
+
"fields": {
|
|
11
|
+
"name": "Name",
|
|
12
|
+
"slug": "Slug",
|
|
13
|
+
"description": "Beschreibung",
|
|
14
|
+
"createdAt": "Erstellt am"
|
|
15
|
+
},
|
|
16
|
+
"help": {
|
|
17
|
+
"slug": "URL-freundlicher Bezeichner. Wird beim Anlegen aus dem Namen übernommen.",
|
|
18
|
+
"description": "Optional. Wird auf der Kategorieseite angezeigt."
|
|
19
|
+
},
|
|
20
|
+
"inlines": {
|
|
21
|
+
"blog_post": "Beiträge"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"blog_post": {
|
|
25
|
+
"label": "Beitrag",
|
|
26
|
+
"labelPlural": "Beiträge",
|
|
27
|
+
"fields": {
|
|
28
|
+
"title": "Titel",
|
|
29
|
+
"slug": "Slug",
|
|
30
|
+
"body": "Text",
|
|
31
|
+
"cover": "Titelbild",
|
|
32
|
+
"published": "Veröffentlicht",
|
|
33
|
+
"publishedAt": "Veröffentlicht am",
|
|
34
|
+
"categoryId": "Kategorie",
|
|
35
|
+
"authorId": "Autor",
|
|
36
|
+
"createdAt": "Erstellt am",
|
|
37
|
+
"updatedAt": "Aktualisiert am"
|
|
38
|
+
},
|
|
39
|
+
"help": {
|
|
40
|
+
"slug": "Wird in der URL des Beitrags verwendet. Beim Anlegen aus dem Titel übernommen.",
|
|
41
|
+
"blog_post_tag": "Beliebig viele Schlagwörter auswählen.",
|
|
42
|
+
"cover": "PNG, JPEG, WebP oder AVIF; erscheint oben im Beitrag.",
|
|
43
|
+
"published": "Nur veröffentlichte Beiträge erscheinen auf der Website.",
|
|
44
|
+
"publishedAt": "Wird als Datum des Beitrags angezeigt. Leer lassen, um es auszublenden.",
|
|
45
|
+
"authorId": "Benutzer-ID des Autors. Über die Suche nachschlagen."
|
|
46
|
+
},
|
|
47
|
+
"fieldsets": {
|
|
48
|
+
"content": {
|
|
49
|
+
"title": "Inhalt"
|
|
50
|
+
},
|
|
51
|
+
"publishing": {
|
|
52
|
+
"title": "Veröffentlichung",
|
|
53
|
+
"description": "Steuert, wann und wo der Beitrag erscheint."
|
|
54
|
+
},
|
|
55
|
+
"advanced": {
|
|
56
|
+
"title": "Erweitert"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"manyToMany": {
|
|
60
|
+
"blog_post_tag": "Schlagwörter"
|
|
61
|
+
},
|
|
62
|
+
"actions": {
|
|
63
|
+
"publish": {
|
|
64
|
+
"label": "Auswahl veröffentlichen"
|
|
65
|
+
},
|
|
66
|
+
"unpublish": {
|
|
67
|
+
"label": "Veröffentlichung aufheben",
|
|
68
|
+
"confirm": "Die ausgewählten Beiträge von der Website nehmen?"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"blog_tag": {
|
|
73
|
+
"label": "Schlagwort",
|
|
74
|
+
"labelPlural": "Schlagwörter",
|
|
75
|
+
"fields": {
|
|
76
|
+
"name": "Name"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"blog_comment": {
|
|
80
|
+
"label": "Kommentar",
|
|
81
|
+
"labelPlural": "Kommentare",
|
|
82
|
+
"fields": {
|
|
83
|
+
"body": "Text",
|
|
84
|
+
"postId": "Beitrag",
|
|
85
|
+
"authorId": "Autor",
|
|
86
|
+
"approved": "Freigegeben",
|
|
87
|
+
"createdAt": "Erstellt am",
|
|
88
|
+
"updatedAt": "Aktualisiert am"
|
|
89
|
+
},
|
|
90
|
+
"help": {
|
|
91
|
+
"approved": "Nur freigegebene Kommentare sind für Besucher sichtbar.",
|
|
92
|
+
"authorId": "Wird für auf der Website verfasste Kommentare automatisch gesetzt."
|
|
93
|
+
},
|
|
94
|
+
"actions": {
|
|
95
|
+
"approve": {
|
|
96
|
+
"label": "Auswahl freigeben"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"resources": {
|
|
102
|
+
"comments": {
|
|
103
|
+
"fields": {
|
|
104
|
+
"body": "Kommentar"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"blog": {
|
|
110
|
+
"title": "Blog",
|
|
111
|
+
"feed": "Knit-Blog ({format})",
|
|
112
|
+
"empty": "Noch keine veröffentlichten Beiträge. Erstellen Sie einen im Admin.",
|
|
113
|
+
"countWords": "Wörter zählen",
|
|
114
|
+
"allPosts": "Alle Beiträge",
|
|
115
|
+
"notFound": "Beitrag nicht gefunden",
|
|
116
|
+
"post": "Beitrag",
|
|
117
|
+
"comments": "Kommentare",
|
|
118
|
+
"noComments": "Noch keine Kommentare.",
|
|
119
|
+
"leaveComment": "Kommentar schreiben",
|
|
120
|
+
"placeholder": "Teilen Sie Ihre Gedanken…",
|
|
121
|
+
"submit": "Kommentar senden",
|
|
122
|
+
"signInPrompt": "Melden Sie sich an, um mitzudiskutieren.",
|
|
123
|
+
"signIn": "Anmelden",
|
|
124
|
+
"pending": "Wartet auf Freigabe",
|
|
125
|
+
"edit": "Bearbeiten",
|
|
126
|
+
"delete": "Löschen",
|
|
127
|
+
"thanks": "Danke für Ihren Kommentar",
|
|
128
|
+
"thanksDescription": "Er ist für alle sichtbar, sobald ihn ein Moderator freigibt.",
|
|
129
|
+
"updated": "Kommentar aktualisiert",
|
|
130
|
+
"deleted": "Kommentar gelöscht",
|
|
131
|
+
"deleteFailed": "Der Kommentar konnte nicht gelöscht werden",
|
|
132
|
+
"stats": {
|
|
133
|
+
"title": "Lesestatistik",
|
|
134
|
+
"summary": "{posts} Beiträge · {words} Wörter · etwa {minutes} Min. Lesezeit für alle",
|
|
135
|
+
"speed": "Ihre Lesegeschwindigkeit (Wörter pro Minute)",
|
|
136
|
+
"speedHelp": "Wird in diesem Browser gespeichert."
|
|
137
|
+
},
|
|
138
|
+
"live": "Live"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"blog": {
|
|
3
|
+
"title": "Blog",
|
|
4
|
+
"feed": "Knit blog ({format})",
|
|
5
|
+
"empty": "No published posts yet. Create one in the admin.",
|
|
6
|
+
"countWords": "Count words",
|
|
7
|
+
"allPosts": "All posts",
|
|
8
|
+
"notFound": "Post not found",
|
|
9
|
+
"post": "Post",
|
|
10
|
+
"comments": "Comments",
|
|
11
|
+
"noComments": "No comments yet.",
|
|
12
|
+
"leaveComment": "Leave a comment",
|
|
13
|
+
"placeholder": "Share your thoughts…",
|
|
14
|
+
"submit": "Post comment",
|
|
15
|
+
"signInPrompt": "Sign in to join the conversation.",
|
|
16
|
+
"signIn": "Sign in",
|
|
17
|
+
"pending": "Awaiting moderation",
|
|
18
|
+
"edit": "Edit",
|
|
19
|
+
"delete": "Delete",
|
|
20
|
+
"thanks": "Thanks for your comment",
|
|
21
|
+
"thanksDescription": "It will appear for everyone once a moderator approves it.",
|
|
22
|
+
"updated": "Comment updated",
|
|
23
|
+
"deleted": "Comment deleted",
|
|
24
|
+
"deleteFailed": "Could not delete the comment",
|
|
25
|
+
"stats": {
|
|
26
|
+
"title": "Reading stats",
|
|
27
|
+
"summary": "{posts} posts · {words} words · about {minutes} min to read them all",
|
|
28
|
+
"speed": "Your reading speed (words per minute)",
|
|
29
|
+
"speedHelp": "Saved in this browser."
|
|
30
|
+
},
|
|
31
|
+
"live": "Live"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"knit": {
|
|
3
|
+
"groups": {
|
|
4
|
+
"blog": "Blog"
|
|
5
|
+
},
|
|
6
|
+
"models": {
|
|
7
|
+
"blog_category": {
|
|
8
|
+
"label": "Categoría",
|
|
9
|
+
"labelPlural": "Categorías",
|
|
10
|
+
"fields": {
|
|
11
|
+
"name": "Nombre",
|
|
12
|
+
"slug": "Slug",
|
|
13
|
+
"description": "Descripción",
|
|
14
|
+
"createdAt": "Creada el"
|
|
15
|
+
},
|
|
16
|
+
"help": {
|
|
17
|
+
"slug": "Identificador apto para URL. Se rellena a partir del nombre al crearla.",
|
|
18
|
+
"description": "Opcional. Se muestra en la página de la categoría."
|
|
19
|
+
},
|
|
20
|
+
"inlines": {
|
|
21
|
+
"blog_post": "Publicaciones"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"blog_post": {
|
|
25
|
+
"label": "Publicación",
|
|
26
|
+
"labelPlural": "Publicaciones",
|
|
27
|
+
"fields": {
|
|
28
|
+
"title": "Título",
|
|
29
|
+
"slug": "Slug",
|
|
30
|
+
"body": "Texto",
|
|
31
|
+
"cover": "Portada",
|
|
32
|
+
"published": "Publicada",
|
|
33
|
+
"publishedAt": "Publicada el",
|
|
34
|
+
"categoryId": "Categoría",
|
|
35
|
+
"authorId": "Autor",
|
|
36
|
+
"createdAt": "Creada el",
|
|
37
|
+
"updatedAt": "Actualizada el"
|
|
38
|
+
},
|
|
39
|
+
"help": {
|
|
40
|
+
"slug": "Se usa en la URL de la publicación. Se rellena a partir del título al crearla.",
|
|
41
|
+
"blog_post_tag": "Elige tantas etiquetas como quieras.",
|
|
42
|
+
"cover": "PNG, JPEG, WebP o AVIF; se muestra al principio de la publicación.",
|
|
43
|
+
"published": "Solo las publicaciones publicadas aparecen en el sitio.",
|
|
44
|
+
"publishedAt": "Se muestra como fecha de la publicación. Déjalo vacío para ocultarla.",
|
|
45
|
+
"authorId": "ID de usuario del autor. Usa la búsqueda para encontrarlo."
|
|
46
|
+
},
|
|
47
|
+
"fieldsets": {
|
|
48
|
+
"content": {
|
|
49
|
+
"title": "Contenido"
|
|
50
|
+
},
|
|
51
|
+
"publishing": {
|
|
52
|
+
"title": "Publicación",
|
|
53
|
+
"description": "Controla cuándo y dónde aparece la publicación."
|
|
54
|
+
},
|
|
55
|
+
"advanced": {
|
|
56
|
+
"title": "Avanzado"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"manyToMany": {
|
|
60
|
+
"blog_post_tag": "Etiquetas"
|
|
61
|
+
},
|
|
62
|
+
"actions": {
|
|
63
|
+
"publish": {
|
|
64
|
+
"label": "Publicar selección"
|
|
65
|
+
},
|
|
66
|
+
"unpublish": {
|
|
67
|
+
"label": "Despublicar selección",
|
|
68
|
+
"confirm": "¿Retirar del sitio las publicaciones seleccionadas?"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"blog_tag": {
|
|
73
|
+
"label": "Etiqueta",
|
|
74
|
+
"labelPlural": "Etiquetas",
|
|
75
|
+
"fields": {
|
|
76
|
+
"name": "Nombre"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"blog_comment": {
|
|
80
|
+
"label": "Comentario",
|
|
81
|
+
"labelPlural": "Comentarios",
|
|
82
|
+
"fields": {
|
|
83
|
+
"body": "Texto",
|
|
84
|
+
"postId": "Publicación",
|
|
85
|
+
"authorId": "Autor",
|
|
86
|
+
"approved": "Aprobado",
|
|
87
|
+
"createdAt": "Creado el",
|
|
88
|
+
"updatedAt": "Actualizado el"
|
|
89
|
+
},
|
|
90
|
+
"help": {
|
|
91
|
+
"approved": "Solo los comentarios aprobados son visibles para los visitantes.",
|
|
92
|
+
"authorId": "Se asigna automáticamente a los comentarios publicados en el sitio."
|
|
93
|
+
},
|
|
94
|
+
"actions": {
|
|
95
|
+
"approve": {
|
|
96
|
+
"label": "Aprobar selección"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"resources": {
|
|
102
|
+
"comments": {
|
|
103
|
+
"fields": {
|
|
104
|
+
"body": "Comentario"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"blog": {
|
|
110
|
+
"title": "Blog",
|
|
111
|
+
"feed": "Blog de Knit ({format})",
|
|
112
|
+
"empty": "Aún no hay publicaciones. Crea una en el admin.",
|
|
113
|
+
"countWords": "Contar palabras",
|
|
114
|
+
"allPosts": "Todas las publicaciones",
|
|
115
|
+
"notFound": "Publicación no encontrada",
|
|
116
|
+
"post": "Publicación",
|
|
117
|
+
"comments": "Comentarios",
|
|
118
|
+
"noComments": "Aún no hay comentarios.",
|
|
119
|
+
"leaveComment": "Deja un comentario",
|
|
120
|
+
"placeholder": "Comparte tu opinión…",
|
|
121
|
+
"submit": "Publicar comentario",
|
|
122
|
+
"signInPrompt": "Inicia sesión para unirte a la conversación.",
|
|
123
|
+
"signIn": "Iniciar sesión",
|
|
124
|
+
"pending": "Pendiente de moderación",
|
|
125
|
+
"edit": "Editar",
|
|
126
|
+
"delete": "Eliminar",
|
|
127
|
+
"thanks": "Gracias por tu comentario",
|
|
128
|
+
"thanksDescription": "Será visible para todos cuando un moderador lo apruebe.",
|
|
129
|
+
"updated": "Comentario actualizado",
|
|
130
|
+
"deleted": "Comentario eliminado",
|
|
131
|
+
"deleteFailed": "No se pudo eliminar el comentario",
|
|
132
|
+
"stats": {
|
|
133
|
+
"title": "Estadísticas de lectura",
|
|
134
|
+
"summary": "{posts} publicaciones · {words} palabras · unos {minutes} min para leerlas todas",
|
|
135
|
+
"speed": "Tu velocidad de lectura (palabras por minuto)",
|
|
136
|
+
"speedHelp": "Se guarda en este navegador."
|
|
137
|
+
},
|
|
138
|
+
"live": "En vivo"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-blog",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./nuxt.config.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@knit-framework/core": "workspace:*",
|
|
9
|
+
"drizzle-orm": "^0.45.4"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"postinstall": "nuxt prepare"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"nuxt": "^4.7.0",
|
|
16
|
+
"vitest": "^5.1.2"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { and, eq } from 'drizzle-orm'
|
|
2
|
+
|
|
3
|
+
/** One published post by slug. */
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const slug = getRouterParam(event, 'slug') ?? ''
|
|
6
|
+
const found = await useDB().query.post.findFirst({
|
|
7
|
+
where: and(eq(tables.post.slug, slug), eq(tables.post.published, true)),
|
|
8
|
+
with: {
|
|
9
|
+
category: { columns: { id: true, name: true, slug: true } },
|
|
10
|
+
author: { columns: { id: true, name: true } },
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
if (!found) throw createError({ statusCode: 404, statusMessage: 'Post not found' })
|
|
14
|
+
return found
|
|
15
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { desc, eq } from 'drizzle-orm'
|
|
2
|
+
|
|
3
|
+
/** Published posts with category + author, via the merged, typed schema. */
|
|
4
|
+
export default defineEventHandler(async () => {
|
|
5
|
+
const db = useDB()
|
|
6
|
+
return db.query.post.findMany({
|
|
7
|
+
where: eq(tables.post.published, true),
|
|
8
|
+
orderBy: desc(tables.post.publishedAt),
|
|
9
|
+
with: {
|
|
10
|
+
category: { columns: { id: true, name: true, slug: true } },
|
|
11
|
+
author: { columns: { id: true, name: true } },
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
})
|