-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroutesHelper.js
50 lines (45 loc) · 1.79 KB
/
routesHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const axios = require('axios')
const fs = require('fs')
const locales = ['fr', 'en']
const excludedRoutes = [
'dashboard/', 'checkout', 'terms-of-sale', 'terms', 'legals', 'privacy', 'credits', 'login', 'test'
]
module.exports.getRoutes = async function getAppRoutes(getExcluded = false) {
let routes = []
for (locale of locales) {
// generate documentation routes from localized docs config
let docConfigPath = __dirname + '/assets/content/' + locale + '/documentation.json'
let docsTree = fs.readFileSync(docConfigPath)
docsTree = JSON.parse(docsTree).tree
for (docPage of docsTree)
if ((docPage.allow_indexing && !getExcluded) || (!docPage.allow_indexing && getExcluded))
routes.push('/' + locale + '/docs/' + docPage.slug)
// generate shop routes from api
let res = await axios.get(process.env.API_ENDPOINT + '/shop/' + locale + '/categories')
let categories = res.data.data.categories
// only map the important shop items, ignore the rest of them
for (categorie of categories)
for (item of categorie.items)
if ((item.allow_indexing && !getExcluded) || (!item.allow_indexing && getExcluded))
routes.push('/' + locale + '/shop/' + item.slug)
}
return routes
}
module.exports.getExcludedRoutes = async function getExcludedRoutes() {
let excludedPaths = []
excludedRoutes.forEach(route => {
locales.forEach(locale => {
excludedPaths.push('/' + locale + '/' + route)
})
})
excludedPaths = [...await module.exports.getRoutes(true), ...excludedPaths]
return excludedPaths
}
module.exports.filterRoutes = function filterRoutes(routes) {
return routes.filter(route => {
for (let i = 0; i < excludedRoutes.length; i++)
if (route.url.indexOf(excludedRoutes[i]) > -1)
return false
return true
})
}