mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
fix(v2): allow negative sidebar positions (#5074)
In some cases, negative sidebar positions can be useful for reversing the sorting order with minimal maintenance overhead. For example, a docs folder with changelogs for historical versions should be sorted in reverse chronological order. This is easy to do for semantic version numbers by converting them into a negative numerical representation, e.g. 11.5.1 -> -110501. The alternative is to make the first version start with a large position number (e.g. 9999) and decrement it for each version. However, this requires referring to older versions to get the current sequence number, thus increasing maintenance overhead. It also makes the number less intuitive and more prone to error. Negative sidebar positions work great for this purpose, so make the front matter validator allow them again as #4796 broke this use case.
This commit is contained in:
parent
3fe7389ee2
commit
79031af16f
2 changed files with 4 additions and 4 deletions
|
@ -196,17 +196,17 @@ describe('validateDocFrontMatter sidebar_position', () => {
|
|||
testField({
|
||||
fieldName: 'sidebar_position',
|
||||
validFrontMatters: [
|
||||
{sidebar_position: -5},
|
||||
{sidebar_position: -3.5},
|
||||
{sidebar_position: 0},
|
||||
{sidebar_position: 5},
|
||||
{sidebar_position: 3.5},
|
||||
],
|
||||
convertibleFrontMatter: [
|
||||
[{sidebar_position: '-1.5'}, {sidebar_position: -1.5}],
|
||||
[{sidebar_position: '1'}, {sidebar_position: 1}],
|
||||
[{sidebar_position: '1.5'}, {sidebar_position: 1.5}],
|
||||
],
|
||||
invalidFrontMatters: [
|
||||
[{sidebar_position: -1}, 'must be greater than or equal to 0'],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
|||
description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
slug: Joi.string(),
|
||||
sidebar_label: Joi.string(),
|
||||
sidebar_position: Joi.number().min(0),
|
||||
sidebar_position: Joi.number(),
|
||||
pagination_label: Joi.string(),
|
||||
custom_edit_url: URISchema.allow('', null),
|
||||
parse_number_prefixes: Joi.boolean(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue