Skip to content

Instantly share code, notes, and snippets.

@yokoishioka
Created May 6, 2023 06:16
Show Gist options
  • Save yokoishioka/598d0bc2df0814e217062cd4128bc768 to your computer and use it in GitHub Desktop.
Save yokoishioka/598d0bc2df0814e217062cd4128bc768 to your computer and use it in GitHub Desktop.
How to write dynamic routes to a file for pre-rendering
const fs = require('fs');
const axios = require('axios');
const endOfLine = require('os').EOL;
const domain = `https://cloudengineering.studio`;
const routesOutputFile = 'example-file-name.txt';
const routes = [];
getArticles();
function getArticles() {
axios.get(articlesApi).then(res => {
res.data.items.forEach(item => {
routes.push(`/articles/${item.fields.slug}`);
});
writeRoutes();
})
.catch(e => console.log(e));
}
function writeRoutes() {
fs.writeFileSync(routesOutputFile, routes.join(endOfLine), 'utf8');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment