feat: scaffold Journal layer with configurable post route and git-install check
- journal module registers the Journal pages at journal.routes paths - typed anonymous-GET client, html gate, SSR x-forwarded-for forwarding - fixture API, built-server SSR smoke and git-tag install check
This commit is contained in:
58
lib/journal-module.ts
Normal file
58
lib/journal-module.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// The layer's local Nuxt module (configKey `journal`). It registers the
|
||||
// Journal page components at the paths in journal.routes, so an app moves or
|
||||
// disables a view in its own nuxt.config without copying page files. It lives
|
||||
// in lib/ rather than modules/ so Nuxt's local-module scan cannot register it
|
||||
// a second time. Layer source never uses the ~ or @ aliases: they resolve to
|
||||
// the consuming project.
|
||||
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { defineNuxtModule, extendPages } from 'nuxt/kit'
|
||||
import { DEFAULT_JOURNAL_ROUTES, JOURNAL_ROUTE_NAMES, normalizeJournalRoutes } from '../app/utils/routes.ts'
|
||||
import type { JournalModuleOptions, JournalRoutes } from '../app/utils/types.ts'
|
||||
|
||||
const PAGE_FILES: Record<keyof JournalRoutes, string> = {
|
||||
index: 'PostIndexPage',
|
||||
post: 'PostPage',
|
||||
category: 'CategoryPage',
|
||||
tag: 'TagPage',
|
||||
author: 'AuthorPage',
|
||||
}
|
||||
|
||||
const pagesDir = fileURLToPath(new URL('../app/journal-pages/', import.meta.url))
|
||||
|
||||
export default defineNuxtModule<JournalModuleOptions>({
|
||||
meta: {
|
||||
name: 'vue-journal-layer',
|
||||
configKey: 'journal',
|
||||
},
|
||||
defaults: {
|
||||
routes: { ...DEFAULT_JOURNAL_ROUTES },
|
||||
perPage: { index: 9, category: 9, tag: 9, author: 9 },
|
||||
sort: 'published_at desc',
|
||||
relatedCount: 3,
|
||||
rss: true,
|
||||
},
|
||||
setup(options, nuxt) {
|
||||
const routes = normalizeJournalRoutes(options.routes as unknown as Record<string, unknown>)
|
||||
|
||||
extendPages((pages) => {
|
||||
for (const key of Object.keys(PAGE_FILES) as Array<keyof JournalRoutes>) {
|
||||
const path = routes[key]
|
||||
if (path === false) continue
|
||||
pages.push({ name: JOURNAL_ROUTE_NAMES[key], path, file: `${pagesDir}${PAGE_FILES[key]}.vue` })
|
||||
}
|
||||
})
|
||||
|
||||
// The public runtime config carries the resolved options next to apiBase,
|
||||
// so pages, links and the sitemap source read one source of truth.
|
||||
const pub = nuxt.options.runtimeConfig.public as Record<string, any>
|
||||
pub.journal = {
|
||||
...(pub.journal ?? {}),
|
||||
routes,
|
||||
perPage: { ...options.perPage },
|
||||
sort: options.sort,
|
||||
relatedCount: options.relatedCount,
|
||||
rss: options.rss,
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user