generated from tepiton/tzintli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.11ty.js
83 lines (67 loc) · 1.71 KB
/
index.11ty.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const stars = ". . ."
module.exports = class Home {
data() {
return {
layout: "base.njk",
home: true,
excerpt: "all the little things",
eleventyNavigation: {
key: "home",
order: 1
}
}
}
async renderPost(post) {
let excerpt = post.data.excerpt || 'oops'
let noTitle = false
let header
excerpt = await this.renderTemplate(excerpt, 'md,njk')
if (post.data.newlines) {
excerpt = excerpt.trim().replace(/\n/g, '<br>\n')
}
if (!post.data.title || post.data.title === stars) {
header = ''
noTitle = true
} else {
header = `
<header>
<a href="${post.url}">${this.markdown(post.data.title)}</a>
</header>`
}
let section = `
<section>
${excerpt}
</section>`
let footer = `
<footer>
<span> </span>
<a href="${post.url}">${post.date.toDateString().replace(' 0', ' ')}</a>
</footer>`
let body = `<article class="rounded-border ${noTitle ? ' noTitle' : ''}">`
if (noTitle)
body += `<a href="${post.url}">`
else
body += header
body += section
body += footer
if (noTitle)
body += '</a>'
body += '\n</article>\n'
return body
}
async render(data) {
// array.reverse() is destructive
// array.slice() is a javascript idiom
// to copy an array
let posts = data.collections.tepiton.slice().reverse()
let head = ``
let notice = ''
let prolog = `<div class="tepiton stack">\n`
let epilog = '</div>'
let body = ''
for (const post of posts) {
body += await this.renderPost(post)
}
return head + notice + prolog + body + epilog
}
}