Skip to content

Commit 11985d9

Browse files
committed
Favicons and meta images
1 parent de3458e commit 11985d9

File tree

6 files changed

+161
-5
lines changed

6 files changed

+161
-5
lines changed

_layouts/base.liquid

+20-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
<html lang="{{ metadata.language }}">
77
<head>
88
<meta charset="utf-8">
9-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no">
1010
<title>{{ fullTitle }}</title>
1111
<meta name="description" content="{{ description or metadata.description }}">
1212
<meta name="generator" content="{{ eleventy.generator }}">
1313

14+
<meta name="og:title" content="{{ fullTitle }}">
15+
<meta name="og:description" content="{{ description or metadata.description }}">
16+
<meta name="og:type" content="website">
17+
<meta name="og:url" content="{{ page.url }}">
18+
{% ogImage metaImage %}
19+
{% favicons 'content/images/logo.svg' %}
20+
1421
<link rel="alternate" href="/feed/feed.xml" type="application/atom+xml" title="{{ fullTitle }}">
1522
<link rel="alternate" href="/feed/feed.json" type="application/json" title="{{ fullTitle }}">
1623

@@ -29,13 +36,13 @@
2936
<body>
3037
<a href="#skip" class="visually-hidden">Skip to main content</a>
3138

32-
<div class="flex flex-col justify-between h-full max-w-[var(--width-content)] px-[0.8rem] my-0 mx-auto">
39+
<div class="flex flex-col justify-between h-full max-w-[var(--width-content)] px-[0.8rem] my-0 mx-auto min-h-screen">
3340
<div>
3441
<header class="mt-4 mb-8 flex items-center justify-between">
3542
<nav>
3643
<h2 class="visually-hidden">Top level navigation menu</h2>
3744

38-
<ul class="flex items-center m-0">
45+
<ul class="flex items-center m-0 font-grotesk font-medium text-textSecondary lowercase">
3946
<li class="mr-6">
4047
<a href="/">
4148
<img src="/images/logo.svg" width="64" height="64" class="m-0" alt="Andrew Branch">
@@ -45,7 +52,7 @@
4552
<li class="pt-4">
4653
<a
4754
href="/about"
48-
class="font-grotesk text-textSecondary lowercase no-underline hover:underline"
55+
class="{% if entry.url != '/about' %}no-underline hover:underline{% endif %}"
4956
{% if entry.url == '/about' %}
5057
aria-current="page"
5158
{% endif %}
@@ -66,7 +73,15 @@
6673
{{ content }}
6774
</main>
6875
</div>
69-
<footer></footer>
76+
77+
<footer class="mt-8">
78+
<p class="font-grotesk text-center text-textSecondary">
79+
<small
80+
>&copy; {{ 'now' | date: '%Y' }} Andrew Branch / Licensed under
81+
<a href="http://creativecommons.org/licenses/by/4.0/legalcode">CC-BY-4.0</a></small
82+
>
83+
</p>
84+
</footer>
7085
</div>
7186
</body>
7287
</html>

content/images/favicon.png

-13.6 KB
Binary file not shown.

content/styles/uno.css

+3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
.mr-6{margin-right:calc(var(--rhythm) * .25rem * 6);}
2828
.ms{margin-inline-start:1rem;}
2929
.mt-4{margin-top:calc(var(--rhythm) * .25rem * 4);}
30+
.mt-8{margin-top:calc(var(--rhythm) * .25rem * 8);}
3031
.block{display:block;}
3132
.contents{display:contents;}
3233
.h-full{height:100%;}
3334
.max-w-\[var\(--width-content\)\]{max-width:var(--width-content);}
35+
.min-h-screen{min-height:100vh;}
3436
.flex{display:flex;}
37+
.shrink-to-fit\=no{flex-shrink:1;}
3538
.grow{flex-grow:1;}
3639
.flex-col{flex-direction:column;}
3740
.items-center{align-items:center;}

eleventy.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const getImageSize = require("image-size").default;
66
const anchor = require("markdown-it-anchor").default;
77
const { loadTheme } = require("shiki");
88
const shikiMarkdown = require("markdown-it-shiki").default;
9+
const faviconsPlugin = require("eleventy-plugin-gen-favicons");
910

1011
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
1112
module.exports = (eleventyConfig) => {
@@ -37,9 +38,34 @@ module.exports = (eleventyConfig) => {
3738
eleventyConfig.addPassthroughCopy("content/images");
3839
eleventyConfig.addPassthroughCopy("content/styles/fonts");
3940
eleventyConfig.addPassthroughCopy("content/_redirects");
41+
eleventyConfig.addPassthroughCopy({
42+
"node_modules/katex/dist/fonts": "bundle/fonts",
43+
});
4044

4145
eleventyConfig.addWatchTarget("./content/*.css");
4246

47+
eleventyConfig.addAsyncShortcode("ogImage", async function (src) {
48+
if (src) {
49+
const originalPath = relativeToInputPath(this.page.inputPath, src);
50+
const metadata = await eleventyImage(originalPath, {
51+
widths: [1200],
52+
formats: ["jpeg"],
53+
outputDir: "public/img",
54+
});
55+
const jpeg = metadata.jpeg[0];
56+
const url = new URL(jpeg.url, new URL("https://blog.andrewbran.ch"));
57+
return `<meta property="og:image" content="${url.toString()}" />`;
58+
} else {
59+
const metadata = await eleventyImage(path.join(__dirname, "content/images/logo.svg"), {
60+
widths: [1200],
61+
formats: ["png"],
62+
outputDir: "public/img",
63+
});
64+
const png = metadata.png[0];
65+
const url = new URL(png.url, new URL("https://blog.andrewbran.ch"));
66+
return `<meta property="og:image" content="${url.toString()}" />`;
67+
}
68+
});
4369
eleventyConfig.addAsyncShortcode("image", async function (src, alt, className, widths, sizes) {
4470
widths = Array.isArray(widths) ? widths : [widths || "auto"];
4571
const originalPath = relativeToInputPath(this.page.inputPath, src);
@@ -99,6 +125,10 @@ module.exports = (eleventyConfig) => {
99125
});
100126
});
101127

128+
eleventyConfig.addPlugin(faviconsPlugin, {
129+
outputDir: "public",
130+
});
131+
102132
return {
103133
dir: {
104134
input: "content",

package-lock.json

+107
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@shopify/prettier-plugin-liquid": "^1.3.4",
2222
"@unocss/cli": "^0.57.2",
2323
"@unocss/reset": "^0.57.2",
24+
"eleventy-plugin-gen-favicons": "^1.1.2",
2425
"image-size": "*",
2526
"katex": "^0.16.9",
2627
"markdown-it-anchor": "^8.6.7",

0 commit comments

Comments
 (0)