Last active
November 5, 2018 10:28
-
-
Save Oldenborg/ac3a353a2a009cd92aaf2d6c770a952c to your computer and use it in GitHub Desktop.
NetliftyCMS prerender folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
... | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
product: Object | |
} | |
}, | |
created() { | |
try { | |
this.product = require(`@/../content/products/${this.$route.params.slug}.json`); | |
} catch (e) { | |
console.log('Product missing'); // TODO redirect to 404 | |
} | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import Router from 'vue-router' | |
import index from './views/index.vue' | |
import products from './views/products' | |
Vue.use(Router) | |
export default new Router({ | |
mode: 'history', | |
base: process.env.BASE_URL, | |
scrollBehavior: () => ({ y: 0 }), | |
routes: [ | |
{ | |
path: '/', | |
name: 'index', | |
component: index | |
}, | |
{ | |
path: '/products/:slug', | |
name: 'products', | |
component: products | |
}, | |
] | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const PrerenderSPAPlugin = require('prerender-spa-plugin') | |
const fg = require('fast-glob'); | |
/** | |
* Glob is a library to get filenames in a folder. | |
* To prerender all bike pages, all files in content/products/ | |
* are inserted. | |
* | |
* The product names are mapped because glob returns a full path | |
* but rerenderer plugin requires url. | |
* maps content/products/bike-name.json => /product/bike-name | |
*/ | |
const pathEntries = fg.sync('./content/products/*.*') | |
.map(entry => `/products/${entry.split('/').pop().replace('.json', '')}`); | |
module.exports = { | |
devServer: { | |
port: 3000 | |
}, | |
configureWebpack: { | |
plugins: [ | |
new PrerenderSPAPlugin({ | |
staticDir: path.join(__dirname, 'dist'), | |
routes: [ | |
'/', | |
'/search', | |
'/katalog' | |
].concat(pathEntries) | |
}) | |
] | |
}, | |
chainWebpack: config => { | |
config | |
.plugin('copy') | |
.use(require('copy-webpack-plugin'), [[{ | |
from: 'public', | |
ignore: ['./index.html', '.DS_Store'] | |
}]]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment