-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a solution to using the Angular Router to avoid client side requests
- Loading branch information
1 parent
aa6c5f3
commit 628d849
Showing
12 changed files
with
250 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { getApi } from '@agility/content-fetch'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
|
||
const client = getApi({ | ||
guid: process.env['AGILITY_GUID'], | ||
apiKey: process.env['AGILITY_API_FETCH_KEY'], | ||
isPreview: Boolean(process.env['AGILITY_PREVIEW']), | ||
}); | ||
|
||
const contentListsToPreRender = ['posts', 'categories']; | ||
|
||
async function prerenderPages() { | ||
|
||
let allContentListsData: { [key: string]: any } = {}; | ||
|
||
for(const contentList of contentListsToPreRender) { | ||
|
||
// Fetch the content list | ||
const list = await client.getContentList({ | ||
referenceName: contentList, | ||
languageCode: process.env['AGILITY_LOCALE'], | ||
locale: process.env['AGILITY_LOCALE'], | ||
}); | ||
|
||
// Add the list to the allContentListsData object | ||
allContentListsData[contentList] = list; | ||
|
||
console.log(`Fetched content list: ${contentList}`); | ||
} | ||
|
||
// Define the JSON output path for the aggregated data | ||
const aggregatedJsonOutputPath = path.join(__dirname, 'src', 'app', 'agility', 'data', 'content.json'); | ||
|
||
// Ensure the directory exists | ||
fs.mkdirSync(path.dirname(aggregatedJsonOutputPath), { recursive: true }); | ||
|
||
// Write the aggregated data to the JSON file | ||
fs.writeFileSync(aggregatedJsonOutputPath, JSON.stringify(allContentListsData, null, 2), 'utf8'); | ||
|
||
|
||
} | ||
|
||
prerenderPages(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { getApi } from '@agility/content-fetch'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const apiKey = process.env['AGILITY_API_FETCH_KEY']; | ||
const guid = process.env['AGILITY_GUID']; | ||
const locale = process.env['AGILITY_LOCALE'] || 'en-use'; | ||
const channel = process.env['AGILITY_WEBSITE'] || 'website'; | ||
|
||
const client = getApi({ | ||
guid, | ||
apiKey, | ||
isPreview: false | ||
}); | ||
|
||
async function prerenderPages() { | ||
// Fetch the sitemap | ||
const sitemap = await client.getSitemapFlat({ languageCode: locale, channelName: channel, locale }); | ||
|
||
// Object to hold all page data | ||
let allPageData: { [key: string]: { page: any, dynamicPageItem: any } } = {}; | ||
|
||
for (const pagePath in sitemap) { | ||
if (sitemap.hasOwnProperty(pagePath)) { | ||
const pageInSitemap = sitemap[pagePath]; | ||
|
||
// Fetch the page content | ||
const pageContent = await client.getPageByPath({ | ||
pagePath, | ||
channelName: channel, | ||
locale | ||
}); | ||
|
||
// Fetch the dynamic page item | ||
let dynamicPageItem = null; | ||
if(pageInSitemap.contentID) { | ||
dynamicPageItem = await client.getContentItem({ | ||
contentID: pageInSitemap.contentID, | ||
locale | ||
}); | ||
} | ||
// Add the page content to the allPageData object | ||
allPageData[pagePath] = { | ||
page: pageContent.page, | ||
dynamicPageItem: dynamicPageItem | ||
}; | ||
} | ||
} | ||
|
||
// Define the JSON output path for the aggregated data | ||
const jsonOutputPath = path.join(__dirname, 'src', 'app', 'agility', 'data', 'pages.json'); | ||
|
||
// Ensure the directory exists | ||
fs.mkdirSync(path.dirname(jsonOutputPath), { recursive: true }); | ||
|
||
// Write the aggregated data to the JSON file | ||
fs.writeFileSync(jsonOutputPath, JSON.stringify(allPageData, null, 2), 'utf8'); | ||
} | ||
|
||
prerenderPages(); |
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
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
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
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
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
Oops, something went wrong.