-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation-layout.js
41 lines (35 loc) · 1.06 KB
/
documentation-layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict'
const renderBlock = require('./block')
module.exports = function (opts = {}) {
const { document } = this
const {
cssClasses = (document.cssClasses || []),
projectId = document.projectId,
categoryId = document.categoryId
} = opts
const docs = this.getHelperConfig().docs
const project = this.getProject(projectId)
const category = this.getCategory(projectId, categoryId)
const pageIndex = project.collection.models.findIndex((item) => item.id === document.id)
const prevModel = project.collection.models[pageIndex - 1] || null
const nextModel = project.collection.models[pageIndex + 1] || null
const parents = (docs.url !== project.url && docs.title)
? [docs].concat([project, category])
: [project, category]
const up = category
const prev = prevModel && {
url: prevModel.attributes.url,
title: prevModel.attributes.title
}
const next = nextModel && {
url: nextModel.attributes.url,
title: nextModel.attributes.title
}
return renderBlock.call(this, {
cssClasses: ['doc'].concat(cssClasses),
parents,
prev,
next,
up
})
}