diff --git a/package.json b/package.json index 3316cc3..a620e9d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "workspaces": ["packages/*"], "scripts": { - "prepare": "husky install", + "prepare": "husky", "format:check": "biome format .", "format:fix": "biome format --write .", "lint:check": "biome lint .", diff --git a/packages/blog/playwright.config.js b/packages/blog/playwright.config.js index a0bbad5..6939ab5 100644 --- a/packages/blog/playwright.config.js +++ b/packages/blog/playwright.config.js @@ -1,6 +1,6 @@ import process from "node:process"; import { defineConfig, devices } from "@playwright/test"; -import { envSchema } from "./src/config/models/env.model.js"; +import { envSchema } from "./src/config/types/env.ts"; const env = envSchema.parse(process.env); diff --git a/packages/blog/src/config/models/env.model.ts b/packages/blog/src/config/types/env.ts similarity index 92% rename from packages/blog/src/config/models/env.model.ts rename to packages/blog/src/config/types/env.ts index c0e1b07..a479db7 100644 --- a/packages/blog/src/config/models/env.model.ts +++ b/packages/blog/src/config/types/env.ts @@ -10,4 +10,4 @@ export const envSchema = z.object({ // biome-ignore lint/style/useNamingConvention: env variables have different convention BASE_URL: z.string().default("http://localhost:3000"), }); -export type EnvModel = z.infer; +export type Env = z.infer; diff --git a/packages/blog/src/filesystem/models/error.model.ts b/packages/blog/src/filesystem/utils/is-errno-exception.ts similarity index 100% rename from packages/blog/src/filesystem/models/error.model.ts rename to packages/blog/src/filesystem/utils/is-errno-exception.ts diff --git a/packages/blog/src/global.d.ts b/packages/blog/src/global.d.ts index f9f1410..b2ff8a9 100644 --- a/packages/blog/src/global.d.ts +++ b/packages/blog/src/global.d.ts @@ -1,6 +1,6 @@ import "fastify"; import "react"; -import type { EnvModel } from "./config/models/env.model.js"; +import type { Env } from "./config/types/env.js"; declare module "react" { // biome-ignore lint/style/useNamingConvention: 3-rd party type @@ -19,6 +19,6 @@ declare module "react" { declare module "fastify" { interface FastifyInstance { - env: EnvModel; + env: Env; } } diff --git a/packages/blog/src/home/pages/about.page.tsx b/packages/blog/src/home/handlers/about.handler.tsx similarity index 91% rename from packages/blog/src/home/pages/about.page.tsx rename to packages/blog/src/home/handlers/about.handler.tsx index 4659dad..15120f8 100644 --- a/packages/blog/src/home/pages/about.page.tsx +++ b/packages/blog/src/home/handlers/about.handler.tsx @@ -7,7 +7,7 @@ import { Intro } from "../components/intro.js"; import { SocialLinks } from "../components/social-links.js"; import { StayUpToDate } from "../components/stay-up-to-date.js"; -export const aboutPage: FastifyPluginCallback = (app, _, done) => { +export const aboutHandler: FastifyPluginCallback = (app, _, done) => { app.get("/about", (_, reply) => { return reply .status(statusCode.ok) diff --git a/packages/blog/src/home/pages/home.page.tsx b/packages/blog/src/home/handlers/home.handler.tsx similarity index 85% rename from packages/blog/src/home/pages/home.page.tsx rename to packages/blog/src/home/handlers/home.handler.tsx index 3c5ca0a..8bfc470 100644 --- a/packages/blog/src/home/pages/home.page.tsx +++ b/packages/blog/src/home/handlers/home.handler.tsx @@ -3,14 +3,14 @@ import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; import { PinnedPosts } from "../../posts/components/pinned-posts.js"; import { RecentPosts } from "../../posts/components/recent-posts.js"; -import { findPosts } from "../../posts/models/post.table.js"; +import { findPosts } from "../../posts/models/post.datasource.js"; import { FeaturedProjects } from "../../projects/components/featured-projects.js"; -import { findProjects } from "../../projects/models/project.table.js"; +import { findProjects } from "../../projects/models/project.datasource.js"; import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { render } from "../../ui/utils/render.js"; import { Intro } from "../components/intro.js"; -export const homePage: FastifyPluginCallback = (app, _, done) => { +export const homeHandler: FastifyPluginCallback = (app, _, done) => { app.get("/", async (_, reply) => { const [allPosts, allProjects] = await Promise.all([ findPosts(), diff --git a/packages/blog/src/home/pages/rss.page.tsx b/packages/blog/src/home/handlers/rss.handler.tsx similarity index 88% rename from packages/blog/src/home/pages/rss.page.tsx rename to packages/blog/src/home/handlers/rss.handler.tsx index 01d826f..84b5bf0 100644 --- a/packages/blog/src/home/pages/rss.page.tsx +++ b/packages/blog/src/home/handlers/rss.handler.tsx @@ -3,9 +3,9 @@ import RSS from "rss"; import { profile } from "../../config/globals/profile.js"; import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; -import { findPosts } from "../../posts/models/post.table.js"; +import { findPosts } from "../../posts/models/post.datasource.js"; -export const rssPage: FastifyPluginCallback = (app, _, done) => { +export const rssHandler: FastifyPluginCallback = (app, _, done) => { app.get("/rss.xml", async (_, reply) => { const rss = new RSS({ title: profile.title, diff --git a/packages/blog/src/home/pages/sitemap.page.tsx b/packages/blog/src/home/handlers/sitemap.handler.tsx similarity index 86% rename from packages/blog/src/home/pages/sitemap.page.tsx rename to packages/blog/src/home/handlers/sitemap.handler.tsx index 060e5b5..f647ac7 100644 --- a/packages/blog/src/home/pages/sitemap.page.tsx +++ b/packages/blog/src/home/handlers/sitemap.handler.tsx @@ -4,12 +4,12 @@ import { type IndexItem, SitemapStream, streamToPromise } from "sitemap"; import type { ContentModel } from "../../content/models/content.model.js"; import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; -import { findPosts } from "../../posts/models/post.table.js"; +import { findPosts } from "../../posts/models/post.datasource.js"; import { getUniqueTags } from "../../posts/utils/get-unique-tags.js"; -import { findChangelogs } from "../../projects/models/changelog.table.js"; -import { findProjects } from "../../projects/models/project.table.js"; +import { findChangelogs } from "../../projects/models/changelog.datasource.js"; +import { findProjects } from "../../projects/models/project.datasource.js"; -export const sitemapPage: FastifyPluginCallback = (app, _, done) => { +export const sitemapHandler: FastifyPluginCallback = (app, _, done) => { app.get("/sitemap.xml", async (_, reply) => { const sitemapStream = new SitemapStream({ hostname: app.env.BASE_URL, diff --git a/packages/blog/src/home/home.module.tsx b/packages/blog/src/home/home.module.tsx index 9937f88..b0aaf08 100644 --- a/packages/blog/src/home/home.module.tsx +++ b/packages/blog/src/home/home.module.tsx @@ -1,11 +1,11 @@ -import fastifyStatic from "@fastify/static"; -import type { FastifyPluginAsync } from "fastify"; import path from "node:path"; import process from "node:process"; -import { aboutPage } from "./pages/about.page.js"; -import { homePage } from "./pages/home.page.js"; -import { rssPage } from "./pages/rss.page.js"; -import { sitemapPage } from "./pages/sitemap.page.js"; +import fastifyStatic from "@fastify/static"; +import type { FastifyPluginAsync } from "fastify"; +import { aboutHandler } from "./handlers/about.handler.js"; +import { homeHandler } from "./handlers/home.handler.js"; +import { rssHandler } from "./handlers/rss.handler.js"; +import { sitemapHandler } from "./handlers/sitemap.handler.js"; export const homeModule: FastifyPluginAsync = async (app) => { await app.register(fastifyStatic, { @@ -13,8 +13,8 @@ export const homeModule: FastifyPluginAsync = async (app) => { prefix: "/home/", }); - await app.register(homePage); - await app.register(aboutPage); - await app.register(rssPage); - await app.register(sitemapPage); + await app.register(homeHandler); + await app.register(aboutHandler); + await app.register(rssHandler); + await app.register(sitemapHandler); }; diff --git a/packages/blog/src/posts/pages/post.page.tsx b/packages/blog/src/posts/handlers/post.handler.tsx similarity index 95% rename from packages/blog/src/posts/pages/post.page.tsx rename to packages/blog/src/posts/handlers/post.handler.tsx index 9547609..7f00017 100644 --- a/packages/blog/src/posts/pages/post.page.tsx +++ b/packages/blog/src/posts/handlers/post.handler.tsx @@ -2,7 +2,7 @@ import { format } from "date-fns"; import type { FastifyPluginCallback } from "fastify"; import type { VFile } from "vfile"; import { publishedAtFormat } from "../../content/globals/published-at-format.js"; -import { isErrnoException } from "../../filesystem/models/error.model.js"; +import { isErrnoException } from "../../filesystem/utils/is-errno-exception.js"; import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; import { sendNotFound } from "../../http/utils/send-not-found.js"; @@ -15,10 +15,10 @@ import { cn } from "../../ui/utils/cn.js"; import { render } from "../../ui/utils/render.js"; import { RelatedPosts } from "../components/related-posts.js"; import { Tag } from "../components/tag.js"; +import { findPosts, getPostFile } from "../models/post.datasource.js"; import { type PostModel, isPostWithCover } from "../models/post.model.js"; -import { findPosts, getPostFile } from "../models/post.table.js"; -export const postPage: FastifyPluginCallback = (app, _, done) => { +export const postHandler: FastifyPluginCallback = (app, _, done) => { // biome-ignore lint/style/useNamingConvention: 3-rd party type app.get<{ Params: PostParams }>("/posts/:slug", async (request, reply) => { let postFile: VFile; diff --git a/packages/blog/src/posts/pages/posts.page.tsx b/packages/blog/src/posts/handlers/posts.handler.tsx similarity index 91% rename from packages/blog/src/posts/pages/posts.page.tsx rename to packages/blog/src/posts/handlers/posts.handler.tsx index 2e2bc53..39f93d1 100644 --- a/packages/blog/src/posts/pages/posts.page.tsx +++ b/packages/blog/src/posts/handlers/posts.handler.tsx @@ -8,9 +8,9 @@ import { ArchiveListItem } from "../../ui/components/archive-list-item.js"; import { ArchiveList } from "../../ui/components/archive-list.js"; import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { render } from "../../ui/utils/render.js"; -import { findPosts } from "../models/post.table.js"; +import { findPosts } from "../models/post.datasource.js"; -export const postsPage: FastifyPluginCallback = (app, _opts, done) => { +export const postsHandler: FastifyPluginCallback = (app, _opts, done) => { app.get("/posts", async (_, reply) => { const allPosts = await findPosts(); diff --git a/packages/blog/src/posts/pages/tag.page.tsx b/packages/blog/src/posts/handlers/tag.handler.tsx similarity index 92% rename from packages/blog/src/posts/pages/tag.page.tsx rename to packages/blog/src/posts/handlers/tag.handler.tsx index baecf91..da7aabe 100644 --- a/packages/blog/src/posts/pages/tag.page.tsx +++ b/packages/blog/src/posts/handlers/tag.handler.tsx @@ -7,9 +7,9 @@ import { ArchiveListItem } from "../../ui/components/archive-list-item.js"; import { ArchiveList } from "../../ui/components/archive-list.js"; import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { render } from "../../ui/utils/render.js"; -import { findPosts } from "../models/post.table.js"; +import { findPosts } from "../models/post.datasource.js"; -export const tagPage: FastifyPluginCallback = (app, _, done) => { +export const tagHandler: FastifyPluginCallback = (app, _, done) => { // biome-ignore lint/style/useNamingConvention: 3-rd party type app.get<{ Params: { tag: string } }>("/tags/:tag", async (request, reply) => { const allPosts = await findPosts(); diff --git a/packages/blog/src/posts/models/post.table.ts b/packages/blog/src/posts/models/post.datasource.ts similarity index 100% rename from packages/blog/src/posts/models/post.table.ts rename to packages/blog/src/posts/models/post.datasource.ts diff --git a/packages/blog/src/posts/posts.module.tsx b/packages/blog/src/posts/posts.module.tsx index a05fa78..870b641 100644 --- a/packages/blog/src/posts/posts.module.tsx +++ b/packages/blog/src/posts/posts.module.tsx @@ -1,9 +1,9 @@ import fastifyStatic from "@fastify/static"; import type { FastifyPluginAsync } from "fastify"; import { resolveContentPath } from "../content/utils/path.js"; -import { postPage } from "./pages/post.page.js"; -import { postsPage } from "./pages/posts.page.js"; -import { tagPage } from "./pages/tag.page.js"; +import { postHandler } from "./handlers/post.handler.js"; +import { postsHandler } from "./handlers/posts.handler.js"; +import { tagHandler } from "./handlers/tag.handler.js"; export const postsModule: FastifyPluginAsync = async (app) => { await app.register(fastifyStatic, { @@ -11,7 +11,7 @@ export const postsModule: FastifyPluginAsync = async (app) => { prefix: "/posts/", }); - await app.register(postsPage); - await app.register(postPage); - await app.register(tagPage); + await app.register(postsHandler); + await app.register(postHandler); + await app.register(tagHandler); }; diff --git a/packages/blog/src/projects/pages/project-changelog.page.tsx b/packages/blog/src/projects/handlers/project-changelog.handler.tsx similarity index 90% rename from packages/blog/src/projects/pages/project-changelog.page.tsx rename to packages/blog/src/projects/handlers/project-changelog.handler.tsx index 0dd3590..acdc6e1 100644 --- a/packages/blog/src/projects/pages/project-changelog.page.tsx +++ b/packages/blog/src/projects/handlers/project-changelog.handler.tsx @@ -1,6 +1,6 @@ import type { FastifyPluginCallback } from "fastify"; import type { VFile } from "vfile"; -import { isErrnoException } from "../../filesystem/models/error.model.js"; +import { isErrnoException } from "../../filesystem/utils/is-errno-exception.js"; import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; import { sendNotFound } from "../../http/utils/send-not-found.js"; @@ -8,12 +8,16 @@ import { Title } from "../../ui/components/title.js"; import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { cn } from "../../ui/utils/cn.js"; import { render } from "../../ui/utils/render.js"; +import { getChangelog } from "../models/changelog.datasource.js"; import type { ChangelogModel } from "../models/changelog.model.js"; -import { getChangelog } from "../models/changelog.table.js"; +import { getProject } from "../models/project.datasource.js"; import type { ProjectModel } from "../models/project.model.js"; -import { getProject } from "../models/project.table.js"; -export const projectChangelogPage: FastifyPluginCallback = (app, _, done) => { +export const projectChangelogHandler: FastifyPluginCallback = ( + app, + _, + done, +) => { // biome-ignore lint/style/useNamingConvention: 3-rd party type app.get<{ Params: ProjectChangelogParams }>( "/projects/:projectSlug/changelogs/:changelogVersion", diff --git a/packages/blog/src/projects/pages/project-changelogs.page.tsx b/packages/blog/src/projects/handlers/project-changelogs.handler.tsx similarity index 90% rename from packages/blog/src/projects/pages/project-changelogs.page.tsx rename to packages/blog/src/projects/handlers/project-changelogs.handler.tsx index 5a3df25..96cf6f9 100644 --- a/packages/blog/src/projects/pages/project-changelogs.page.tsx +++ b/packages/blog/src/projects/handlers/project-changelogs.handler.tsx @@ -4,7 +4,11 @@ import { statusCode } from "../../http/types/status-code.js"; import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { render } from "../../ui/utils/render.js"; -export const projectChangelogsPage: FastifyPluginCallback = (app, _, done) => { +export const projectChangelogsHandler: FastifyPluginCallback = ( + app, + _, + done, +) => { // biome-ignore lint/style/useNamingConvention: 3-rd party type app.get<{ Params: ProjectChangelogsParams }>( "/projects/:slug/changelogs", diff --git a/packages/blog/src/projects/pages/project.page.tsx b/packages/blog/src/projects/handlers/project.handler.tsx similarity index 93% rename from packages/blog/src/projects/pages/project.page.tsx rename to packages/blog/src/projects/handlers/project.handler.tsx index 2ebf0f8..57ab68b 100644 --- a/packages/blog/src/projects/pages/project.page.tsx +++ b/packages/blog/src/projects/handlers/project.handler.tsx @@ -1,6 +1,6 @@ import type { FastifyPluginCallback } from "fastify"; import type { VFile } from "vfile"; -import { isErrnoException } from "../../filesystem/models/error.model.js"; +import { isErrnoException } from "../../filesystem/utils/is-errno-exception.js"; import { contentType } from "../../http/types/content-type.js"; import { statusCode } from "../../http/types/status-code.js"; import { sendNotFound } from "../../http/utils/send-not-found.js"; @@ -14,11 +14,11 @@ import { cn } from "../../ui/utils/cn.js"; import { render } from "../../ui/utils/render.js"; import { ProjectChangelogs } from "../components/project-changelogs.js"; import { Version } from "../components/version.js"; -import { findChangelogs } from "../models/changelog.table.js"; +import { findChangelogs } from "../models/changelog.datasource.js"; +import { getProjectFile } from "../models/project.datasource.js"; import type { ProjectModel } from "../models/project.model.js"; -import { getProjectFile } from "../models/project.table.js"; -export const projectPage: FastifyPluginCallback = (app, _, done) => { +export const projectHandler: FastifyPluginCallback = (app, _, done) => { // biome-ignore lint/style/useNamingConvention: 3-rd party type app.get<{ Params: ProjectParams }>( "/projects/:slug", diff --git a/packages/blog/src/projects/pages/projects.page.tsx b/packages/blog/src/projects/handlers/projects.handler.tsx similarity index 90% rename from packages/blog/src/projects/pages/projects.page.tsx rename to packages/blog/src/projects/handlers/projects.handler.tsx index f9b3924..03227e1 100644 --- a/packages/blog/src/projects/pages/projects.page.tsx +++ b/packages/blog/src/projects/handlers/projects.handler.tsx @@ -6,17 +6,17 @@ import { DefaultLayout } from "../../ui/layouts/default.layout.js"; import { render } from "../../ui/utils/render.js"; import { ProjectTiledListItem } from "../components/project-tiled-list-item.js"; import { ProjectTiledList } from "../components/project-tiled-list.js"; +import { findChangelogs } from "../models/changelog.datasource.js"; import type { ChangelogModel } from "../models/changelog.model.js"; -import { findChangelogs } from "../models/changelog.table.js"; +import { findProjects } from "../models/project.datasource.js"; import { type ProjectStatus, projectStatusOrder, projectStatusToLabel, } from "../models/project.model.js"; -import { findProjects } from "../models/project.table.js"; import { getProjectIdFromChangelogPath } from "../utils/get-project-id-from-changelog-path.js"; -export const projectsPage: FastifyPluginCallback = (app, _, done) => { +export const projectsHandler: FastifyPluginCallback = (app, _, done) => { app.get("/projects", async (_, reply) => { const [allProjects, allChangelogs] = await Promise.all([ findProjects(), diff --git a/packages/blog/src/projects/models/changelog.table.spec.ts b/packages/blog/src/projects/models/changelog.datasource.spec.ts similarity index 100% rename from packages/blog/src/projects/models/changelog.table.spec.ts rename to packages/blog/src/projects/models/changelog.datasource.spec.ts diff --git a/packages/blog/src/projects/models/changelog.table.ts b/packages/blog/src/projects/models/changelog.datasource.ts similarity index 100% rename from packages/blog/src/projects/models/changelog.table.ts rename to packages/blog/src/projects/models/changelog.datasource.ts diff --git a/packages/blog/src/projects/models/project.table.ts b/packages/blog/src/projects/models/project.datasource.ts similarity index 100% rename from packages/blog/src/projects/models/project.table.ts rename to packages/blog/src/projects/models/project.datasource.ts diff --git a/packages/blog/src/projects/projects.module.tsx b/packages/blog/src/projects/projects.module.tsx index db841aa..be414f3 100644 --- a/packages/blog/src/projects/projects.module.tsx +++ b/packages/blog/src/projects/projects.module.tsx @@ -1,10 +1,10 @@ import fastifyStatic from "@fastify/static"; import type { FastifyPluginAsync } from "fastify"; import { resolveContentPath } from "../content/utils/path.js"; -import { projectChangelogPage } from "./pages/project-changelog.page.js"; -import { projectChangelogsPage } from "./pages/project-changelogs.page.js"; -import { projectPage } from "./pages/project.page.js"; -import { projectsPage } from "./pages/projects.page.js"; +import { projectChangelogHandler } from "./handlers/project-changelog.handler.js"; +import { projectChangelogsHandler } from "./handlers/project-changelogs.handler.js"; +import { projectHandler } from "./handlers/project.handler.js"; +import { projectsHandler } from "./handlers/projects.handler.js"; export const projectsModule: FastifyPluginAsync = async (app) => { await app.register(fastifyStatic, { @@ -12,8 +12,8 @@ export const projectsModule: FastifyPluginAsync = async (app) => { prefix: "/projects/", }); - await app.register(projectsPage); - await app.register(projectPage); - await app.register(projectChangelogsPage); - await app.register(projectChangelogPage); + await app.register(projectsHandler); + await app.register(projectHandler); + await app.register(projectChangelogsHandler); + await app.register(projectChangelogHandler); }; diff --git a/packages/blog/src/server.tsx b/packages/blog/src/server.tsx index 0df5474..b22af20 100644 --- a/packages/blog/src/server.tsx +++ b/packages/blog/src/server.tsx @@ -3,7 +3,7 @@ import process from "node:process"; import fastifyStatic from "@fastify/static"; import closeWithGrace from "close-with-grace"; import Fastify from "fastify"; -import { envSchema } from "./config/models/env.model.js"; +import { envSchema } from "./config/types/env.js"; import { homeModule } from "./home/home.module.js"; import { sendNotFound } from "./http/utils/send-not-found.js"; import { postsModule } from "./posts/posts.module.js"; diff --git a/packages/blog/src/ui/layouts/default.layout.tsx b/packages/blog/src/ui/layouts/default.layout.tsx index c7c7c6b..3175296 100644 --- a/packages/blog/src/ui/layouts/default.layout.tsx +++ b/packages/blog/src/ui/layouts/default.layout.tsx @@ -1,7 +1,7 @@ import { URL } from "node:url"; import type { FC, PropsWithChildren } from "react"; import { profile } from "../../config/globals/profile.js"; -import type { EnvModel } from "../../config/models/env.model.js"; +import type { Env } from "../../config/types/env.js"; import { Background } from "../components/background.js"; import { ButtonLink } from "../components/button-link.js"; import { Button } from "../components/button.js"; @@ -107,7 +107,7 @@ export const DefaultLayout: FC> = ({ export interface DefaultLayoutProps { // TODO merge currentPath with env.BASE_URL currentPath: string; - env: EnvModel; + env: Env; title?: string; image?: string; description?: string; @@ -192,9 +192,9 @@ const Nav: FC = () => ( ); const navLinksMeta = [ - { label: "👨‍💻 About", url: "/about" }, - { label: "✏️ Posts", url: "/posts" }, - { label: "🏗️ Projects", url: "/projects" }, + { label: "👨 About", url: "/about" }, + { label: "✏ Posts", url: "/posts" }, + { label: "🏗 Projects", url: "/projects" }, ] as const; const NavLink: FC> = ({