forked from moodle/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[repo] Adjust /docs to include next version
This commit changes the unversioned docs at /docs/ to instead be at /docs/[nextVersionNumber]. It includes a redirect for /docs/* (where an existing page is not found) and it adds helpers to specify the version number in URLs and other locations. Fixes moodle#955
- Loading branch information
1 parent
8280d33
commit 23b8a4c
Showing
6 changed files
with
98 additions
and
9 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
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,26 @@ | ||
/** | ||
* Copyright (c) Moodle Pty Ltd. | ||
* | ||
* Moodle is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Moodle is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
const nextVersion = '4.4'; | ||
const nextLTSVersion = '4.5'; | ||
const nextVersionRoot = `/docs/${nextVersion}`; | ||
|
||
module.exports = { | ||
nextVersion, | ||
nextLTSVersion, | ||
nextVersionRoot, | ||
}; |
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,58 @@ | ||
/** | ||
* Copyright (c) Moodle Pty Ltd. | ||
* | ||
* Moodle is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Moodle is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { SKIP, CONTINUE, visit } from 'unist-util-visit'; | ||
import { nextVersionRoot } from '../../nextVersion.js'; | ||
|
||
/** | ||
* Update any /docs/* link to point to /docs/:nextVersion. | ||
* | ||
* @param {Tree} node | ||
* @param {Number} index | ||
* @param {Tree} parent | ||
* @returns {Number|String} The next index to process, or 'skip' to skip this node. | ||
*/ | ||
const updateLink = (node) => { | ||
if (!node.url) { | ||
return SKIP; | ||
} | ||
|
||
if (!node.url.startsWith('/docs/')) { | ||
return SKIP; | ||
} | ||
|
||
if (node.url.match(/\/docs\/\d\.\d/)) { | ||
return SKIP; | ||
} | ||
|
||
// Get the current version. | ||
node.url = node.url.replace(/^\/docs\//, `${nextVersionRoot}/`); | ||
|
||
return CONTINUE; | ||
}; | ||
|
||
const plugin = () => async (ast) => { | ||
// Visit all nodes on the AST which are of type 'link' and apply the updateLink function on them. | ||
// The visit function's third parameter is a Visitor function. | ||
// See the docs at https://github.com/syntax-tree/unist-util-visit-parents | ||
// Note: It has a mixed return type. | ||
// - If the Visitor function returns 'skip', then the visit function will skip this node and continue. | ||
// - If the Visitor function returns a Number, then the visit function will continue from that index. | ||
visit(ast, 'link', (node, index, parent) => updateLink(node, index, parent)); | ||
}; | ||
|
||
export default plugin; |
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