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:
Danny Lin 2021-06-28 10:59:05 -07:00 committed by GitHub
parent 3fe7389ee2
commit 79031af16f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -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'],
],
});
});