feat: Journal list, category pages, pagination, tokens and pl/en strings
- index and category pages paginate with ?page=N and 404 out of range - category content renders above the list through the html gate - related posts fall back to the latest posts - --journal-* tokens and neutral base styles - pl/en strings registered only for locales the app enables
This commit is contained in:
@@ -19,6 +19,18 @@ const PAGE_FILES: Record<keyof JournalRoutes, string> = {
|
||||
}
|
||||
|
||||
const pagesDir = fileURLToPath(new URL('../app/journal-pages/', import.meta.url))
|
||||
const langDir = fileURLToPath(new URL('../i18n/locales/', import.meta.url))
|
||||
|
||||
/** UI string locales the layer ships, each in i18n/locales/<code>.json. */
|
||||
const LAYER_LOCALES = ['pl', 'en'] as const
|
||||
|
||||
/** Locale codes the project enables in its i18n config (strings or objects). */
|
||||
function enabledLocaleCodes(locales: unknown): string[] {
|
||||
if (!Array.isArray(locales)) return []
|
||||
return locales
|
||||
.map((l) => (typeof l === 'string' ? l : l && typeof l === 'object' ? (l as { code?: unknown }).code : undefined))
|
||||
.filter((c): c is string => typeof c === 'string')
|
||||
}
|
||||
|
||||
export default defineNuxtModule<JournalModuleOptions>({
|
||||
meta: {
|
||||
@@ -43,6 +55,20 @@ export default defineNuxtModule<JournalModuleOptions>({
|
||||
}
|
||||
})
|
||||
|
||||
// Register the layer's strings only for locales the app enables. The
|
||||
// layer config declares no locales: @nuxtjs/i18n merges every locale a
|
||||
// layer declares into the app, which would add /en routes to an app that
|
||||
// enables only pl.
|
||||
const hook = nuxt.hook as unknown as (
|
||||
name: 'i18n:registerModule',
|
||||
fn: (register: (config: { langDir: string; locales: Array<{ code: string; file: string }> }) => void) => void,
|
||||
) => void
|
||||
hook('i18n:registerModule', (register) => {
|
||||
const enabled = enabledLocaleCodes((nuxt.options as { i18n?: { locales?: unknown } }).i18n?.locales)
|
||||
const locales = LAYER_LOCALES.filter((code) => enabled.includes(code)).map((code) => ({ code, file: `${code}.json` }))
|
||||
if (locales.length > 0) register({ langDir, locales })
|
||||
})
|
||||
|
||||
// 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>
|
||||
|
||||
Reference in New Issue
Block a user