@palmbeach/nuxt-content-routes
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Nuxt Content Routes

npm version License Nuxt

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

  1. 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
  1. Add nuxt-content-routes to the modules section of nuxt.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

Readme

Keywords

none

Package Sidebar

Install

npm i @palmbeach/nuxt-content-routes

Weekly Downloads

3

Version

1.0.9

License

MIT

Unpacked Size

9.96 kB

Total Files

10

Last publish

Collaborators

  • metaforx