-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.js
59 lines (56 loc) · 1.6 KB
/
block.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const h = require('hyperscript')
module.exports = function (opts = {}) {
// Prepare
const { document, content, text = {} } = this
const {
permalink = document.url,
heading = document.title,
subheading = document.subheading || document.description,
author = document.author,
cssClasses = (document.cssClasses || []),
editUrl = document.editUrl,
date,
prev,
next,
up,
parents = []
} = opts
// Render
const classes = ['block'].concat(cssClasses)
return h('article', { class: classes.join(' ') },
h('header.block-header',
(parents.length || null) && h('nav.parentcrumbs',
h('ul', parents.map((parent) =>
h('li',
h('a.permalink', { href: parent.url },
h('h3', parent.title)
)
)
))
),
(permalink || h('h1', heading)) && h('a.permalink.hover-link', { href: permalink }, h('h1', heading)),
(subheading || null) && h('h2', subheading),
(date || null) && h('span.date', date),
(author || null) && h('a.author', { href: `/people/${author}` }, author)
),
h('section.block-content', { innerHTML: content }),
h('footer.block-footer', ((prev || up || next) || null) && h('nav.prev-next',
(prev || null) && h('a.prev', { href: prev.url },
h('span.icon'),
h('span.title', prev.title)
),
(up || null) && h('a.up', { href: up.url },
h('span.icon'),
h('span.title', up.title)
),
(next || null) && h('a.next', { href: next.url },
h('span.icon'),
h('span.title', next.title)
)
)),
(editUrl || null) && h('aside.block-edit',
h('a', { href: editUrl }, text.edit || 'Edit and improve this page!')
)
)
}