1 | const { join } = require('path')
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | exports.interceptRoutes = function (routes, content, options) {
|
8 |
|
9 | const contentRoutePaths = {}
|
10 | options.dirs.forEach(registeredType => {
|
11 | const dirOpts = registeredType[1]
|
12 | const routeName = dirOpts.routeName || options.routeName
|
13 | if (routeName === '') return
|
14 | const path = join('/' + dirOpts.permalink || options.permalink)
|
15 | contentRoutePaths[routeName] = path
|
16 | })
|
17 |
|
18 |
|
19 | routes.forEach(route => {
|
20 | if (contentRoutePaths[route.name]) {
|
21 | route.path = contentRoutePaths[route.name]
|
22 | }
|
23 | })
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | exports.getRoutes = function (content) {
|
30 | const contentRoutes = []
|
31 | Object.keys(content).forEach(registeredDir => {
|
32 | content[registeredDir].forEach(page => {
|
33 | contentRoutes.push(page.data.permalink)
|
34 | })
|
35 | })
|
36 | return contentRoutes
|
37 | }
|