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

docs(api.pug): change to redirect to mongoose API page #12223

Merged
merged 5 commits into from
Feb 13, 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
64 changes: 3 additions & 61 deletions docs/api.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,8 @@ 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/redirect-old-api.js")

block content
h1 API Docs

include includes/native

div.api-nav
div.api-nav-content
each item in docs
- if (!item.hideFromNav)
div.nav-item(id='nav-' + item.name)
div.nav-item-title
a(href='./api/' + item.name.toLowerCase() + '.html')
| #{item.name}
ul.nav-item-sub
each prop in item.props
li
a(href='./api/' + item.name.toLowerCase() + '.html#' + prop.anchorId)
| #{prop.string}

each item in docs
hr.separate-api
div.item-header-wrap
<a class="edit-docs-link" href="#{item.editLink}" target="_blank">
<img src="/docs/images/pencil.svg" />
</a>
h2(id=item.name, class="item-header")
a(href='#' + item.name)
| #{item.name}
ul
each prop in item.props
li
a(href='#' + prop.anchorId)
| #{prop.string}
each prop in item.props
hr.separate-api-elements
h3(id=prop.anchorId)
a(href='#' + prop.anchorId)
| #{prop.string}
if prop.param != null
h5 Parameters
ul.params
each param in prop.param
- if (param.nested)
ul(style="margin-top: 0.5em")
li
| #{param.name}
| <span class="method-type">&laquo;#{param.types}&raquo;</span> !{param.description}
- else
li.param
| #{param.name}
| <span class="method-type">&laquo;#{param.types}&raquo;</span> !{param.description}
if prop.return != null
h5 Returns:
ul
li <span class="method-type">&laquo;#{prop.return.types}&raquo;</span> !{prop.return.description}
if prop.type != null && prop.type !== 'method' && prop.type !== 'function'
h5 Type:
ul
li <span class="method-type">&laquo;#{prop.type}&raquo;</span>
div
| !{prop.description}
p Redirecting to proper API page, please wait
noscript This Page requires JavaScript to Redirect old links properly
2 changes: 1 addition & 1 deletion docs/includes/nav.pug
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ul
a(href="https://github.com/Automattic/mongoose/wiki/4.0-Release-Notes")
| 4.0 release notes
li.api
a(href="./api.html") API docs
a(href="./api/mongoose.html") API docs
li.quickstart
a(href="./index.html") quick start
li.contrib
Expand Down
29 changes: 29 additions & 0 deletions docs/js/redirect-old-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
window.addEventListener('DOMContentLoaded', () => {
const anchor = window.location.hash;

// in case there is not anchor
if (!anchor) {
return redirectToBase();
}

const firstName = anchor.split('_')[0];

// in case there is no split
if (!firstName) {
return redirectToBase();
}

const sliced = firstName.slice(1).toLowerCase(); // ignore first character, which will always be "#"

// in case everything after "#" is empty
if (!sliced) {
return redirectToBase();
}

window.location.replace('./api/' + sliced + '.html' + anchor);
}, { once: true });

// helper function to redirect in case no other redirect can be found
function redirectToBase() {
window.location.replace('./api/mongoose.html');
}
2 changes: 1 addition & 1 deletion docs/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ html(lang='en')
li.pure-menu-item.tertiary-item
a.pure-menu-link(href="/docs/typescript/subdocuments.html", class=outputUrl === '/docs/typescript/subdocuments.html' ? 'selected' : '') Subdocuments
li.pure-menu-item
a.pure-menu-link(href="/docs/api.html", class=outputUrl === '/docs/api.html' ? 'selected' : '') API
a.pure-menu-link(href="/docs/api/mongoose.html", class=outputUrl === '/docs/api/mongoose.html' ? 'selected' : '') API
li.pure-menu-item.sub-item
a.pure-menu-link(href="/docs/api/mongoose.html", class=outputUrl === '/docs/api/mongoose.html' ? 'selected' : '') Mongoose
li.pure-menu-item.sub-item
Expand Down
9 changes: 1 addition & 8 deletions docs/source/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ const files = [
'lib/types/map.js'
];

module.exports = {
docs: [],
github: 'https://github.com/Automattic/mongoose/blob/',
title: 'API docs',
api: true
};

const out = module.exports.docs;
const out = module.exports.docs = [];

const combinedFiles = [];
for (const file of files) {
Expand Down
5 changes: 4 additions & 1 deletion docs/source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ try {
} catch (err) {}

exports['index.pug'] = require('./home');
exports['docs/api.pug'] = require('./api');
exports['docs/api.pug'] = {
docs: [],
title: 'Redirect to API',
};

exports['docs/advanced_schemas.md'] = { title: 'Advanced Schemas', acquit: true, markdown: true };
exports['docs/validation.md'] = { title: 'Validation', acquit: true, markdown: true };
Expand Down