Reformatting

This commit is contained in:
2024-11-04 23:23:20 +00:00
parent bdcc7cea6a
commit 232599a7f8
18 changed files with 140 additions and 100 deletions

3
.prettierrc Normal file
View File

@@ -0,0 +1,3 @@
{
"trailingComma": "none"
}

View File

@@ -1,22 +1,26 @@
import { DateTime } from "luxon";
export default function(eleventyConfig) {
export default function (eleventyConfig) {
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(
format || "dd LLLL yyyy"
);
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd');
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(
"yyyy-LL-dd"
);
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if(!Array.isArray(array) || array.length === 0) {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
if( n < 0 ) {
if (n < 0) {
return array.slice(n);
}
@@ -29,12 +33,13 @@ export default function(eleventyConfig) {
});
// Return the keys used in an object
eleventyConfig.addFilter("getKeys", target => {
eleventyConfig.addFilter("getKeys", (target) => {
return Object.keys(target);
});
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "posts"].indexOf(tag) === -1);
return (tags || []).filter(
(tag) => ["all", "posts"].indexOf(tag) === -1
);
});
};
}

View File

@@ -1,13 +1,15 @@
import { z } from "zod";
import { fromZodError } from 'zod-validation-error';
import { fromZodError } from "zod-validation-error";
export default function(data) {
export default function (data) {
// Draft content, validate `draft` front matter
let result = z.object({
draft: z.boolean().or(z.undefined()),
}).safeParse(data);
let result = z
.object({
draft: z.boolean().or(z.undefined())
})
.safeParse(data);
if(result.error) {
if (result.error) {
throw fromZodError(result.error);
}
}

View File

@@ -8,4 +8,4 @@ export default {
email: "chris@kaczor.us",
url: "https://chriskaczor.com/about/"
}
}
};

View File

@@ -33,7 +33,9 @@
{# {%- css %}{% include "node_modules/prismjs/themes/prism-okaidia.css" %}{% endcss %} #}
{#- Render the CSS bundle using inlined CSS (for the fastest site performance in production) #}
<style>{% getBundle "css" %}</style>
<style>
{% getBundle "css" %}
</style>
{#- Renders the CSS bundle using a separate file, if you can't set CSP directive style-src: 'unsafe-inline' #}
{#- <link rel="stylesheet" href="{% getBundleFileUrl "css" %}"> #}
@@ -50,9 +52,11 @@
<nav>
<h2 class="visually-hidden">Top level navigation menu</h2>
<ul class="nav">
{%- for entry in collections.all | eleventyNavigation %}
<li class="nav-item"><a href="{{ entry.url }}"{% if entry.url == page.url %} aria-current="page"{% endif %}>{{ entry.title }}</a></li>
{%- endfor %}
{%- for entry in collections.all | eleventyNavigation %}
<li class="nav-item">
<a href="{{ entry.url }}"{% if entry.url == page.url %} aria-current="page"{% endif %}>{{ entry.title }}</a>
</li>
{%- endfor %}
</ul>
</nav>
</header>
@@ -64,10 +68,13 @@
</main>
<footer>
<p><em>Built with <a href="https://www.11ty.dev/">{{ eleventy.generator }}</a></em></p>
<p>
<em>Built with <a href="https://www.11ty.dev/">{{ eleventy.generator }}</a>
</em>
</p>
</footer>
<!-- This page `{{ page.url | htmlBaseUrl }}` was built on {% currentBuildDate %} -->
<script type="module" src="{% getBundleFileUrl "js" %}"></script>
</body>
</html>
</html>

View File

@@ -2,4 +2,4 @@
layout: layouts/base.njk
---
{{ content | safe }}
{{ content | safe }}

View File

@@ -7,22 +7,35 @@ layout: layouts/base.njk
<h1>{{ title }}</h1>
<ul class="post-metadata">
<li><time datetime="{{ page.date | htmlDateString }}">{{ page.date | readableDate }}</time></li>
<li>
<time datetime="{{ page.date | htmlDateString }}">{{ page.date | readableDate }}</time>
</li>
{%- for tag in tags | filterTagList %}
{%- set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
<li><a href="{{ tagUrl }}" class="post-tag">{{ tag }}</a>{%- if not loop.last %}, {% endif %}</li>
{%- set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
<li>
<a href="{{ tagUrl }}" class="post-tag">{{ tag }}</a>
{%- if not loop.last %}, {% endif %}
</li>
{%- endfor %}
</ul>
{{ content | safe }}
{%- if collections.posts %}
{%- set previousPost = collections.posts | getPreviousCollectionItem %}
{%- set nextPost = collections.posts | getNextCollectionItem %}
{%- if nextPost or previousPost %}
<ul class="links-nextprev">
{%- if previousPost %}<li class="links-nextprev-prev">← Previous<br> <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li class="links-nextprev-next">Next →<br><a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a></li>{% endif %}
</ul>
{%- endif %}
{%- endif %}
{%- set previousPost = collections.posts | getPreviousCollectionItem %}
{%- set nextPost = collections.posts | getNextCollectionItem %}
{%- if nextPost or previousPost %}
<ul class="links-nextprev">
{%- if previousPost %}
<li class="links-nextprev-prev">← Previous<br>
<a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a>
</li>
{% endif %}
{%- if nextPost %}
<li class="links-nextprev-next">Next →<br>
<a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a>
</li>
{% endif %}
</ul>
{%- endif %}
{%- endif %}

View File

@@ -1,9 +1,14 @@
{%- css %}.postlist { counter-reset: start-from {{ (postslistCounter or postslist.length) + 1 }} }{% endcss %}
<ol reversed class="postlist">
{% for post in postslist | reverse %}
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}">
<a href="{{ post.url }}" class="postlist-link">{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}</a>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate("LLLL yyyy") }}</time>
</li>
{% endfor %}
</ol>
{% for post in postslist | reverse %}
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}">
<a href="{{ post.url }}" class="postlist-link">
{% if post.data.title %}{{ post.data.title }}
{% else %}
<code>{{ post.url }}</code>
{% endif %}
</a>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate("LLLL yyyy") }}</time>
</li>
{% endfor %}
</ol>

View File

@@ -7,4 +7,4 @@ const eleventyNavigation = {
<h1>Archive</h1>
{% set postslist = collections.posts %}
{% include "postslist.njk" %}
{% include "postslist.njk" %}

View File

@@ -1,3 +1,3 @@
export default {
layout: "layouts/home.njk",
layout: "layouts/home.njk"
};

View File

@@ -8,7 +8,8 @@ const numberOfLatestPostsToShow = 3;
---
{% set postsCount = collections.posts | length %}
{% set latestPostsCount = postsCount | min(numberOfLatestPostsToShow) %}
<h1>Latest {{ latestPostsCount }} Post{% if latestPostsCount != 1 %}s{% endif %}</h1>
<h1>Latest {{ latestPostsCount }} Post{% if latestPostsCount != 1 %}s{% endif %}
</h1>
{% set postslist = collections.posts | head(-1 * numberOfLatestPostsToShow) %}
{% set postslistCounter = postsCount %}
@@ -16,7 +17,7 @@ const numberOfLatestPostsToShow = 3;
{% set morePosts = postsCount - numberOfLatestPostsToShow %}
{% if morePosts > 0 %}
<p>{{ morePosts }} more post{% if morePosts != 1 %}s{% endif %} can be found in <a href="blog.njk">the archive</a>.</p>
<p>{{ morePosts }} more post{% if morePosts != 1 %}s{% endif %} can be found in <a href="blog.njk">the archive</a>.</p>
{% endif %}
{# List every content page in the project #}
@@ -26,4 +27,4 @@ const numberOfLatestPostsToShow = 3;
<li><a href="{{ entry.url }}"><code>{{ entry.url }}</code></a></li>
{%- endfor %}
</ul>
#}
#}

View File

@@ -5,11 +5,11 @@ eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{%- for page in collections.all %}
{% set absoluteUrl %}{{ page.url | htmlBaseUrl(metadata.url) }}{% endset %}
<url>
<loc>{{ absoluteUrl }}</loc>
<lastmod>{{ page.date | htmlDateString }}</lastmod>
</url>
{%- endfor %}
</urlset>
{%- for page in collections.all %}
{% set absoluteUrl %}{{ page.url | htmlBaseUrl(metadata.url) }}{% endset %}
<url>
<loc>{{ absoluteUrl }}</loc>
<lastmod>{{ page.date | htmlDateString }}</lastmod>
</url>
{%- endfor %}
</urlset>

View File

@@ -19,7 +19,7 @@ const eleventyComputed = {
---
<h1>Tagged “{{ tag }}”</h1>
{% set postslist = collections[ tag ] %}
{% set postslist = collections[tag] %}
{% include "postslist.njk" %}
<p>See <a href="tags.njk">all tags</a>.</p>
<p>See <a href="tags.njk">all tags</a>.</p>

View File

@@ -1,8 +1,10 @@
<h1>Tags</h1>
<ul>
{% for tag in collections | getKeys | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
<li><a href="{{ tagUrl }}" class="post-tag">{{ tag }}</a></li>
{% endfor %}
</ul>
{% for tag in collections | getKeys | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slugify }}/{% endset %}
<li>
<a href="{{ tagUrl }}" class="post-tag">{{ tag }}</a>
</li>
{% endfor %}
</ul>

View File

@@ -1,4 +1,8 @@
import { IdAttributePlugin, InputPathToUrlTransformPlugin, HtmlBasePlugin } from "@11ty/eleventy";
import {
IdAttributePlugin,
InputPathToUrlTransformPlugin,
HtmlBasePlugin
} from "@11ty/eleventy";
import { feedPlugin } from "@11ty/eleventy-plugin-rss";
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import pluginNavigation from "@11ty/eleventy-navigation";
@@ -7,10 +11,10 @@ import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import pluginFilters from "./_config/filters.js";
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function(eleventyConfig) {
export default async function (eleventyConfig) {
// Drafts, see also _data/eleventyDataSchema.js
eleventyConfig.addPreprocessor("drafts", "*", (data, content) => {
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
if (data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
return false;
}
});
@@ -34,11 +38,11 @@ export default async function(eleventyConfig) {
// Per-page bundles, see https://github.com/11ty/eleventy-plugin-bundle
// Adds the {% css %} paired shortcode
eleventyConfig.addBundle("css", {
toFileDirectory: "dist",
toFileDirectory: "dist"
});
// Adds the {% js %} paired shortcode
eleventyConfig.addBundle("js", {
toFileDirectory: "dist",
toFileDirectory: "dist"
});
// Official plugins
@@ -61,7 +65,7 @@ export default async function(eleventyConfig) {
},
collection: {
name: "posts",
limit: 10,
limit: 10
},
metadata: {
language: "en",
@@ -87,7 +91,7 @@ export default async function(eleventyConfig) {
defaultAttributes: {
// e.g. <img loading decoding> assigned on the HTML tag will override these values.
loading: "lazy",
decoding: "async",
decoding: "async"
}
});
@@ -101,7 +105,7 @@ export default async function(eleventyConfig) {
});
eleventyConfig.addShortcode("currentBuildDate", () => {
return (new Date()).toISOString();
return new Date().toISOString();
});
eleventyConfig.amendLibrary("md", (mdLib) => {
@@ -127,9 +131,11 @@ export default async function(eleventyConfig) {
return defaultImageRender(tokens, idx, options, env, self);
};
var defaultLinkOpenRender = mdLib.renderer.rules.link_open || function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
var defaultLinkOpenRender =
mdLib.renderer.rules.link_open ||
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
mdLib.renderer.rules.link_open = function (
tokens,
@@ -150,7 +156,6 @@ export default async function(eleventyConfig) {
return defaultLinkOpenRender(tokens, idx, options, env, self);
};
});
// Features to make your build faster (when you need them)
@@ -160,18 +165,12 @@ export default async function(eleventyConfig) {
// https://www.11ty.dev/docs/copy/#emulate-passthrough-copy-during-serve
// eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
};
}
export const config = {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: [
"md",
"njk",
"html",
"liquid",
"11ty.js",
],
templateFormats: ["md", "njk", "html", "liquid", "11ty.js"],
// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: "njk",
@@ -181,11 +180,11 @@ export const config = {
// These are all optional:
dir: {
input: "content", // default: "."
includes: "../_includes", // default: "_includes" (`input` relative)
data: "../_data", // default: "_data" (`input` relative)
input: "content", // default: "."
includes: "../_includes", // default: "_includes" (`input` relative)
data: "../_data", // default: "_data" (`input` relative)
output: "_site"
},
}
// -----------------------------------------------------------------
// Optional items:

View File

@@ -1,13 +1,16 @@
/* Defaults */
:root {
--font-family: Roboto, -apple-system, system-ui, sans-serif;
--font-family-monospace: Consolas, Menlo, Monaco, Andale Mono WT, Andale Mono, Lucida Console, Lucida Sans Typewriter, DejaVu Sans Mono, Bitstream Vera Sans Mono, Liberation Mono, Nimbus Mono L, Courier New, Courier, monospace;
--font-family-monospace: Consolas, Menlo, Monaco, Andale Mono WT,
Andale Mono, Lucida Console, Lucida Sans Typewriter, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Liberation Mono, Nimbus Mono L, Courier New,
Courier, monospace;
}
/* Theme colors */
:root {
--color-gray-20: #e0e0e0;
--color-gray-50: #C0C0C0;
--color-gray-50: #c0c0c0;
--color-gray-90: #333;
--background-color: #fff;
@@ -15,7 +18,7 @@
--text-color: var(--color-gray-90);
--text-color-link: #082840;
--text-color-link-active: #5f2b48;
--text-color-link-visited: #17050F;
--text-color-link-visited: #17050f;
--syntax-tab-size: 2;
}
@@ -23,7 +26,7 @@
@media (prefers-color-scheme: dark) {
:root {
--color-gray-20: #e0e0e0;
--color-gray-50: #C0C0C0;
--color-gray-50: #c0c0c0;
--color-gray-90: #dad8d8;
/* --text-color is assigned to --color-gray-_ above */
@@ -35,7 +38,6 @@
}
}
/* Global stylesheet */
* {
box-sizing: border-box;
@@ -113,7 +115,7 @@ header:after {
.links-nextprev {
display: flex;
justify-content: space-between;
gap: .5em 1em;
gap: 0.5em 1em;
list-style: "";
border-top: 1px dashed var(--color-gray-20);
padding: 1em 0;
@@ -138,7 +140,7 @@ code {
font-family: var(--font-family-monospace);
}
pre:not([class*="language-"]) {
margin: .5em 0;
margin: 0.5em 0;
line-height: 1.375; /* 22px /16 */
-moz-tab-size: var(--syntax-tab-size);
-o-tab-size: var(--syntax-tab-size);
@@ -160,7 +162,7 @@ code {
/* Header */
header {
display: flex;
gap: 1em .5em;
gap: 1em 0.5em;
flex-wrap: wrap;
align-items: center;
padding: 1em;
@@ -226,8 +228,8 @@ header {
font-size: 1.1875em; /* 19px /16 */
font-weight: 700;
flex-basis: calc(100% - 1.5rem);
padding-left: .25em;
padding-right: .5em;
padding-left: 0.25em;
padding-right: 0.5em;
text-underline-position: from-font;
text-underline-offset: 0;
text-decoration-thickness: 1px;
@@ -252,7 +254,7 @@ header {
.post-metadata {
display: inline-flex;
flex-wrap: wrap;
gap: .5em;
gap: 0.5em;
list-style: none;
padding: 0;
margin: 0;
@@ -260,4 +262,3 @@ header {
.post-metadata time {
margin-right: 1em;
}

View File

@@ -31,7 +31,7 @@ pre[class*="language-diff-"] {
.token.prefix.inserted,
.token.prefix.deleted {
width: var(--eleventy-code-padding);
background-color: rgba(0,0,0,.2);
background-color: rgba(0, 0, 0, 0.2);
}
/* Optional: full-width background color */

View File

@@ -1 +1,3 @@
{ "trailingSlash": true }
{
"trailingSlash": true
}