Skip to content

Commit b6b5828

Browse files
committed
Group URLs by version and use a separate browser for each version
This prevents the store from having all versions of data
1 parent b181c98 commit b6b5828

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

prember-urls.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ const singularData = {
1515
module.exports = function () {
1616
const projects = readdirSync('ember-api-docs-data/json-docs');
1717

18-
const urls = [];
18+
const urlsByVersion = new Map();
19+
20+
const addUrlToVersion = (versionKey, url) => {
21+
if (!urlsByVersion.has(versionKey)) {
22+
urlsByVersion.set(versionKey, []);
23+
}
24+
urlsByVersion.get(versionKey).push(url);
25+
};
1926

2027
projects.forEach((p) => {
2128
// add release index for each of the projects
22-
urls.push(`/${p}/release`);
29+
addUrlToVersion(`${p}/release`, `/${p}/release`);
2330

2431
const fullProjectVersions = readdirSync(
2532
`ember-api-docs-data/json-docs/${p}`,
@@ -44,9 +51,9 @@ module.exports = function () {
4451
const addUrl = (p, uniqVersion, suffix) => {
4552
// If it's the latest release version, also create release URLs
4653
if (projectVersions[projectVersions.length - 1] === uniqVersion) {
47-
urls.push(`/${p}/release/${suffix}`);
54+
addUrlToVersion(`${p}/release`, `/${p}/release/${suffix}`);
4855
}
49-
urls.push(`/${p}/${uniqVersion}/${suffix}`);
56+
addUrlToVersion(`${p}/${uniqVersion}`, `/${p}/${uniqVersion}/${suffix}`);
5057
};
5158

5259
const oldVersions = ['1.13', '2.18', '3.28', '4.12', '5.12'];
@@ -68,7 +75,7 @@ module.exports = function () {
6875
return;
6976
}
7077

71-
urls.push(`/${p}/${uniqVersion}`);
78+
addUrlToVersion(`${p}/${uniqVersion}`, `/${p}/${uniqVersion}`);
7279

7380
const sortedPatchVersions = fullProjectVersions
7481
.filter((projectVersion) => {
@@ -144,7 +151,7 @@ module.exports = function () {
144151
});
145152
});
146153

147-
return urls;
154+
return urlsByVersion;
148155
};
149156

150157
// this is useful to debug why a url isn't being prembered

prerender.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ const getPremberUrls = require('./prember-urls');
66
const BASE_URL = 'http://127.0.0.1:8080';
77
const PRERENDER_DIR = 'prerender';
88

9-
async function prerender() {
10-
const urls = getPremberUrls();
11-
console.log(`Prerendering ${urls.length} URLs...`);
12-
9+
async function prerenderVersion(urls) {
1310
const browser = await chromium.launch();
1411
const page = await browser.newPage();
1512

@@ -46,8 +43,6 @@ async function prerender() {
4643

4744
// Check if we got a 404 by looking for common error indicators
4845
const is404 = await page.evaluate(() => {
49-
// Check for "Not Found" text or 404 status indicator
50-
const bodyText = document.body.innerText;
5146
return document.title.includes('Page Not Found');
5247
});
5348

@@ -83,11 +78,22 @@ async function prerender() {
8378
}
8479

8580
await browser.close();
81+
}
82+
async function prerender() {
83+
const urlsByVersion = getPremberUrls();
84+
const totalUrls = Array.from(urlsByVersion.values()).reduce(
85+
(sum, urls) => sum + urls.length,
86+
0,
87+
);
88+
89+
console.log(`Prerendering ${totalUrls} URLs...`);
90+
91+
for (const [version, urls] of urlsByVersion.entries()) {
92+
await prerenderVersion(urls);
93+
}
8694

8795
console.log('\nPrerendering complete!');
88-
console.log(`Total URLs: ${urls.length}`);
89-
console.log(`Successfully saved: ${successCount}`);
90-
console.log(`Not found: ${notFoundCount}`);
96+
console.log(`Total URLs: ${totalUrls}`);
9197
}
9298

9399
prerender().catch((error) => {

0 commit comments

Comments
 (0)