* feat: upgrade to v3; install eleventy-upgrade-help * feat: convert all files to esm * feat: remove decapcms * fix: remove unused filter * feat: remove netlify packages * feat: update image handling - removes old image shortcode - update to latest 11ty image transform plugin * feat: update colophon * fix: pill style; global style Fixes an issue with <img> inside <figure> not being centered * feat: remove linting packages * feat: update package.json scripts * feat: remove upgrade helper plugin * feat: add new button style, update nav * feat: simplify `pill` class usage * feat: fix tag list in catalogue-item.html * feat: move games into their own section * feat: update node version to latest LTS * feat: move books to their own section * feat: move fun pages into pages dir * feat: update index and book/game templates * feat: add watching section * fix: update scaling values for buttons * feat: various css updates * feat: update now page style * feat: cleaning up newer posts using old shortcode also adding markdown-it-attrs to add attrs to various markdown elements! * fix: movie data structure * feat: update colophon * fix: remove text-skew from post excerpt text * feat: add support for shows in /watching * fix: update book tags * feat: add complete implementation of books pages other stuff happened too * fix: image border-radius * feat: update game layout and content * feat: reorganize watching section * feat: add contact page * feat: small page changes * feat: add podroll page * feat: reorganize content directories * feat: exclude podcasts from page output * chore: delete guestbook page * chore: remove bracket syntax for css classes in html * feat: create macro for tag list * fix: colophon update * chore: remove last.fm data * chore: clean up 11ty config * fix: misc permalink fixes * feat: add update post * fix: media meta grid on mobile * fix: tables on mobile * fix: add titles to icon button links * fix: add missing divider for movies/shows * feat: add alternate feeds * fix: tag cleanup * feat: homepage content update * fix: game meta data * fix: update post dates * feat: add missing link to changelog
96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
import dayjs from "dayjs";
|
|
import utc from "dayjs/plugin/utc.js";
|
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
|
|
import pluralizeBase from "pluralize";
|
|
|
|
export const keys = Object.keys;
|
|
export const values = Object.values;
|
|
export const entries = Object.entries;
|
|
|
|
dayjs.extend(utc);
|
|
dayjs.extend(advancedFormat);
|
|
|
|
export const formatDate = (date, format) => dayjs.utc(date).format(format);
|
|
|
|
export const organizeByDate = (collection) => {
|
|
const collectionByDate = {};
|
|
|
|
collection.forEach((item) => {
|
|
const year = formatDate(item.date, "YYYY");
|
|
|
|
if (!collectionByDate[year]) {
|
|
return (collectionByDate[year] = [item]);
|
|
}
|
|
|
|
collectionByDate[year].push(item);
|
|
});
|
|
|
|
return collectionByDate;
|
|
};
|
|
|
|
export const transformByDate = (collection) => {
|
|
const collectionByDate = {};
|
|
|
|
collection.forEach((item) => {
|
|
const year = formatDate(item.date, "YYYY");
|
|
|
|
if (!collectionByDate[year]) {
|
|
return (collectionByDate[year] = { value: year, data: [item] });
|
|
}
|
|
|
|
collectionByDate[year].data.push(item);
|
|
});
|
|
|
|
return collectionByDate;
|
|
};
|
|
|
|
export const allTagCounts = (collection, ignore = ["post"]) => {
|
|
if (!collection.length) {
|
|
throw new Error("Invalid collection, no items");
|
|
}
|
|
|
|
const tagCounts = new Map();
|
|
|
|
for (const item of collection) {
|
|
const tags = item.data.tags;
|
|
|
|
tags?.forEach((tag) => tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1));
|
|
}
|
|
|
|
ignore.forEach((tag) => tagCounts.delete(tag));
|
|
|
|
const tagArray = Array.from(tagCounts.entries())
|
|
.map(([tag, count]) => ({
|
|
tag,
|
|
count,
|
|
}))
|
|
.sort((a, b) => b.count - a.count);
|
|
|
|
return tagArray;
|
|
};
|
|
|
|
export const filter = (collection, filters = []) => {
|
|
return collection.filter((item) => !filters.includes(item));
|
|
};
|
|
|
|
export const pluralize = (string, count = 0) => {
|
|
return pluralizeBase(string, count);
|
|
};
|
|
|
|
export const limit = (collection, limit = 5) => collection.slice(0, limit);
|
|
|
|
export const filterFavourites = (collection) => {
|
|
return collection.filter(
|
|
(item) => item.data.favourite || item.data.isFavourite,
|
|
);
|
|
};
|
|
|
|
export const isOld = (dateArg) => {
|
|
const date = dayjs(dateArg);
|
|
const now = dayjs();
|
|
|
|
const diffInYears = now.diff(date, "years");
|
|
|
|
return diffInYears >= 2;
|
|
};
|