Created
October 12, 2019 22:52
-
-
Save cvega93/5d6661082249809d09600e84d2e35194 to your computer and use it in GitHub Desktop.
Links generator for @nuxtjs/sitemap
This file contains 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
env_file = process.env.NODE_ENV ? process.env.NODE_ENV: 'local'; | |
const env = require('./enviroments/'+env_file); | |
const axios = require('axios'); | |
var routes; | |
let generatePlaces = async function () { | |
// Rutas a generar | |
let paths = [ | |
':slug', | |
'centros/:slug', | |
'centros/:slug/comentarios' | |
]; | |
// Api donde están todos los Slugs | |
let target = env.config.SERVER.BASE_URL + 'places/markers?limit=100'; | |
let requestSlugs = axios.get(target) | |
.then((res) => res.data.results.map((place) => place.slug)); | |
let slugs = await requestSlugs; | |
console.log(slugs); | |
return generateRoutes(paths, slugs); | |
}; | |
function generateRoutes(paths, slugs) { | |
let result = []; | |
paths.forEach(function (path) { | |
slugs.forEach(function (slug) { | |
let link = { | |
url: path.replace(/:\w+/, slug), | |
changefreq: 'weekly', | |
priority: 1 | |
}; | |
result.push(link) | |
}) | |
}); | |
return result | |
} | |
routes = async function () { | |
let places = await generatePlaces(); | |
return places | |
}; | |
module.exports = routes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment