chore(*): use prettier for formatting
This commit is contained in:
parent
6c659fe1d0
commit
ce869012ef
73 changed files with 1393 additions and 794 deletions
|
@ -1,11 +1,14 @@
|
|||
import ics from "ics";
|
||||
import ics from 'ics';
|
||||
|
||||
export const albumReleasesCalendar = (collection) => {
|
||||
const collectionData = collection.getAll()[0];
|
||||
const { data } = collectionData;
|
||||
const { albumReleases: { all }, globals: { url } } = data;
|
||||
const {
|
||||
albumReleases: { all },
|
||||
globals: { url }
|
||||
} = data;
|
||||
|
||||
if (!all || all.length === 0) return "";
|
||||
if (!all || all.length === 0) return '';
|
||||
|
||||
const events = all
|
||||
.map((album) => {
|
||||
|
@ -13,27 +16,30 @@ 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") ? album.artust.url : `${url}${album.artist.url}`;
|
||||
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,
|
||||
uid: `${album.release_timestamp}-${album.artist.name}-${album.title}`,
|
||||
uid: `${album.release_timestamp}-${album.artist.name}-${album.title}`
|
||||
};
|
||||
}).filter((event) => event !== null);
|
||||
})
|
||||
.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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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://")) {
|
||||
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}`);
|
||||
$link.attr('href', `${normalizedDomain}/${normalizedHref}`);
|
||||
}
|
||||
});
|
||||
|
||||
return $.html();
|
||||
},
|
||||
generatePermalink: (url, baseUrl) => {
|
||||
if (url?.includes("http") || !baseUrl) return url
|
||||
return `${baseUrl}${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;
|
||||
|
||||
|
@ -40,4 +40,4 @@ export default {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,21 +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 = "&";
|
||||
const replacement = '&';
|
||||
|
||||
return string.replace(pattern, replacement);
|
||||
},
|
||||
replaceQuotes: (string) => {
|
||||
if (!string) return '';
|
||||
return string.replace(/"/g, """);
|
||||
return string.replace(/"/g, '"');
|
||||
},
|
||||
htmlTruncate: (content, limit = 50) => truncateHtml(content, limit, {
|
||||
htmlTruncate: (content, limit = 50) =>
|
||||
truncateHtml(content, limit, {
|
||||
byWords: true,
|
||||
ellipsis: "...",
|
||||
ellipsis: '...'
|
||||
}),
|
||||
shuffleArray: (array) => {
|
||||
const shuffled = [...array];
|
||||
|
@ -29,9 +30,9 @@ export default {
|
|||
|
||||
return shuffled;
|
||||
},
|
||||
mergeArray: (a, b) => Array.isArray(a) && Array.isArray(b) ? [...new Set([...a, ...b])] : [],
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
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,
|
||||
...general,
|
||||
...media,
|
||||
...metadata,
|
||||
...navigation,
|
||||
...navigation
|
||||
};
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
export default {
|
||||
filterBooksByStatus: (books, status) => books.filter((book) => book.status === status),
|
||||
findFavoriteBooks: (books) => books.filter((book) => book.favorite === true),
|
||||
bookYearLinks: (years) => years.sort((a, b) => b.value - a.value).map((year, index) =>
|
||||
`<a href="/reading/years/${year.value}">${year.value}</a>${
|
||||
index < years.length - 1 ? " • " : ""
|
||||
}`).join(""),
|
||||
bookYearLinks: (years) =>
|
||||
years
|
||||
.sort((a, b) => b.value - a.value)
|
||||
.map(
|
||||
(year, index) =>
|
||||
`<a href="/reading/years/${year.value}">${year.value}</a>${
|
||||
index < years.length - 1 ? ' • ' : ''
|
||||
}`
|
||||
)
|
||||
.join(''),
|
||||
mediaLinks: (data, type, count = 10) => {
|
||||
if (!data || !type) return "";
|
||||
if (!data || !type) return '';
|
||||
|
||||
const dataSlice = data.slice(0, count);
|
||||
|
||||
|
@ -14,23 +20,23 @@ 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}`;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
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 image = metadata?.open_graph_image || globals.metadata?.open_graph_image || globals.avatar;
|
||||
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;
|
||||
const resolvedTitle = 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 resolvedTitle =
|
||||
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}` : '#');
|
||||
|
||||
return {
|
||||
title: resolvedTitle,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export default {
|
||||
isLinkActive: (category, page) => page.includes(category) && page.split("/").filter((a) => a !== "").length <= 1,
|
||||
isLinkActive: (category, page) =>
|
||||
page.includes(category) && page.split('/').filter((a) => a !== '').length <= 1
|
||||
};
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
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, { from: inputPath });
|
||||
let result = await postcss([postcssImportExtGlob, postcssImport, cssnano]).process(
|
||||
inputContent,
|
||||
{ from: inputPath }
|
||||
);
|
||||
|
||||
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, result.css);
|
||||
|
@ -26,6 +25,6 @@ export const cssConfig = (eleventyConfig) => {
|
|||
return result.css;
|
||||
};
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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, {
|
||||
level: [1, 2],
|
||||
permalink: markdownItAnchor.permalink.headerLink({
|
||||
safariReaderFix: true,
|
||||
}),
|
||||
safariReaderFix: true
|
||||
})
|
||||
})
|
||||
.use(markdownItLinkAttributes, [
|
||||
{
|
||||
|
@ -17,9 +17,9 @@ export const markdownLib = markdownIt({ html: true, linkify: true })
|
|||
return href.match(/^https?:\/\//);
|
||||
},
|
||||
attrs: {
|
||||
rel: "noopener",
|
||||
},
|
||||
},
|
||||
rel: 'noopener'
|
||||
}
|
||||
}
|
||||
])
|
||||
.use(markdownItFootnote)
|
||||
.use(markdownItPrism);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue