{{ post.title }}
@@ -207,21 +215,20 @@ export default {
},
};
-````
+```
### Generating pages with the `generate` property
-
Since Nuxt 2.13+, nuxt export has a crawler feature integrated which will crawl all your links and generate your routes based on those links. Therefore you do not need to do anything in order for your dynamic routes to be crawled. i.e, if you are on version of nuxt above 2.14 add target as static in nuxt.config.js and use `nuxt generate` to build your static site.
-
```javascript
// nuxt.config.js
target: 'static'
```
+
If you are using nuxt version below 2.14 you have to use generate option in nuxt/content module to generate pages
-````javascript
+```javascript
//nux.config.js
export default {
modules: [,
@@ -236,21 +243,20 @@ export default {
}
}
}
-````
-
+```
To render your site as a static site, you'll need to create or update the `generate` property in `nuxt.config.js` to create dynamic routes and provide their content as a `payload`. In `generate`, make your `routes` entry a function:
-```js
+```javascript
export default {
generate: {
routes: function() {
const fs = require('fs');
const path = require('path');
- return fs.readdirSync('./assets/content/blog').map(file => {
+ return fs.readdirSync('./content/blog').map(file => {
return {
route: `/blog/${path.parse(file).name}`, // Return the slug
- payload: require(`./assets/content/blog/${file}`),
+ payload: require(`./content/blog/${file}`),
};
});
},
@@ -258,4 +264,4 @@ export default {
};
```
-To see the generated site, navigate to name-of-your-website.netlify.app/blog
+To see the generated site, navigate to name-of-your-website.netlify.app/blog
\ No newline at end of file