-
Notifications
You must be signed in to change notification settings - Fork 1
/
prerender-routes.ts
48 lines (36 loc) · 1.47 KB
/
prerender-routes.ts
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
require('dotenv').config();
const fs = require('fs');
const agilityFetch = require('@agility/content-fetch');
const path = require('path');
// const { environment } = require('./src/environments/environment.ts');
// Initialize the Agility API client
const agilityClient = agilityFetch.getApi({
guid: process.env['AGILITY_GUID'],
apiKey: process.env['AGILITY_API_FETCH_KEY'],
isPreview: false, // Set to true if you want to fetch preview content
});
async function fetchRoutes() {
try {
// Fetch the flat sitemap
const data = await agilityClient.getSitemapFlat({
languageCode: process.env['AGILITY_LOCALE'],
channelName: process.env['AGILITY_SITEMAP'],
});
console.log("Fetched routes:", data);
// Extract paths from the sitemap keys
const routes = Object.keys(data);
// Define the path for the output .txt file
const outputPath = 'src/app/agility/routing/agility-routes.txt';
// Ensure the directory exists
const directoryPath = path.dirname(outputPath);
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath, { recursive: true });
}
// Write the routes to the .txt file
fs.writeFileSync(outputPath, routes.join('\n'), 'utf-8');
console.log(`Prerender routes written successfully to ${outputPath}!`);
} catch (error) {
console.error("Error fetching routes:", error);
}
}
fetchRoutes();