Skip to content

Commit

Permalink
fix: backward support position
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 15, 2021
1 parent 385a9bf commit 2f81f49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion theme/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions theme/utils/document.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand All @@ -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) {
Expand Down

1 comment on commit 2f81f49

@vercel
Copy link

@vercel vercel bot commented on 2f81f49 Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.