1.0.9 • Published 2 months ago

@palmbeach/nuxt-content-routes v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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
1.0.9

2 months ago

1.0.8

8 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago