feat(*.liquid): apply prettier to liquid templates

- offer to create tag when none is found while adding a link from cli
- fix tag display in search
This commit is contained in:
Cory Dransfeldt 2025-06-16 14:40:54 -07:00
parent 49e21d574e
commit efe701f939
No known key found for this signature in database
112 changed files with 1319 additions and 1134 deletions

View file

@ -1,4 +1,4 @@
import ics from 'ics';
import ics from "ics";
export const albumReleasesCalendar = (collection) => {
const collectionData = collection.getAll()[0];
@ -8,7 +8,7 @@ export const albumReleasesCalendar = (collection) => {
globals: { url }
} = data;
if (!all || all.length === 0) return '';
if (!all || all.length === 0) return "";
const events = all
.map((album) => {
@ -16,15 +16,15 @@ export const albumReleasesCalendar = (collection) => {
if (isNaN(date.getTime())) return null;
const albumUrl = album.url?.includes('http') ? album.url : `${url}${album.url}`;
const artistUrl = album.artist.url?.includes('http')
const albumUrl = album.url?.includes("http") ? album.url : `${url}${album.url}`;
const artistUrl = album.artist.url?.includes("http")
? album.artust.url
: `${url}${album.artist.url}`;
return {
start: [date.getFullYear(), date.getMonth() + 1, date.getDate()],
startInputType: 'local',
startOutputType: 'local',
startInputType: "local",
startOutputType: "local",
title: `Release: ${album.artist.name} - ${album.title}`,
description: `Check out this new album release: ${albumUrl}. Read more about ${album.artist.name} at ${artistUrl}`,
url: albumUrl,
@ -34,12 +34,12 @@ export const albumReleasesCalendar = (collection) => {
.filter((event) => event !== null);
const { error, value } = ics.createEvents(events, {
calName: 'Album releases calendar • coryd.dev'
calName: "Album releases calendar • coryd.dev"
});
if (error) {
console.error('Error creating events: ', error);
return '';
console.error("Error creating events: ", error);
return "";
}
return value;

View file

@ -1,9 +1,9 @@
import fs from 'fs';
import path from 'path';
import { minify } from 'terser';
import fs from "fs";
import path from "path";
import { minify } from "terser";
export const minifyJsComponents = async () => {
const scriptsDir = 'dist/assets/scripts';
const scriptsDir = "dist/assets/scripts";
const minifyJsFilesInDir = async (dir) => {
const files = fs.readdirSync(dir);
@ -13,8 +13,8 @@ export const minifyJsComponents = async () => {
if (stat.isDirectory()) {
await minifyJsFilesInDir(filePath);
} else if (fileName.endsWith('.js')) {
const fileContent = fs.readFileSync(filePath, 'utf8');
} else if (fileName.endsWith(".js")) {
const fileContent = fs.readFileSync(filePath, "utf8");
const minified = await minify(fileContent);
if (minified.error) {

View file

@ -1,4 +1,4 @@
import * as cheerio from 'cheerio';
import * as cheerio from "cheerio";
export default {
convertRelativeLinks: (htmlContent, domain) => {
@ -6,32 +6,32 @@ export default {
const $ = cheerio.load(htmlContent);
$('a[href]').each((_, link) => {
$("a[href]").each((_, link) => {
const $link = $(link);
let href = $link.attr('href');
let href = $link.attr("href");
if (href.startsWith('#')) {
$link.replaceWith($('<span>').text($link.text()));
} else if (!href.startsWith('http://') && !href.startsWith('https://')) {
const normalizedDomain = domain.replace(/\/$/, '');
const normalizedHref = href.replace(/^\/+/, '');
$link.attr('href', `${normalizedDomain}/${normalizedHref}`);
if (href.startsWith("#")) {
$link.replaceWith($("<span>").text($link.text()));
} else if (!href.startsWith("http://") && !href.startsWith("https://")) {
const normalizedDomain = domain.replace(/\/$/, "");
const normalizedHref = href.replace(/^\/+/, "");
$link.attr("href", `${normalizedDomain}/${normalizedHref}`);
}
});
return $.html();
},
generatePermalink: (url, baseUrl) => {
if (url?.includes('http') || !baseUrl) return url;
if (url?.includes("http") || !baseUrl) return url;
return `${baseUrl}${url}`;
},
getRemoteFileSize: async (url) => {
try {
const response = await fetch(url, { method: 'HEAD' });
const response = await fetch(url, { method: "HEAD" });
if (!response.ok) return 0;
const contentLength = response.headers.get('content-length');
const contentLength = response.headers.get("content-length");
if (!contentLength) return 0;

View file

@ -1,22 +1,22 @@
import truncateHtml from 'truncate-html';
import truncateHtml from "truncate-html";
export default {
encodeAmp: (string) => {
if (!string) return;
const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g;
const replacement = '&amp;';
const replacement = "&amp;";
return string.replace(pattern, replacement);
},
replaceQuotes: (string) => {
if (!string) return '';
return string.replace(/"/g, '&quot;');
if (!string) return "";
return string.replace(/"/g, "&quot;").replace(/'/g, "&#39;");
},
htmlTruncate: (content, limit = 50) =>
truncateHtml(content, limit, {
byWords: true,
ellipsis: '...'
ellipsis: "..."
}),
shuffleArray: (array) => {
const shuffled = [...array];
@ -32,12 +32,12 @@ export default {
},
mergeArray: (a, b) => (Array.isArray(a) && Array.isArray(b) ? [...new Set([...a, ...b])] : []),
pluralize: (count, string, trailing) => {
const countStr = String(count).replace(/,/g, '');
const countStr = String(count).replace(/,/g, "");
if (parseInt(countStr, 10) === 1) return string;
return `${string}s${trailing ? `${trailing}` : ''}`;
return `${string}s${trailing ? `${trailing}` : ""}`;
},
jsonEscape: (string) => JSON.stringify(string),
regexEscape: (string) => string.replace(/[.*+?^${}()[]\\]/g, '\\$&')
regexEscape: (string) => string.replace(/[.*+?^${}()[]\\]/g, "\\$&")
};

View file

@ -1,8 +1,8 @@
import feeds from './feeds.js';
import general from './general.js';
import media from './media.js';
import metadata from './metadata.js';
import navigation from './navigation.js';
import feeds from "./feeds.js";
import general from "./general.js";
import media from "./media.js";
import metadata from "./metadata.js";
import navigation from "./navigation.js";
export default {
...feeds,

View file

@ -7,12 +7,12 @@ export default {
.map(
(year, index) =>
`<a href="/reading/years/${year.value}">${year.value}</a>${
index < years.length - 1 ? ' • ' : ''
index < years.length - 1 ? " • " : ""
}`
)
.join(''),
.join(""),
mediaLinks: (data, type, count = 10) => {
if (!data || !type) return '';
if (!data || !type) return "";
const dataSlice = data.slice(0, count);
@ -20,21 +20,21 @@ export default {
const buildLink = (item) => {
switch (type) {
case 'genre':
case "genre":
return `<a href="${item.genre_url}">${item.genre_name}</a>`;
case 'artist':
case "artist":
return `<a href="${item.url}">${item.name}</a>`;
case 'book':
case "book":
return `<a href="${item.url}">${item.title}</a>`;
default:
return '';
return "";
}
};
if (dataSlice.length === 1) return buildLink(dataSlice[0]);
const links = dataSlice.map(buildLink);
const allButLast = links.slice(0, -1).join(', ');
const allButLast = links.slice(0, -1).join(", ");
const last = links[links.length - 1];
return `${allButLast} and ${last}`;

View file

@ -1,8 +1,8 @@
export default {
getMetadata: (data = {}, globals = {}, page = {}, title = '', description = '', schema = '') => {
getMetadata: (data = {}, globals = {}, page = {}, title = "", description = "", schema = "") => {
const metadata = data?.metadata;
const baseUrl = globals.url || '';
const ogPath = '/og/w800';
const baseUrl = globals.url || "";
const ogPath = "/og/w800";
const image =
metadata?.open_graph_image || globals.metadata?.open_graph_image || globals.avatar;
const rawTitle = title || page.title || metadata?.title || globals.site_name;
@ -10,7 +10,7 @@ export default {
rawTitle === globals.site_name ? globals.site_name : `${rawTitle}${globals.site_name}`;
const resolvedDescription =
description || metadata?.description || page.description || globals.site_description;
const url = metadata?.url || (page.url ? `${baseUrl}${page.url}` : '#');
const url = metadata?.url || (page.url ? `${baseUrl}${page.url}` : "#");
return {
title: resolvedTitle,

View file

@ -1,11 +1,11 @@
const normalizeUrl = (url) =>
url.replace(/index\.php$|index\.html$/i, '').replace(/\.php$|\.html$/i, '') || '/';
url.replace(/index\.php$|index\.html$/i, "").replace(/\.php$|\.html$/i, "") || "/";
export default {
isLinkActive: (category, page) => {
const normalized = normalizeUrl(page);
return (
normalized.includes(category) && normalized.split('/').filter((a) => a !== '').length <= 1
normalized.includes(category) && normalized.split("/").filter((a) => a !== "").length <= 1
);
},
normalizeUrl

View file

@ -1,18 +1,18 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import postcss from 'postcss';
import postcssImport from 'postcss-import';
import postcssImportExtGlob from 'postcss-import-ext-glob';
import cssnano from 'cssnano';
import fs from "node:fs/promises";
import path from "node:path";
import postcss from "postcss";
import postcssImport from "postcss-import";
import postcssImportExtGlob from "postcss-import-ext-glob";
import cssnano from "cssnano";
export const cssConfig = (eleventyConfig) => {
eleventyConfig.addTemplateFormats('css');
eleventyConfig.addExtension('css', {
outputFileExtension: 'css',
eleventyConfig.addTemplateFormats("css");
eleventyConfig.addExtension("css", {
outputFileExtension: "css",
compile: async (inputContent, inputPath) => {
const outputPath = 'dist/assets/css/index.css';
const outputPath = "dist/assets/css/index.css";
if (inputPath.endsWith('index.css')) {
if (inputPath.endsWith("index.css")) {
return async () => {
let result = await postcss([postcssImportExtGlob, postcssImport, cssnano]).process(
inputContent,

View file

@ -1,8 +1,8 @@
import htmlmin from 'html-minifier-terser';
import htmlmin from "html-minifier-terser";
export const htmlConfig = (eleventyConfig) => {
eleventyConfig.addTransform('html-minify', (content, path) => {
if (path && path.endsWith('.html')) {
eleventyConfig.addTransform("html-minify", (content, path) => {
if (path && path.endsWith(".html")) {
return htmlmin.minify(content, {
collapseBooleanAttributes: true,
collapseWhitespace: true,

View file

@ -1,5 +1,5 @@
import { cssConfig } from './css-config.js';
import { htmlConfig } from './html-config.js';
import { markdownLib } from './markdown.js';
import { cssConfig } from "./css-config.js";
import { htmlConfig } from "./html-config.js";
import { markdownLib } from "./markdown.js";
export default { cssConfig, htmlConfig, markdownLib };

View file

@ -1,8 +1,8 @@
import markdownIt from 'markdown-it';
import markdownItAnchor from 'markdown-it-anchor';
import markdownItFootnote from 'markdown-it-footnote';
import markdownItLinkAttributes from 'markdown-it-link-attributes';
import markdownItPrism from 'markdown-it-prism';
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItFootnote from "markdown-it-footnote";
import markdownItLinkAttributes from "markdown-it-link-attributes";
import markdownItPrism from "markdown-it-prism";
export const markdownLib = markdownIt({ html: true, linkify: true })
.use(markdownItAnchor, {
@ -17,7 +17,7 @@ export const markdownLib = markdownIt({ html: true, linkify: true })
return href.match(/^https?:\/\//);
},
attrs: {
rel: 'noopener'
rel: "noopener"
}
}
])