mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(v2): docs, make numberPrefixParser configurable, better defaults, minor breaking-changes (#4655)
* make number prefix parsing logic configurable * Make numberPrefixParser configurable + rename frontmatter + avoid parsing date/version patterns by default * add more tests * more test cases
This commit is contained in:
parent
d0d29f43cc
commit
c04e613ffe
14 changed files with 325 additions and 82 deletions
|
@ -76,10 +76,35 @@ module.exports = {
|
|||
* Function used to replace the sidebar items of type "autogenerated"
|
||||
* by real sidebar items (docs, categories, links...)
|
||||
*/
|
||||
sidebarItemsGenerator: function ({item, version, docs}) {
|
||||
sidebarItemsGenerator: function ({
|
||||
item,
|
||||
version,
|
||||
docs,
|
||||
numberPrefixParser,
|
||||
}) {
|
||||
// Use the provided data to create a custom "sidebar slice"
|
||||
return [{type: 'doc', id: 'doc1'}];
|
||||
},
|
||||
/**
|
||||
* The Docs plugin supports number prefixes like "01-My Folder/02.My Doc.md".
|
||||
* Number prefixes are extracted and used as position to order autogenerated sidebar items.
|
||||
* For conveniency, number prefixes are automatically removed from the default doc id, name, title.
|
||||
* This parsing logic is configurable to allow all possible usecases and filename patterns.
|
||||
* Use "false" to disable this behavior and leave the docs untouched.
|
||||
*/
|
||||
numberPrefixParser: function (filename) {
|
||||
// Implement your own logic to extract a potential number prefix
|
||||
const numberPrefix = findNumberPrefix(filename);
|
||||
// Prefix found: return it with the cleaned filename
|
||||
if (numberPrefix) {
|
||||
return {
|
||||
numberPrefix,
|
||||
filename: filename.replace(prefix, ''),
|
||||
};
|
||||
}
|
||||
// No number prefix found
|
||||
return {numberPrefix: undefined, filename};
|
||||
},
|
||||
/**
|
||||
* Theme components used by the docs pages
|
||||
*/
|
||||
|
@ -165,7 +190,7 @@ Markdown documents can use the following markdown frontmatter metadata fields, e
|
|||
- `hide_table_of_contents`: Whether to hide the table of contents to the right. By default it is `false`
|
||||
- `sidebar_label`: The text shown in the document sidebar and in the next/previous button for this document. If this field is not present, the document's `sidebar_label` will default to its `title`
|
||||
- `sidebar_position`: Permits to control the position of a doc inside the generated sidebar slice, when using `autogenerated` sidebar items. Can be Int or Float.
|
||||
- `strip_number_prefixes`: When a document has a number prefix (`001 - My Doc.md`, `2. MyDoc.md`...), it is automatically removed, and the prefix is used as `sidebar_position`. Use `strip_number_prefixes: false` if you want to disable this behavior
|
||||
- `parse_number_prefixes`: When a document has a number prefix (`001 - My Doc.md`, `2. MyDoc.md`...), it is automatically parsed and extracted by the plugin `numberPrefixParser`, and the number prefix is used as `sidebar_position`. Use `parse_number_prefixes: false` to disable number prefix parsing on this doc
|
||||
- `custom_edit_url`: The URL for editing this document. If this field is not present, the document's edit URL will fall back to `editUrl` from options fields passed to `docusaurus-plugin-content-docs`
|
||||
- `keywords`: Keywords meta tag for the document page, for search engines
|
||||
- `description`: The description of your document, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. If this field is not present, it will default to the first line of the contents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue