Skip to content

Commit 48a8bdf

Browse files
committed
add each function to prember-urls
1 parent 55886aa commit 48a8bdf

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

prember-urls.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { readdirSync } = require('fs');
1+
const { readdirSync, readFileSync } = require('fs');
22
const cmp = require('semver-compare');
33
const semver = require('semver');
44

@@ -40,12 +40,50 @@ module.exports = function () {
4040

4141
['classes', 'namespaces', 'modules'].forEach((entity) => {
4242
// add classes
43-
revIndex.data.relationships[entity].data.forEach(({id}) => {
43+
revIndex.data.relationships[entity].data.forEach(({ id }) => {
4444
const [, cleanId] = id.match(/^.+-\d+\.\d+\.\d+-(.*)/);
4545
urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}`);
46+
47+
// TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it
4648
urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/methods`);
4749
urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/properties`);
4850
urls.push(`/${p}/${uniqVersion}/${entity}/${cleanId}/events`);
51+
52+
if (entity === 'modules') {
53+
// id is
54+
55+
const moduleKey = `${encodeURIComponent(id)}`;
56+
const fileName = revIndex.meta.module[moduleKey];
57+
58+
if (fileName === undefined) {
59+
// rare cases when very strange things make it through this far
60+
// e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed.
61+
// 🤷‍♀️
62+
return;
63+
}
64+
65+
const moduleData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/modules/${fileName}.json`);
66+
67+
const staticFunctions = moduleData.data.attributes.staticfunctions;
68+
69+
Object.keys(staticFunctions).forEach((k) => {
70+
const listOfFunctions = staticFunctions[k];
71+
72+
listOfFunctions.forEach((func) => {
73+
urls.push(
74+
`/${p}/${uniqVersion}/functions/${cleanId.replace(
75+
'/',
76+
'%2F'
77+
)}/${func.name}`
78+
);
79+
});
80+
});
81+
}
82+
83+
// TODO review that we have got all the URLs that we care about
84+
85+
// TODO discuss only prembering "supported" versions - maybe last version in a major and supported versions
86+
// alternative is to rely on netlify complex build
4987
});
5088
});
5189
});

0 commit comments

Comments
 (0)