-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13113 from hasezoey/changeDocsHeaderId
Change API documentation headers to be more unique
- Loading branch information
Showing
3 changed files
with
73 additions
and
8 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
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 }); |
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