@nera-static/theme-stack 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +373 -2
- package/assets/css/theme.css +1640 -0
- package/assets/fonts/stack/OFL-bricolage-grotesque.txt +93 -0
- package/assets/fonts/stack/OFL-inter.txt +93 -0
- package/assets/fonts/stack/OFL-jetbrains-mono.txt +93 -0
- package/assets/fonts/stack/bricolage-grotesque-latin-ext-wght-normal.woff2 +0 -0
- package/assets/fonts/stack/bricolage-grotesque-latin-wght-normal.woff2 +0 -0
- package/assets/fonts/stack/inter-latin-ext-wght-italic.woff2 +0 -0
- package/assets/fonts/stack/inter-latin-ext-wght-normal.woff2 +0 -0
- package/assets/fonts/stack/inter-latin-wght-italic.woff2 +0 -0
- package/assets/fonts/stack/inter-latin-wght-normal.woff2 +0 -0
- package/assets/fonts/stack/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
- package/assets/fonts/stack/jetbrains-mono-latin-wght-normal.woff2 +0 -0
- package/config/theme.yaml +37 -0
- package/package.json +80 -5
- package/views/layouts/layout.pug +19 -0
- package/views/pages/archive.pug +20 -0
- package/views/pages/default.pug +8 -0
- package/views/pages/home.pug +40 -0
- package/views/pages/post.pug +59 -0
- package/views/pages/tag.pug +8 -0
- package/views/partials/card-media.pug +5 -0
- package/views/partials/feed-link.pug +4 -0
- package/views/partials/footer-extra.pug +4 -0
- package/views/partials/footer.pug +10 -0
- package/views/partials/head-extra.pug +4 -0
- package/views/partials/head.pug +14 -0
- package/views/partials/header.pug +8 -0
- package/views/partials/helpers.pug +215 -0
- package/views/partials/home-about.pug +14 -0
- package/views/partials/home-series.pug +14 -0
- package/views/partials/lang-switch.pug +13 -0
- package/views/partials/nav-main.pug +5 -0
- package/views/partials/page-header.pug +6 -0
- package/views/partials/post-card.pug +21 -0
- package/views/partials/post-media.pug +4 -0
- package/views/partials/post-pagination.pug +4 -0
- package/views/partials/post-tags.pug +3 -0
- package/views/partials/scripts-extra.pug +2 -0
- package/views/partials/scripts.pug +3 -0
- package/views/partials/tag-cloud.pug +4 -0
- package/views/partials/tag-overview.pug +8 -0
- package/views/partials/tokens.pug +7 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
//- The shared functions every view calls (ROADMAP-themes §S2.2). Included by
|
|
2
|
+
//- layouts/layout.pug before anything that uses them; a site that overrides
|
|
3
|
+
//- the layout includes this file too.
|
|
4
|
+
//-
|
|
5
|
+
//- Pug compiles a page and everything it includes into one function, so a
|
|
6
|
+
//- top-level name here would clash with a `const` of the same name in any
|
|
7
|
+
//- included template (plugin-tags' tag-overview declares `lang`, for one).
|
|
8
|
+
//- The theme therefore declares only the six helpers of §S2.2 and one object,
|
|
9
|
+
//- `themeStack`, which holds the rest.
|
|
10
|
+
-
|
|
11
|
+
// The language a page is in: its own `lang`, else the site's.
|
|
12
|
+
function pageLang(page) {
|
|
13
|
+
return (page && page.meta && page.meta.lang) || app.lang
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Whether a page is in the current page's language.
|
|
17
|
+
function sameLang(page) {
|
|
18
|
+
return pageLang(page) === pageLang({ meta })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The home page of a language (§S2.8, rule 2), falling back to `/`.
|
|
22
|
+
function homeHref(lang) {
|
|
23
|
+
const home = themeStack.homePage(lang)
|
|
24
|
+
return home ? home.meta.href : '/'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Formatted in UTC: a YAML date is midnight UTC, so a build machine in a
|
|
28
|
+
// time zone west of UTC would otherwise print the day before.
|
|
29
|
+
function formatDate(value, lang) {
|
|
30
|
+
const date = themeStack.toDate(value)
|
|
31
|
+
return date
|
|
32
|
+
? date.toLocaleDateString(lang, { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' })
|
|
33
|
+
: ''
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isoDate(value) {
|
|
37
|
+
const date = themeStack.toDate(value)
|
|
38
|
+
return date ? date.toISOString().slice(0, 10) : ''
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A path, or a `{ <lang>: path }` map resolved for `lang`. Undefined when
|
|
42
|
+
// the map has no path for that language.
|
|
43
|
+
function hrefFor(value, lang) {
|
|
44
|
+
if (typeof value === 'string') return value
|
|
45
|
+
if (value && typeof value === 'object' && typeof value[lang] === 'string') return value[lang]
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const themeStack = (() => {
|
|
50
|
+
const config = (app.theme && app.theme.config) || {}
|
|
51
|
+
const blog = config.blog || {}
|
|
52
|
+
const pages = () => (Array.isArray(pagesData) ? pagesData : []).filter((page) => page && page.meta)
|
|
53
|
+
const byHref = (a, b) => String(a.meta.href).localeCompare(String(b.meta.href))
|
|
54
|
+
|
|
55
|
+
// Frontmatter dates arrive as Date objects (YAML timestamps), a
|
|
56
|
+
// file's birth time, or a string. Null when the value is not a date.
|
|
57
|
+
const toDate = (value) => {
|
|
58
|
+
if (value === undefined || value === null || value === '') return null
|
|
59
|
+
const date = value instanceof Date ? value : new Date(value)
|
|
60
|
+
return Number.isNaN(date.getTime()) ? null : date
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A rendered `index.html` in that language with the shortest
|
|
64
|
+
// `dirname` (ties by href), or null.
|
|
65
|
+
const homePage = (lang) =>
|
|
66
|
+
pages()
|
|
67
|
+
.filter((page) => page.meta.layout && page.meta.filename === 'index.html' && pageLang(page) === lang)
|
|
68
|
+
.sort((a, b) => String(a.meta.dirname).length - String(b.meta.dirname).length || byHref(a, b))[0] || null
|
|
69
|
+
|
|
70
|
+
// The posts of a language (§S4.1): pages whose layout is listed in
|
|
71
|
+
// `blog.post_layouts`, newest first by `createdAt`, ties by href.
|
|
72
|
+
const posts = (lang) => {
|
|
73
|
+
const layouts = Array.isArray(blog.post_layouts) ? blog.post_layouts : ['pages/post.pug']
|
|
74
|
+
const time = (page) => {
|
|
75
|
+
const date = toDate(page.meta.createdAt)
|
|
76
|
+
return date ? date.getTime() : -8.64e15
|
|
77
|
+
}
|
|
78
|
+
return pages()
|
|
79
|
+
.filter((page) => layouts.includes(page.meta.layout) && pageLang(page) === lang)
|
|
80
|
+
.sort((a, b) => time(b) - time(a) || byHref(a, b))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The posts the home lists: the newest `blog.home_posts` (default 7:
|
|
84
|
+
// the featured card and two rows of three).
|
|
85
|
+
const homePosts = (lang) => {
|
|
86
|
+
const count = Number(blog.home_posts)
|
|
87
|
+
return posts(lang).slice(0, Number.isInteger(count) && count >= 0 ? count : 7)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The posts of a language grouped by year, newest year first. A post
|
|
91
|
+
// whose date does not parse has no year and is left out.
|
|
92
|
+
const postsByYear = (lang) => {
|
|
93
|
+
const years = []
|
|
94
|
+
for (const post of posts(lang)) {
|
|
95
|
+
const date = toDate(post.meta.createdAt)
|
|
96
|
+
if (!date) continue
|
|
97
|
+
const year = date.getUTCFullYear()
|
|
98
|
+
const last = years[years.length - 1]
|
|
99
|
+
if (last && last.year === year) last.posts.push(post)
|
|
100
|
+
else years.push({ year, posts: [post] })
|
|
101
|
+
}
|
|
102
|
+
return years
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The design tokens as one `:root{…}` rule (§S2.5), '' when no token
|
|
106
|
+
// survives. A value is emitted only if it is a string or number
|
|
107
|
+
// without `<`, `>`, `{`, `}` or `;`, a group or token name only if it
|
|
108
|
+
// is made of letters, digits, `-` and `_`.
|
|
109
|
+
const tokenRule = () => {
|
|
110
|
+
const tokens = config.tokens || {}
|
|
111
|
+
const safe = (v) => ['string', 'number'].includes(typeof v) && !/[<>{};]/.test(String(v))
|
|
112
|
+
const safeName = (n) => /^[A-Za-z0-9_-]+$/.test(n)
|
|
113
|
+
const decls = []
|
|
114
|
+
for (const [group, values] of Object.entries(tokens)) {
|
|
115
|
+
if (!values || typeof values !== 'object' || !safeName(group)) continue
|
|
116
|
+
for (const [name, value] of Object.entries(values)) {
|
|
117
|
+
if (safeName(name) && safe(value)) decls.push(`--theme-${group}-${name.replace(/_/g, '-')}:${value};`)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return decls.length ? `:root{${decls.join('')}}` : ''
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// `extra_css` entries that are root-absolute paths: one leading `/`,
|
|
124
|
+
// not `//` or `/\` (a browser reads both as another host), and no tab,
|
|
125
|
+
// CR or LF anywhere (the URL parser drops them, so `/<tab>/host` would
|
|
126
|
+
// become `//host`).
|
|
127
|
+
const extraCss = () =>
|
|
128
|
+
(Array.isArray(config.extra_css) ? config.extra_css : [])
|
|
129
|
+
.filter((entry) => typeof entry === 'string' && /^\/(?![/\\])[^\t\n\r]*$/.test(entry))
|
|
130
|
+
|
|
131
|
+
// `footer_links` resolved for a language; an entry without a label or
|
|
132
|
+
// without a path for that language is left out.
|
|
133
|
+
const footerLinks = (lang) =>
|
|
134
|
+
(Array.isArray(config.footer_links) ? config.footer_links : [])
|
|
135
|
+
.filter((entry) => entry && typeof entry.label === 'string' && hrefFor(entry.href, lang))
|
|
136
|
+
.map((entry) => ({ label: entry.label, href: hrefFor(entry.href, lang) }))
|
|
137
|
+
|
|
138
|
+
// The language switch (§S2.8): every language of `app.translations`,
|
|
139
|
+
// the page's own as `current`, each other one linked to the page with
|
|
140
|
+
// the same `slug` in that language, else to that language's home.
|
|
141
|
+
// A language with neither is left out. Empty, so the switch is not
|
|
142
|
+
// rendered, when there are fewer than two translations or fewer than
|
|
143
|
+
// two links.
|
|
144
|
+
const languageLinks = (lang) => {
|
|
145
|
+
const translations = app.translations || {}
|
|
146
|
+
const slug = meta.slug
|
|
147
|
+
const links = Object.keys(translations)
|
|
148
|
+
.map((code) => {
|
|
149
|
+
const name = (translations[code] && translations[code].language_name) || code.toUpperCase()
|
|
150
|
+
if (code === lang) return { code, name, current: true }
|
|
151
|
+
const twin = slug === undefined || slug === null
|
|
152
|
+
? null
|
|
153
|
+
: pages()
|
|
154
|
+
.filter((page) => page.meta.layout && page.meta.slug === slug && pageLang(page) === code)
|
|
155
|
+
.sort(byHref)[0]
|
|
156
|
+
const target = twin || homePage(code)
|
|
157
|
+
return target ? { code, name, href: target.meta.href } : null
|
|
158
|
+
})
|
|
159
|
+
.filter(Boolean)
|
|
160
|
+
return Object.keys(translations).length >= 2 && links.length >= 2 ? links : []
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The parts of a series in a language (Revision R3): posts whose
|
|
164
|
+
// frontmatter `series` is `name`, ordered by `series_part`, then by
|
|
165
|
+
// date. Empty for an empty name.
|
|
166
|
+
const seriesParts = (name, lang) => {
|
|
167
|
+
if (typeof name !== 'string' || !name) return []
|
|
168
|
+
const part = (page) => {
|
|
169
|
+
const n = Number(page.meta.series_part)
|
|
170
|
+
return Number.isFinite(n) ? n : Number.MAX_SAFE_INTEGER
|
|
171
|
+
}
|
|
172
|
+
return posts(lang)
|
|
173
|
+
.filter((page) => page.meta.series === name)
|
|
174
|
+
.sort((a, b) => part(a) - part(b) || ((toDate(a.meta.createdAt) || 0) - (toDate(b.meta.createdAt) || 0)))
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// `blog.featured_series` (Revision R3), '' when unset.
|
|
178
|
+
const featuredSeries = () => (typeof blog.featured_series === 'string' ? blog.featured_series : '')
|
|
179
|
+
|
|
180
|
+
// The `author` block of config/theme.yaml (Revision R3), resolved
|
|
181
|
+
// for a language: `href` may be a path or a `{ <lang>: path }` map,
|
|
182
|
+
// like `footer_links`.
|
|
183
|
+
const author = (lang) => {
|
|
184
|
+
const value = config.author || {}
|
|
185
|
+
const text = (v) => (typeof v === 'string' ? v : '')
|
|
186
|
+
return { name: text(value.name), bio: text(value.bio), href: hrefFor(value.href, lang) || '' }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The round mark: the first letters of the name's first two words.
|
|
190
|
+
const initials = (name) =>
|
|
191
|
+
String(name || '').split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('')
|
|
192
|
+
|
|
193
|
+
// `facts` of a post: at most four `{ label, value }` with both set.
|
|
194
|
+
const facts = (page) =>
|
|
195
|
+
(Array.isArray(page.meta.facts) ? page.meta.facts : [])
|
|
196
|
+
.filter((fact) => fact && fact.label !== undefined && fact.value !== undefined && fact.label !== null && fact.value !== null)
|
|
197
|
+
.slice(0, 4)
|
|
198
|
+
|
|
199
|
+
// The type cover of a card without `image` (Revision R3): the first
|
|
200
|
+
// frontmatter tag, on a colour that follows the card's position.
|
|
201
|
+
const TONES = ['night', 'lime', 'red', 'blue', 'paper', 'night', 'mint']
|
|
202
|
+
const cover = (page, position) => {
|
|
203
|
+
const tags = Array.isArray(page.meta.tags) ? page.meta.tags.filter((tag) => typeof tag === 'string' && tag) : []
|
|
204
|
+
const index = Number.isInteger(position) && position >= 0 ? position : 0
|
|
205
|
+
return { text: tags[0] || '', tone: TONES[index % TONES.length] }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Day and month without the year, for rows under a year heading.
|
|
209
|
+
const dayMonth = (value, lang) => {
|
|
210
|
+
const date = toDate(value)
|
|
211
|
+
return date ? date.toLocaleDateString(lang, { month: 'short', day: 'numeric', timeZone: 'UTC' }) : ''
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { dayMonth, toDate, homePage, posts, homePosts, postsByYear, tokenRule, extraCss, footerLinks, languageLinks, seriesParts, featuredSeries, author, initials, facts, cover }
|
|
215
|
+
})()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//- The about block on the home (Revision R3, `author.*`): the initials in
|
|
2
|
+
//- a mark, label t('About the author'), the name, the bio and a link
|
|
3
|
+
//- t('Read more') to `author.href`. Not rendered without `author.name`.
|
|
4
|
+
if themeStack.author(pageLang({ meta })).name
|
|
5
|
+
section.home-about
|
|
6
|
+
span.home-about__mark(aria-hidden='true')= themeStack.initials(themeStack.author(pageLang({ meta })).name)
|
|
7
|
+
div
|
|
8
|
+
p= t('About the author')
|
|
9
|
+
h2= themeStack.author(pageLang({ meta })).name
|
|
10
|
+
if themeStack.author(pageLang({ meta })).bio
|
|
11
|
+
p= themeStack.author(pageLang({ meta })).bio
|
|
12
|
+
if themeStack.author(pageLang({ meta })).href
|
|
13
|
+
.home-about__links
|
|
14
|
+
a.button(href=themeStack.author(pageLang({ meta })).href)= t('Read more')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//- The featured series on the home (Revision R3, `blog.featured_series`):
|
|
2
|
+
//- label t('Series'), the name, a link t('Read more') to part one, and the
|
|
3
|
+
//- parts as a numbered list. Not rendered when the series has no part in the
|
|
4
|
+
//- page's language.
|
|
5
|
+
if themeStack.seriesParts(themeStack.featuredSeries(), pageLang({ meta })).length
|
|
6
|
+
section.home-series
|
|
7
|
+
div
|
|
8
|
+
p= t('Series')
|
|
9
|
+
h2= themeStack.featuredSeries()
|
|
10
|
+
a.button(href=themeStack.seriesParts(themeStack.featuredSeries(), pageLang({ meta }))[0].meta.href)= t('Read more')
|
|
11
|
+
ol
|
|
12
|
+
each part in themeStack.seriesParts(themeStack.featuredSeries(), pageLang({ meta }))
|
|
13
|
+
li
|
|
14
|
+
a(href=part.meta.href)= part.meta.title
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//- The language switch (§S2.8), shown when app.translations has two or more
|
|
2
|
+
//- languages and at least one other language has a page to link (a site with
|
|
3
|
+
//- a copied, untranslated entry gets no one-item switch). Each language is
|
|
4
|
+
//- named by its own `language_name` translation.
|
|
5
|
+
if themeStack.languageLinks(pageLang({ meta })).length
|
|
6
|
+
nav.lang-switch(aria-label=t('Language'))
|
|
7
|
+
ul.lang-switch__list
|
|
8
|
+
each link in themeStack.languageLinks(pageLang({ meta }))
|
|
9
|
+
li.lang-switch__item
|
|
10
|
+
if link.current
|
|
11
|
+
span.lang-switch__link(aria-current='true' lang=link.code)= link.name
|
|
12
|
+
else
|
|
13
|
+
a.lang-switch__link(href=link.href hreflang=link.code lang=link.code)= link.name
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//- Seam (§S2.4): inside nav.site-header__nav. In scope: app, meta. Empty in
|
|
2
|
+
//- the theme. A site with @nera-static/plugin-navigation overrides it with
|
|
3
|
+
//- the list form, so the theme's labelled <nav> is the only <nav> around it:
|
|
4
|
+
//- include /vendor/plugin-navigation/partials/link-list-navigation
|
|
5
|
+
//- +linkListNav
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//- One post in a list (§S4.1a, Revision R3). In scope: `item` (the post,
|
|
2
|
+
//- { content, meta }), `position` (its place in the list, for the cover
|
|
3
|
+
//- colour) and `featured` (true for the wide card of the newest post). A post
|
|
4
|
+
//- with a frontmatter `image` shows it through the card-media seam; one
|
|
5
|
+
//- without shows its first tag as large type on a coloured cover.
|
|
6
|
+
li.post-list__item
|
|
7
|
+
article.post-card(class=(typeof featured !== 'undefined' && featured) ? 'post-card--featured' : undefined)
|
|
8
|
+
if item.meta.image
|
|
9
|
+
.post-card__media
|
|
10
|
+
include card-media.pug
|
|
11
|
+
else
|
|
12
|
+
.post-card__cover(class=`post-card__cover--${themeStack.cover(item, typeof position === 'number' ? position : 0).tone}` aria-hidden='true')
|
|
13
|
+
span= themeStack.cover(item, typeof position === 'number' ? position : 0).text
|
|
14
|
+
.post-card__body
|
|
15
|
+
h3.post-card__title
|
|
16
|
+
a.post-card__link(href=item.meta.href)= item.meta.title
|
|
17
|
+
if item.meta.description
|
|
18
|
+
p.post-card__excerpt= item.meta.description
|
|
19
|
+
if isoDate(item.meta.createdAt)
|
|
20
|
+
p.post-card__meta
|
|
21
|
+
time.post-card__date(datetime=isoDate(item.meta.createdAt))= formatDate(item.meta.createdAt, pageLang(item))
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//- Seam (§S4.2): div.post__media of a post. In scope: meta. Empty in the
|
|
2
|
+
//- theme. A site with @nera-static/plugin-images overrides it with:
|
|
3
|
+
//- include /vendor/plugin-images/picture
|
|
4
|
+
//- +picture(meta.images && meta.images.image, { alt: meta.image_alt, class: 'post__image', loading: 'eager' })
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//- Seam (§S4.2): section.tag-page, the tag pages of @nera-static/plugin-tags.
|
|
2
|
+
//- In scope: meta, app. It owns the page's <h1>. A site with the plugin
|
|
3
|
+
//- overrides it with:
|
|
4
|
+
//- include /vendor/plugin-tags/pages/tag-overview
|
|
5
|
+
//- Without the plugin: the page title and body.
|
|
6
|
+
h1.page__title= meta.title || app.name
|
|
7
|
+
.page__body
|
|
8
|
+
!= content
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//- The design tokens of config/theme.yaml as --theme-* custom properties
|
|
2
|
+
//- (§S2.5), in one inline <style>. The rule is built by
|
|
3
|
+
//- themeStack.tokenRule() (helpers.pug), which drops every value with `<`,
|
|
4
|
+
//- `>`, `{`, `}` or `;` and every name not made of letters, digits, `-` and
|
|
5
|
+
//- `_`, so nothing in the YAML can break out of the rule.
|
|
6
|
+
if themeStack.tokenRule()
|
|
7
|
+
style!= themeStack.tokenRule()
|