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

116
app/shared/github.d.ts vendored Normal file
View File

@@ -0,0 +1,116 @@
// i know i can import one but
// i can't find one so here we are
export interface GithubUser {
id: number;
login: string;
display_login: string;
gravatar_id: string;
url: string;
avatar_url: string;
}
export interface GithubRepo {
id: number;
name: string;
url: string;
}
export interface GithubCommit {
sha: string;
author: {
email: string;
name: string;
};
message: string;
distinct: boolean;
url: string;
}
export interface GithubPullRequest {
url: string;
id: number;
node_id: string;
html_url: string;
diff_url: string;
patch_url: string;
issue_url: string;
number: number;
state: string;
locked: boolean;
title: string;
body: string;
created_at: string;
updated_at: string;
closed_at: string | null;
merged_at: string | null;
merge_commit_sha: string | null;
draft: boolean;
// there's more but i don't wanna
}
export interface GithubRelease {
url: string;
assets_url: string;
upload_url: string;
html_url: string;
id: number;
// author: AUTHOR
node_id: string;
tag_name: string;
target_commitish: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: string;
published_at: string;
tarball_url: string;
zipball_url: string;
body: string;
short_description_html: string;
is_short_description_html_truncated: boolean;
}
export interface GithubCommitEventPayload {
push_id: number;
size: number;
distinct_size: number;
ref: string;
head: string;
before: string;
}
export interface GithubPullRequestEventPayload {
action: string;
number: number;
pull_request: GithubPullRequest;
}
export interface GithubReleaseEventPayload {
action: string;
release: GithubRelease;
public: boolean;
created_at: string;
}
export interface GithubEvent {
id: string;
type: "PushEvent" | "CreateEvent" | "ReleaseEvent" | "PullRequestEvent";
actor: GithubUser;
repo: GithubRepo;
payload:
| GithubCommitEventPayload
| GithubPullRequestEventPayload
| GithubReleaseEventPayload;
public: boolean;
created_at: string;
}
export interface GithubPushEvent extends GithubEvent {
type: "PushEvent";
payload: GithubCommitEventPayload;
}
export interface GithubCreateEvent {}
export interface GithubReleaseEvent {}

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");
}

28
app/shared/types.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
import type { ParsedContent } from "@nuxt/content/dist/runtime/types";
interface ReadingTime {
text: string;
minutes: number;
time: number;
words: number;
}
interface BlogParsedContent extends ParsedContent {
date: Date;
title: string;
tags: string[];
description?: string;
readingTime: ReadingTime;
nopreview?: boolean;
}
interface StoryParsedContent extends ParsedContent {
date: Date;
title: string;
tags: string[];
description?: string;
readingTime: ReadingTime;
nopreview?: boolean;
}
type AnyParsedContent = BlogParsedContent | StoryParsedContent;