chore(*): remove duplicate cache rule + cleanup cache headers; cleanup + formatting
This commit is contained in:
parent
425fed6ff6
commit
0e565970a5
42 changed files with 223 additions and 217 deletions
|
@ -25,8 +25,7 @@ export const albumReleasesCalendar = (collection) => {
|
|||
url: albumUrl,
|
||||
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",
|
||||
|
|
|
@ -4,9 +4,9 @@ import { minify } from "terser";
|
|||
|
||||
export const minifyJsComponents = async () => {
|
||||
const scriptsDir = "dist/assets/scripts";
|
||||
|
||||
const minifyJsFilesInDir = async (dir) => {
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
for (const fileName of files) {
|
||||
const filePath = path.join(dir, fileName);
|
||||
const stat = fs.statSync(filePath);
|
||||
|
@ -16,6 +16,7 @@ export const minifyJsComponents = async () => {
|
|||
} else if (fileName.endsWith(".js")) {
|
||||
const fileContent = fs.readFileSync(filePath, "utf8");
|
||||
const minified = await minify(fileContent);
|
||||
|
||||
if (minified.error) {
|
||||
console.error(`Error minifying ${filePath}:`, minified.error);
|
||||
} else {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
export default {
|
||||
stringToRFC822Date: (dateString) => {
|
||||
const date = new Date(dateString);
|
||||
|
||||
if (isNaN(date.getTime())) return "";
|
||||
|
||||
const options = {
|
||||
timeZone: "America/Los_Angeles",
|
||||
weekday: "short",
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
timeZoneName: "short",
|
||||
};
|
||||
|
||||
return new Intl.DateTimeFormat("en-US", options).format(date);
|
||||
},
|
||||
};
|
|
@ -30,9 +30,13 @@ export default {
|
|||
getRemoteFileSize: async (url) => {
|
||||
try {
|
||||
const response = await fetch(url, { method: "HEAD" });
|
||||
|
||||
if (!response.ok) return 0;
|
||||
|
||||
const contentLength = response.headers.get("content-length");
|
||||
|
||||
if (!contentLength) return 0;
|
||||
|
||||
return parseInt(contentLength, 10);
|
||||
} catch (error) {
|
||||
return 0;
|
||||
|
|
|
@ -1,25 +1,37 @@
|
|||
import truncateHtml from "truncate-html";
|
||||
import { shuffleArray } from "../utilities/index.js";
|
||||
|
||||
export default {
|
||||
encodeAmp: (string) => {
|
||||
if (!string) return;
|
||||
|
||||
const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g;
|
||||
const replacement = "&";
|
||||
|
||||
return string.replace(pattern, replacement);
|
||||
},
|
||||
replaceQuotes: (string) => string.replace(/"/g, """),
|
||||
htmlTruncate: (content, limit = 50) =>
|
||||
truncateHtml(content, limit, {
|
||||
htmlTruncate: (content, limit = 50) => truncateHtml(content, limit, {
|
||||
byWords: true,
|
||||
ellipsis: "...",
|
||||
}),
|
||||
shuffleArray,
|
||||
mergeArray: (a, b) =>
|
||||
Array.isArray(a) && Array.isArray(b) ? [...new Set([...a, ...b])] : [],
|
||||
shuffleArray: (array) => {
|
||||
const shuffled = [...array];
|
||||
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
let j = Math.floor(Math.random() * (i + 1));
|
||||
let temp = shuffled[i];
|
||||
shuffled[i] = shuffled[j];
|
||||
shuffled[j] = temp;
|
||||
}
|
||||
|
||||
return shuffled;
|
||||
},
|
||||
mergeArray: (a, b) => Array.isArray(a) && Array.isArray(b) ? [...new Set([...a, ...b])] : [],
|
||||
pluralize: (count, string, trailing) => {
|
||||
const countStr = String(count).replace(/,/g, "");
|
||||
|
||||
if (parseInt(countStr, 10) === 1) return string;
|
||||
|
||||
return `${string}s${trailing ? `${trailing}` : ''}`;
|
||||
},
|
||||
jsonEscape: (string) => JSON.stringify(string),
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import dates from "./dates.js";
|
||||
import feeds from "./feeds.js"
|
||||
import general from "./general.js";
|
||||
import media from "./media.js";
|
||||
import navigation from "./navigation.js";
|
||||
|
||||
export default {
|
||||
...dates,
|
||||
...feeds,
|
||||
...general,
|
||||
...media,
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
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(""),
|
||||
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(""),
|
||||
mediaLinks: (data, type, count = 10) => {
|
||||
if (!data || !type) return "";
|
||||
|
||||
const dataSlice = data.slice(0, count);
|
||||
|
||||
if (dataSlice.length === 0) return null;
|
||||
|
||||
const buildLink = (item) => {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
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,10 +0,0 @@
|
|||
export const shuffleArray = (array) => {
|
||||
const shuffled = [...array];
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
let j = Math.floor(Math.random() * (i + 1));
|
||||
let temp = shuffled[i];
|
||||
shuffled[i] = shuffled[j];
|
||||
shuffled[j] = temp;
|
||||
}
|
||||
return shuffled;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue