Skip to content

Commit

Permalink
more renames
Browse files Browse the repository at this point in the history
  • Loading branch information
vorant94 committed Jul 23, 2024
1 parent 904ab76 commit 833a86a
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
2 changes: 1 addition & 1 deletion packages/blog/playwright.config.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof envSchema>;
export type Env = z.infer<typeof envSchema>;
4 changes: 2 additions & 2 deletions packages/blog/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +19,6 @@ declare module "react" {

declare module "fastify" {
interface FastifyInstance {
env: EnvModel;
env: Env;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions packages/blog/src/home/home.module.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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, {
root: path.resolve(process.cwd(), "src/home/assets"),
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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions packages/blog/src/posts/posts.module.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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, {
root: resolveContentPath("posts"),
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);
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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";
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions packages/blog/src/projects/projects.module.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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, {
root: resolveContentPath("projects"),
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);
};
2 changes: 1 addition & 1 deletion packages/blog/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 5 additions & 5 deletions packages/blog/src/ui/layouts/default.layout.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -107,7 +107,7 @@ export const DefaultLayout: FC<PropsWithChildren<DefaultLayoutProps>> = ({
export interface DefaultLayoutProps {
// TODO merge currentPath with env.BASE_URL
currentPath: string;
env: EnvModel;
env: Env;
title?: string;
image?: string;
description?: string;
Expand Down Expand Up @@ -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<PropsWithChildren<NavLinkProps>> = ({
Expand Down

0 comments on commit 833a86a

Please sign in to comment.