Skip to content

Commit

Permalink
feat: add experimental JS, add proepr alt text to each image
Browse files Browse the repository at this point in the history
  • Loading branch information
ca057 committed Dec 28, 2024
1 parent 1ab87e6 commit 4b0ce26
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,34 @@ export default async function (eleventyConfig) {

eleventyConfig.addWatchTarget("src/**/_favicon.json");

eleventyConfig.addWatchTarget("src/**/*.css");
eleventyConfig.addBundle("css");
eleventyConfig.addWatchTarget("src/**/*.js");
eleventyConfig.addBundle("js");
eleventyConfig.addPassthroughCopy("src/_fonts");

eleventyConfig.addFilter("blurhashColorRgb", (blurhash) => `rgb(${getBlurHashAverageColor(blurhash).join(",")})`);
eleventyConfig.addFilter("formatDate", (date, locale = "en-UK") => {
return Temporal.PlainDate.from(date).toLocaleString(locale, { calendar: "gregory", dateStyle: "long" });
});
eleventyConfig.addFilter("formatOrdinals", (count) => {
// copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
const enOrdinalRules = new Intl.PluralRules("en-EN", { type: "ordinal" });

const suffixes = new Map([
["one", "st"],
["two", "nd"],
["few", "rd"],
["other", "th"],
]);
const formatOrdinals = (n) => {
const rule = enOrdinalRules.select(n);
const suffix = suffixes.get(rule);
return `${n}${suffix}`;
};

return formatOrdinals(count);
});

eleventyConfig.addPlugin(VentoPlugin);
await eleventyConfig.addPlugin(pluginMultipleFavicons, { configNamePattern: /_favicon\.json/ });
Expand Down
Binary file modified src/coffee/_favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/coffee/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ footer {
.nowrap {
white-space: nowrap;
}

.coffees img:hover,
.coffees img:active {
border: 2px solid blue;
}
9 changes: 8 additions & 1 deletion src/coffee/index.vto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
{{ include "css-reset.css" }}
{{ include "./index.css" }}
</style>
{{ js }}
{{ include "./overlay.js" }}
{{ /js }}
<script>
{{ getBundle "js" }}
</script>
</head>
<body>
<header>
Expand All @@ -44,6 +50,7 @@
{{ set allCoffees = coffees.images.toReversed() }}
{{ for index of allCoffees.length }}
{{ set coffee = allCoffees[index-1] }}
{{ set countOfDay = Number(coffee.id.slice(8)) + 1 }}
<img
id="{{ coffee.id }}"
style="background: {{ coffee.images.blurhash |> blurhashColorRgb }}"
Expand All @@ -52,7 +59,7 @@
height="300"
loading="{{ (index - 1) < 10 ? 'eager' : 'lazy' }}"
decoding="async"
alt="TODO"
alt="My {{ countOfDay |> formatOrdinals }} coffee from {{ coffee.day |> formatDate }}."
>
</img>
{{ /for }}
Expand Down
9 changes: 9 additions & 0 deletions src/coffee/overlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function addImgListeners() {
console.log(document.readyState);
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", addImgListeners);
} else {
addImgListeners();
}

0 comments on commit 4b0ce26

Please sign in to comment.