Skip to content

Commit ce76cd9

Browse files
committed
Dates improved. Pagination simplified. SEO improved.
1 parent e75b12e commit ce76cd9

12 files changed

Lines changed: 92 additions & 52 deletions

File tree

_config/filters.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ export default function(eleventyConfig) {
77
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
88
});
99

10-
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
10+
eleventyConfig.addFilter("isoDate", (dateObj) => {
1111
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
1212
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd');
1313
});
1414

15+
eleventyConfig.addFilter("isoDateTime", (dateObj) => {
16+
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
17+
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd HH:ii:ss');
18+
});
19+
1520
// Get the first `n` elements of a collection.
1621
eleventyConfig.addFilter("head", (array, n) => {
1722
if(!Array.isArray(array) || array.length === 0) {
@@ -25,9 +30,12 @@ export default function(eleventyConfig) {
2530
});
2631

2732
// Return the smallest number argument
28-
eleventyConfig.addFilter("min", (...numbers) => {
33+
eleventyConfig.addFilter("min", (numbers) => {
2934
return Math.min.apply(null, numbers);
3035
});
36+
eleventyConfig.addFilter("max", (numbers) => {
37+
return Math.max.apply(null, numbers);
38+
});
3139

3240
// Return the keys used in an object
3341
eleventyConfig.addFilter("getKeys", target => {

_config/shortcodes.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import Image from "@11ty/eleventy-img"
2-
31
export default function(eleventyConfig) {
4-
eleventyConfig.addShortcode("currentBuildDate", () => {
5-
return (new Date()).toISOString();
6-
});
72
};
83

_includes/layouts/base.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
{% include "partials/footer.njk" %}
3636

37-
<!-- This page `{{ page.url | absoluteUrl(metadata.url) }}` was built on {% currentBuildDate %} -->
37+
<!-- This page `{{ page.url | absoluteUrl(metadata.url) }}` was built on {{ renderDate | isoDateTime }} -->
3838
<script type="module" src="{% getBundleFileUrl "js" %}"></script>
3939
</body>
4040
</html>

_includes/layouts/post.njk

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,33 @@ layout: layouts/base.njk
3838
}
3939

4040
{%- endcss %}
41-
<h1>{{ title }}</h1>
41+
<article>
42+
<h1>{{ title }}</h1>
4243

43-
<ul class="post-metadata">
44-
<div>
45-
<i class="fa-regular fa-calendar"></i>
46-
<time datetime="{{ page.date | htmlDateString }}">{{ page.date | readableDate }}</time>
47-
</div>
48-
<div data-words="{{ content | striptags | wordcount | formatWords }} words">
49-
<i class="fa-regular fa-clock"></i>
50-
{{ content | striptags | wordcount | readingTime }}
51-
</div>
52-
<div>
53-
<i class="fa-solid fa-tags"></i>
54-
{%- for tag in tags | filterTagList %}
55-
{%- set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
56-
<span class="tag"><a href="{{ tagUrl }}">{{ tag }}</a></span>
57-
{%- endfor %}
58-
</div>
59-
</ul>
44+
<ul class="post-metadata">
45+
<div>
46+
<i class="fa-regular fa-calendar"></i>
47+
<time datetime="{{ page.date | isoDate }}">{{ page.date | readableDate }}</time>
48+
</div>
49+
<div data-words="{{ content | striptags | wordcount | formatWords }} words">
50+
<i class="fa-regular fa-clock"></i>
51+
{{ content | striptags | wordcount | readingTime }}
52+
</div>
53+
<div>
54+
<i class="fa-solid fa-tags"></i>
55+
{%- for tag in tags | filterTagList %}
56+
{%- set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
57+
<span class="tag"><a href="{{ tagUrl }}">{{ tag }}</a></span>
58+
{%- endfor %}
59+
</div>
60+
</ul>
6061

61-
{%- if image %}
62-
<img src="{{ image }}" alt="" class="post-header" />
63-
{% endif %}
62+
{%- if image %}
63+
<img src="{{ image }}" alt="" class="post-header" />
64+
{% endif %}
6465

65-
{{ content | safe }}
66+
{{ content | safe }}
67+
</article>
6668

6769
{% include "partials/socials.njk" %}
6870

_includes/partials/footer.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
footer {
33
position: sticky;
44
bottom: 0;
5+
margin-top: 1.5rem;
56
padding: 0.5em;
67
background-color: var(--bg-color-secondary);
78
transition: background-color 0.3s, color 0.3s;

_includes/partials/head.njk

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,46 @@
88
<meta name="author" content="{{ metadata.author.name }}" />
99
<link rel="canonical" href="{{ page.url | absoluteUrl(metadata.url) }}" />
1010

11+
<script type="application/ld+json">
12+
{
13+
"@context": "https://schema.org",
14+
"@type": "BlogPosting",
15+
"mainEntityOfPage": {
16+
"@type": "WebPage",
17+
"@id": "{{ metadata.url }}"
18+
},
19+
"headline": "{{ title or metadata.title }}",
20+
"description": "{{ description or metadata.description }}",
21+
{% if image %}"image": "{{ page.url | absoluteUrl(metadata.url) }}{{ image }}",{% endif %}
22+
"author": {
23+
"@type": "Person",
24+
"name": "{{ metadata.author.name }}"
25+
},
26+
"publisher": {
27+
"@type": "Organization",
28+
"name": "{{ metadata.title }}",
29+
"logo": {
30+
"@type": "ImageObject",
31+
"url": "{{ metadata.logo | absoluteUrl(metadata.url) }}"
32+
}
33+
},
34+
"datePublished": "{{ date | isoDate }}",
35+
"dateModified": "{{ renderDate | isoDate }}"
36+
}
37+
</script>
38+
1139
{% favicons 'public/img/icon.svg' %}
1240

1341
<meta property="og:url" content="{{ page.url | absoluteUrl(metadata.url) }}">
1442
<meta property="og:type" content="website">
1543
<meta property="og:title" content="{% if title %}{{ title }} | {% endif %}{{ metadata.title }}">
1644
<meta property="og:description" content="{% if description %}{{ description }}{% else %}{{ metadata.description }}{% endif %}">
45+
{% if image %}<meta property="og:image" content="{{ page.url | absoluteUrl(metadata.url) }}{{ image }}" />{% endif %}
1746

1847
<meta property="twitter:card" content="summary_large_image">
1948
<meta name="twitter:title" content="{% if title %}{{ title }} | {% endif %}{{ metadata.title }}" />
2049
<meta name="twitter:description" content="{{ description or metadata.description }}" />
50+
{% if image %}<meta name="twitter:image" content="{{ page.url | absoluteUrl(metadata.url) }}{{ image }}" />{% endif %}
2151

2252
<meta name="robots" content="index, follow" />
2353
<link rel="alternate" href="{{ 'feed/feed.xml' | absoluteUrl(metadata.url) }}" type="application/atom+xml" title="{{ metadata.title }}">

_includes/partials/pagination.njk

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@
4040
}
4141
{% endcss %}
4242

43-
{%- set totalPages = pagination.pages|length -%}
44-
{%- set currentPage = pagination.pageNumber + 1 -%}
45-
{%- set previousHref = pagination.href.previous -%}
46-
{%- set nextHref = pagination.href.next -%}
47-
48-
{% if totalPages > 1 %}
49-
43+
{% if pagination.pages.length > 1 %}
44+
{% set pageIndexStart = [pagination.pageNumber - 2, 0] | max %}
45+
{% set pageIndexEnd = [pagination.pageNumber + 2, pagination.pages.length - 1] | min %}
5046
<nav class="pagination">
5147
<ul>
5248
{% if pagination.pageNumber > 0 %}
@@ -66,15 +62,13 @@
6662
</li>
6763
{% endif %}
6864

69-
{% for pageEntry in pagination.pages %}
70-
{% if loop.index0 < 6 and pagination.hrefs[loop.index0 + pagination.pageNumber] %}
71-
<li class="{% if pagination.hrefs[loop.index0 + pagination.pageNumber] === page.url %}active{% endif %}">
72-
<a href="{{ pagination.hrefs[loop.index0 + pagination.pageNumber] }}">{{ loop.index + pagination.pageNumber }}</a>
73-
</li>
74-
{% endif %}
65+
{% for i in range(pageIndexStart, pageIndexEnd + 1) %}
66+
<li class="{% if i == pagination.pageNumber %}active{% endif %}">
67+
<a href="{{ pagination.hrefs[i] }}">{{ i + 1 }}</a>
68+
</li>
7569
{% endfor %}
7670

77-
{% if (pagination.pageNumber + 5) < pagination.pages.length %}
71+
{% if (pagination.pageNumber + 1) < pagination.pages.length %}
7872
<li>
7973
<a href="{{ pagination.href.next }}">&gt;</a>
8074
</li>

_includes/partials/post-card.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="excerpt"><em>{{ post | excerpt | truncate(500) }}</em></div>
1212
<div class="flex post-card-meta">
1313
<div>
14-
<i class="fa-regular fa-calendar"></i> <time datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
14+
<i class="fa-regular fa-calendar"></i> <time datetime="{{ post.date | isoDate }}">{{ post.date | readableDate }}</time>
1515
</div>
1616
<div data-words="{{ post.templateContent | striptags | wordcount | formatWords }} words">
1717
<i class="fa-regular fa-clock"></i> {{ post.templateContent | striptags | wordcount | readingTime }}

content/404.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ eleventyExcludeFromCollections: true
44
---
55
# Content not found.
66

7-
Go to [homepage](index.njk).
7+
We couldn’t find the page you were looking for. Try returning to the [homepage](index.njk).

content/index.njk

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ eleventyNavigation:
44
order: 1
55
pagination:
66
data: collections.posts
7-
size: 4
7+
size: 3
88
reverse: true
99
permalink: "{% if pagination.pageNumber > 0 %}/page/{{ pagination.pageNumber + 1 }}{% endif %}/"
1010
canonical: /
1111
---
12-
<h1>Welcome to ByteAether!</h1>
13-
<p>Welcome to ByteAether, a space where technology meets curiosity. Whether you're here to explore the latest in .NET and C# development, deep-dive into the technical nuances of software engineering, or keep up with the newest releases from our open-source projects, you've come to the right place. ByteAether is more than just a blog - it's a gateway to tools, insights, and discussions for developers of all levels.</p>
12+
{% if pagination.pageNumber == 0 %}
13+
<h1>Welcome to ByteAether!</h1>
14+
<p>Welcome to ByteAether, a space where technology meets curiosity. Whether you're here to explore the latest in .NET and C# development, deep-dive into the technical nuances of software engineering, or keep up with the newest releases from our open-source projects, you've come to the right place. ByteAether is more than just a blog - it's a gateway to tools, insights, and discussions for developers of all levels.</p>
1415

15-
<p>Here, you'll find a mix of release announcements for our NuGet packages, technical explorations of problem-solving strategies, and practical tips to enhance your coding workflow. If you're curious about the person behind ByteAether, feel free to visit the <a href="/about">About Me</a> section, where I share more about my journey, passions, and the work I do. Thanks for stopping by - happy reading and coding!</p>
16+
<p>Here, you'll find a mix of release announcements for our NuGet packages, technical explorations of problem-solving strategies, and practical tips to enhance your coding workflow. If you're curious about the person behind ByteAether, feel free to visit the <a href="/about">About Me</a> section, where I share more about my journey, passions, and the work I do. Thanks for stopping by - happy reading and coding!</p>
17+
{% endif %}
1618

17-
<h1>{% if pagination.pageNumber == 0 %}Latest {% endif %}{{ pagination.items.count }} Post{% if pagination.items.count != 1 %}s{% endif %}</h1>
19+
<h1>
20+
{% if pagination.pageNumber == 0 %}
21+
Latest {{ pagination.items.length }} Post{% if pagination.items.length != 1 %}s{% endif %}
22+
{% else %}
23+
Post{% if pagination.items.length != 1 %}s{% endif %} {{ pagination.size * pagination.pageNumber + 1 }}{% if pagination.items.length != 1 %} - {{ pagination.size * (pagination.pageNumber + 1) }}{% endif %}
24+
{% endif %}
25+
</h1>
1826

1927
{% for post in pagination.items %}
2028
{% include "partials/post-card.njk" %}

0 commit comments

Comments
 (0)