From 2f81f490db826640fec173ba982fe091109325ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 15 Feb 2021 17:09:30 +0100 Subject: [PATCH] fix: backward support position --- theme/module.js | 2 +- theme/utils/document.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/theme/module.js b/theme/module.js index 8552f1f79..3817ed470 100644 --- a/theme/module.js +++ b/theme/module.js @@ -69,7 +69,7 @@ export default function docusModule () { const _category = category && typeof category === 'string' ? category : '' const _to = `${_dir}/${slug}` - const position = generatePosition(_to) + const position = generatePosition(_to, document) document.slug = generateSlug(slug) document.position = position diff --git a/theme/utils/document.js b/theme/utils/document.js index 68119d7b4..8f65a4235 100644 --- a/theme/utils/document.js +++ b/theme/utils/document.js @@ -1,9 +1,10 @@ -export function generatePosition (path) { +export function generatePosition (path, doc) { const position = path.split('/').filter(Boolean).map((part) => { const match = part.match(/^(\d+)\./) - return match - ? paddLeft(match[1], 4) - : '9999' // Parts wihtout a position are going down to the bottom + if (match) { + return paddLeft(match[1], 4) + } + return doc.position ? paddLeft(doc.position, 4) : '9999' // Parts without a position are going down to the bottom }).join('') return paddRight(position, 12) } @@ -16,7 +17,7 @@ export function generateSlug (path) { } function paddLeft (value, length) { - return ('0'.repeat(length) + value).substr(value.length) + return ('0'.repeat(length) + value).substr(String(value).length) } function paddRight (value, length) {