Skip to content

Commit 594a86a

Browse files
authored
resolves #16 allow components to be rearranged (PR #17)
1 parent ce17df7 commit 594a86a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

preview-src/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Author Name
55
:!example-caption:
66
:!table-caption:
77
:page-pagination:
8+
:page-component-order: *, abc
89

910
image:multirepo-ssg.svg[Multirepo SSG,200,float=right]
1011
Platonem complectitur mediocritatem ea eos.

src/helpers/rearrange.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
module.exports = (collection, property, orderSpec) => {
4+
if (!orderSpec || orderSpec === '*') return Object.values(collection)
5+
const order = orderSpec.split(',').map((it) => it.trim())
6+
const sourceCollection = Object.values(collection).reduce((accum, it) => accum.set(it[property], it), new Map())
7+
const restIdx = order.indexOf('*')
8+
if (~restIdx) order.splice(restIdx, 1)
9+
const targetCollection = order.reduce((accum, key) => {
10+
if (sourceCollection.has(key)) {
11+
accum.push(sourceCollection.get(key))
12+
sourceCollection.delete(key)
13+
}
14+
return accum
15+
}, [])
16+
if (~restIdx) targetCollection.splice(restIdx, 0, ...sourceCollection.values())
17+
return targetCollection
18+
}

src/partials/nav-explore.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
{{/if}}
88
<ul class="components">
9-
{{#each site.components}}
9+
{{#each (rearrange site.components 'name' page.attributes.component-order)}}
1010
<li class="component{{#if (eq this @root.page.component)}} is-current{{/if}}">
1111
<a class="title" href="{{{relativize ./url}}}">{{{./title}}}</a>
1212
{{#if (or ./versions.[1] (not (eq ./versions.[0].displayVersion 'current')))}}

0 commit comments

Comments
 (0)