Skip to content

Commit 6f68a03

Browse files
mansonajenweber
authored andcommitted
only render methods properties and events if exist
1 parent abf6b9f commit 6f68a03

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

prember-urls.js

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

55
function partialUrlEncode(input) {
6-
return input.replace('/', '%2F');
6+
return input.replace(/\//g, '%2F');
77
}
88

9+
const singularData = {
10+
classes: 'class',
11+
namespaces: 'namespace',
12+
modules: 'module',
13+
};
14+
915
module.exports = function () {
1016
const projects = readdirSync('ember-api-docs-data/json-docs');
1117

@@ -72,36 +78,42 @@ module.exports = function () {
7278
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}`
7379
);
7480

75-
// TODO only include sub routes if that entity has stuff in that route i.e. if it's empty don't pre-render it
76-
urls.push(
77-
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(
78-
cleanId
79-
)}/methods`
80-
);
81-
urls.push(
82-
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(
83-
cleanId
84-
)}/properties`
85-
);
86-
urls.push(
87-
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(cleanId)}/events`
88-
);
81+
const fileName = revIndex.meta[singularData[entity]][id];
82+
let entityData;
8983

90-
if (entity === 'modules') {
91-
const moduleKey = id;
84+
if (fileName !== undefined) {
85+
// rare cases when very strange things make it through this far
86+
// e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed.
87+
// 🤷‍♀️
88+
entityData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/${entity}/${fileName}.json`);
89+
}
9290

93-
const fileName = revIndex.meta.module[moduleKey];
91+
if (entityData.data.attributes.methods?.length) {
92+
urls.push(
93+
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(
94+
cleanId
95+
)}/methods`
96+
);
97+
}
9498

95-
if (fileName === undefined) {
96-
// rare cases when very strange things make it through this far
97-
// e.g. ember-3.0.0-ember%0A%0ARemove%20after%203.4%20once%20_ENABLE_RENDER_SUPPORT%20flag%20is%20no%20longer%20needed.
98-
// 🤷‍♀️
99-
return;
100-
}
99+
if (entityData.data.attributes.properties?.length) {
100+
urls.push(
101+
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(
102+
cleanId
103+
)}/properties`
104+
);
105+
}
101106

102-
const moduleData = require(`${__dirname}/ember-api-docs-data/json-docs/${p}/${highestPatchVersion}/modules/${fileName}.json`);
107+
if (entityData.data.attributes.events?.length) {
108+
urls.push(
109+
`/${p}/${uniqVersion}/${entity}/${partialUrlEncode(
110+
cleanId
111+
)}/events`
112+
);
113+
}
103114

104-
const staticFunctions = moduleData.data.attributes.staticfunctions;
115+
if (entity === 'modules' && entityData) {
116+
const staticFunctions = entityData.data.attributes.staticfunctions;
105117

106118
Object.keys(staticFunctions).forEach((k) => {
107119
const listOfFunctions = staticFunctions[k];

0 commit comments

Comments
 (0)