Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change API documentation headers to be more unique #13113

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api_split.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends layout
append style
link(rel="stylesheet", href="/docs/css/api.css")
script(src="/docs/js/api-bold-current-nav.js")
script(src="/docs/js/convert-old-anchorid.js")

block content
<a class="edit-docs-link" href="#{editLink}" target="_blank">
Expand Down
71 changes: 71 additions & 0 deletions docs/js/convert-old-anchorid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

window.addEventListener('DOMContentLoaded', () => {
const anchor = window.location.hash;

// only operate on the old id's
if (!/^#\w+_\w+(?:-\w+)?$/i.test(anchor)) {
return;
}

// in case there is no anchor, return without modifying the anchor
if (!anchor) {
return;
}

const splits = anchor.split('_');

// dont modify anything if the splits are not "2"
if (splits.length !== 2) {
return;
}

const secondSplits = splits[1].split('-');

let mainName;
let propName = '';

// there are 2 possibilities:
// "mongoose_Mongoose-property"
// "mongoose_property"
if (secondSplits.length === 2) {
mainName = secondSplits[0];
propName = secondSplits[1];
} else {
// use the part after the "_" directly, because the before is just a lower-cased version
mainName = splits[1];
propName = '';
}

// check to ensure those properties are not empty
if (!mainName) {
return;
}

let tests = [];

// have to use multiple tests, because the old version did not differentiate between functions and properties
if (mainName && propName) {
// have to double the tests here, because the old version did not differentiate between static and instance properties
tests = [
`${mainName}.${propName}`,
`${mainName}.${propName}()`,

`${mainName}.prototype.${propName}`,
`${mainName}.prototype.${propName}()`
];
} else {
tests = [
mainName,
`${mainName}()`
];
}

for (const test of tests) {
// have to use the "[id=]" selector because "#Something()" is not a valid selector (the "()" part)
const header = document.querySelector(`h3[id="${test}"]`);
if (header) {
window.location.hash = `#${test}`;
}
}
}, { once: true });
9 changes: 1 addition & 8 deletions docs/source/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,7 @@ function parse() {
ctx.string = ctx.string + '()';
}

// Backwards compat anchors
if (typeof ctx.constructor === 'string') {
ctx.anchorId = `${ctx.constructor.toLowerCase()}_${ctx.constructor}-${ctx.name}`;
} else if (typeof ctx.receiver === 'string') {
ctx.anchorId = `${ctx.receiver.toLowerCase()}_${ctx.receiver}.${ctx.name}`;
} else {
ctx.anchorId = `${ctx.name.toLowerCase()}_${ctx.name}`;
}
ctx.anchorId = ctx.string;

ctx.description = prop.description.full.
replace(/<br \/>/ig, ' ').
Expand Down