Skip to content

Commit 4c367cb

Browse files
committed
Add publishing times to default HTML template, various CSS fixes
1 parent 961d8fe commit 4c367cb

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ const JUSTIFY_CSS = `
6767
let configured = false;
6868
function configure() {
6969
if (!configured) {
70-
nunjucks.configure({ autoescape: false, noCache: true });
70+
const env = nunjucks.configure({
71+
autoescape: false,
72+
noCache: true
73+
});
74+
env.addFilter('humandate', humanDate);
7175
configured = true;
7276
}
7377
}
@@ -299,7 +303,7 @@ async function bundlePdf(items, options) {
299303
filetype: 'pdf',
300304
title,
301305
author,
302-
date: humanDate(new Date()),
306+
date: new Date(),
303307
items,
304308
style,
305309
options: {
@@ -497,7 +501,7 @@ async function bundleHtml(items, options) {
497501
title:
498502
options.title ||
499503
(items.length === 1 ? items[0].title : 'Untitled'),
500-
date: humanDate(new Date()),
504+
date: new Date(),
501505
items,
502506
style,
503507
options: {
@@ -552,7 +556,7 @@ async function bundleMd(items, options) {
552556
title:
553557
options.title ||
554558
(items.length === 1 ? items[0].title : 'Untitled'),
555-
date: humanDate(new Date()),
559+
date: new Date(),
556560
items,
557561
style,
558562
options: {

src/cleanup-item.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export default async function cleanupItem(
173173
url,
174174
title: sanitizer.sanitize(parsed.title),
175175
byline: sanitizer.sanitize(parsed.byline),
176+
published: sanitizer.sanitize(parsed.published || parsed.publishedTime),
177+
updated: sanitizer.sanitize(parsed.updated),
176178
dir: sanitizer.sanitize(parsed.dir),
177179
excerpt: serializer(sanitize_to_dom(parsed.excerpt)),
178180
content: serializer(

src/util/human-date.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
const formatter = new Intl.DateTimeFormat('en', {
1+
const dateTimeFormatter = new Intl.DateTimeFormat('en', {
2+
dateStyle: 'medium',
3+
timeStyle: 'short'
4+
});
5+
6+
const dateFormatter = new Intl.DateTimeFormat('en', {
27
dateStyle: 'medium'
38
});
49

5-
export default function humanDate(d) {
6-
return formatter.format(d);
10+
export default function humanDate(date, includeTime = false) {
11+
const d = new Date(date);
12+
return includeTime ? dateTimeFormatter.format(d) : dateFormatter.format(d);
713
}

templates/default.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ article {
117117
}
118118

119119
article:not(:last-of-type) {
120+
margin-bottom: 2em;
120121
page-break-after: always;
121122
}
122123

@@ -136,9 +137,12 @@ article:not(:last-of-type) {
136137
line-height: 1.1;
137138
}
138139

140+
.article__byline,
141+
.article__time,
139142
.article__url {
140143
font-style: italic;
141144
font-size: 0.9em;
145+
margin: 0;
142146
}
143147

144148
/*
@@ -148,6 +152,7 @@ article:not(:last-of-type) {
148152

149153
.article__content img {
150154
max-width: 100%;
155+
height: auto;
151156
display: block;
152157
margin: 0 auto;
153158
}

templates/default.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<h1 class="cover__title">{{ title }}</h1>
3232
<p class="cover__subtitle">
3333
<time class="cover__date" datetime="{{ date }}"
34-
>{{ date }}</time
34+
>{{ date | humandate }}</time
3535
>
3636
</p>
3737
</div>
@@ -57,6 +57,18 @@ <h1 class="toc__title">Table of Contents</h1>
5757
<h1 class="article__title">{{ item.title }}</h1>
5858
{% if item.byline %}
5959
<p class="article__byline">By <span>{{ item.byline }}</span></p>
60+
{% endif %} {% if item.published %}
61+
<p class="article__time">
62+
Published
63+
<time datetime="{{item.published}}">
64+
{{item.published | humandate(true) }} </time
65+
>{%- if item.updated and item.updated !== item.published
66+
-%}, updated
67+
<time datetime="{{item.updated}}">
68+
{{item.updated | humandate(true) }}
69+
</time>
70+
{%- endif -%}
71+
</p>
6072
{% endif %}
6173
<p class="article__url">
6274
Source:

0 commit comments

Comments
 (0)