@palmbeach/nuxt-content-routes
v1.0.9
Published
Automatically generate routes from your Nuxt Content files and directories. Respects i18n prefix strategy.
Downloads
9
Readme
Nuxt Content Routes
A small add-on for Nuxt Content that generates static routes for markdown files.
Routes are generated during the build process from the Nuxt Content directory when the documentDriven
option cannot be utilized. This is particularly useful in scenarios where Nuxt Content and static pages are combined, or when a specific i18n strategy is required.
Zero impact on runtime performance.
Please note that this add-on might become obsolete with upcoming Nuxt Content releases.
//Only executed on build via nuxt build
const paths = await listFilesInDirectory(
directory,
prefix,
i18nDefaultLocale,
i18nStrategy,
)
nuxt.hook('nitro:config', (nitroConfig) => {
if (nitroConfig && nitroConfig.prerender) {
nitroConfig.prerender.routes = nitroConfig.prerender.routes || []
nitroConfig.prerender.routes.push(...paths)
}
})
Features
- Generates all routes for Nuxt Content markdown files in content directory
- Supports i18n strategy 'prefix' and 'prefix_except_default'
- Generate clean path names (no order prefixes, no file extensions, no capital letters)
Todo
Quick Setup
- Add
@palmbeach/nuxt-content-routes
dependency to your project
# Using pnpm
pnpm add -D @palmbeach/nuxt-content-routes
# Using yarn
yarn add --dev @palmbeach/nuxt-content-routes
# Using npm
npm install --save-dev @palmbeach/nuxt-content-routes
- Add
nuxt-content-routes
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'@palmbeach/nuxt-content-routes'
]
})
Contributing
Playground / Example
#content directory structure in playground
content/
├─ de/
│ ├─ 1.foo/
│ │ ├─ 1.bar.md
│ │ ├─ index.md
│ ├─ 2.bar/
│ │ ├─ 1.foo.md
│ │ ├─ index.md
│ ├─ index.md
├─ en/
│ ├─ 1.foo/
│ │ ├─ 1.bar.md
│ │ ├─ index.md
│ ├─ 2.bar/
│ │ ├─ 1.foo.md
│ │ ├─ index.md
│ ├─ index.md
├─ index.md
#routes: nuxt.config.ts > i18n > strategy = 'prefix'
├─ /de
├─ /en
├─ /
├─ /en/foo/bar
├─ /de/foo/bar
├─ /en/bar/foo
├─ /de/bar/foo
├─ /de/bar
├─ /de/foo
├─ /en/foo
├─ /en/bar
#routes: nuxt.config.ts > i18n > strategy = 'prefix_except_default'
├─ /de
├─ /bar
├─ /
├─ /foo
├─ /de/foo/bar
├─ /de/bar/foo
├─ /bar/foo
├─ /foo/bar
├─ /de/foo
├─ /de/bar
Development
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release