chore: upgrade to nuxt 4

This commit is contained in:
eggy
2025-10-19 15:33:02 +08:00
parent 21c717ed79
commit 4c1c8ae3af
8 changed files with 419 additions and 0 deletions

44
app/shared/metadata.ts Normal file
View File

@@ -0,0 +1,44 @@
import type { AnyParsedContent } from "./types";
import readingTime from "reading-time";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc.js";
dayjs.extend(utc);
function countWords(str: string) {
let words = 0;
for (const c of str) {
if (c === " " || c === "/") {
words++;
}
}
return words;
}
function search(obj: Record<string, any>, results: string[] = []) {
if (obj.value) {
results.push(obj.value);
}
if (obj.children) {
for (const el of obj.children) {
search(el, results);
}
}
return results;
}
export function calcReadingTime(doc: AnyParsedContent) {
let body: string[] = search(doc.body);
return readingTime(body.join(" "));
}
export function getPrettyDate(doc: AnyParsedContent) {
const date = dayjs(doc.date).utc();
return date.format("DD MMM YYYY");
}
export function getUtcDate(doc: AnyParsedContent) {
const date = dayjs(doc.date).utc();
return date.format("YYYY-MM-DD");
}