migrate website to astro
This commit is contained in:
23
src/utils/format-date.ts
Normal file
23
src/utils/format-date.ts
Normal file
@ -0,0 +1,23 @@
|
||||
const months = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
|
||||
export default function formatDate(date: Date | string) {
|
||||
const newDate = new Date(date);
|
||||
const month = months[newDate.getMonth()];
|
||||
const day = newDate.getDate();
|
||||
const year = newDate.getFullYear();
|
||||
|
||||
return `${month} ${day}, ${year}`;
|
||||
}
|
36
src/utils/nav-links.tsx
Normal file
36
src/utils/nav-links.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
type TNavItem = {
|
||||
label: string;
|
||||
to: string;
|
||||
};
|
||||
|
||||
export const navItems: TNavItem[] = [
|
||||
{
|
||||
label: "Blog",
|
||||
to: "/blog",
|
||||
},
|
||||
{
|
||||
label: "Portfolio",
|
||||
to: "/portfolio",
|
||||
},
|
||||
|
||||
{
|
||||
label: "Microblog",
|
||||
to: "/microblog",
|
||||
},
|
||||
{
|
||||
label: "Resources",
|
||||
to: "/resources",
|
||||
},
|
||||
// {
|
||||
// label: "Videos",
|
||||
// to: "/videos",
|
||||
// },
|
||||
{
|
||||
label: "About",
|
||||
to: "/about",
|
||||
},
|
||||
{
|
||||
label: "Contact",
|
||||
to: "/contact",
|
||||
},
|
||||
];
|
84
src/utils/pocketbase.ts
Normal file
84
src/utils/pocketbase.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import PocketBase from "pocketbase";
|
||||
import type { RecordService } from "pocketbase";
|
||||
|
||||
export enum Collections {
|
||||
Microblogs = "microblogs",
|
||||
Tags = "tags",
|
||||
Users = "users",
|
||||
}
|
||||
|
||||
export type IsoDateString = string;
|
||||
export type RecordIdString = string;
|
||||
export type HTMLString = string;
|
||||
|
||||
export type BaseSystemFields<T = never> = {
|
||||
id: RecordIdString;
|
||||
created: IsoDateString;
|
||||
updated: IsoDateString;
|
||||
collectionId: string;
|
||||
collectionName: Collections;
|
||||
expand?: T;
|
||||
};
|
||||
|
||||
export type AuthSystemFields<T = never> = {
|
||||
email: string;
|
||||
emailVisibility: boolean;
|
||||
username: string;
|
||||
verified: boolean;
|
||||
} & BaseSystemFields<T>;
|
||||
|
||||
export type MicroblogsRecord = {
|
||||
content?: string;
|
||||
published: IsoDateString;
|
||||
tags?: RecordIdString[];
|
||||
};
|
||||
|
||||
export type TagsRecord = {
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export type UsersRecord = {
|
||||
avatar?: string;
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export type MicroblogsResponse<Texpand = unknown> = Required<MicroblogsRecord> &
|
||||
BaseSystemFields<Texpand>;
|
||||
export type TagsResponse<Texpand = unknown> = Required<TagsRecord> &
|
||||
BaseSystemFields<Texpand>;
|
||||
export type UsersResponse<Texpand = unknown> = Required<UsersRecord> &
|
||||
AuthSystemFields<Texpand>;
|
||||
|
||||
export type CollectionRecords = {
|
||||
microblogs: MicroblogsRecord;
|
||||
tags: TagsRecord;
|
||||
users: UsersRecord;
|
||||
};
|
||||
|
||||
export type CollectionResponses = {
|
||||
microblogs: MicroblogsResponse;
|
||||
tags: TagsResponse;
|
||||
users: UsersResponse;
|
||||
};
|
||||
|
||||
export type TypedPocketBase = PocketBase & {
|
||||
collection(idOrName: "microblogs"): RecordService<MicroblogsResponse>;
|
||||
collection(idOrName: "tags"): RecordService<TagsResponse>;
|
||||
collection(idOrName: "users"): RecordService<UsersResponse>;
|
||||
};
|
||||
|
||||
export function createServerClient(url: string) {
|
||||
if (!url) {
|
||||
throw new Error("Pocketbase API url not defined !");
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
throw new Error(
|
||||
"This method is only supposed to call from the Server environment",
|
||||
);
|
||||
}
|
||||
|
||||
const client = new PocketBase(url) as TypedPocketBase;
|
||||
|
||||
return client;
|
||||
}
|
Reference in New Issue
Block a user