From 501160e27e6282193e7a02a079f495a34586171b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 20 Jun 2025 14:12:38 +1000 Subject: [PATCH] refactor: move blog plugin directly into routes --- .../blog/components => components}/Share.tsx | 0 fresh.config.ts | 2 -- fresh.gen.ts | 6 +++++ plugins/blog/mod.ts | 24 ------------------- .../blog/routes => routes}/blog/[slug].tsx | 4 ++-- .../blog/routes => routes}/blog/index.tsx | 2 +- {plugins/blog/routes => routes}/feed.ts | 2 +- {plugins/blog/utils => utils}/posts.ts | 0 {plugins/blog/utils => utils}/posts_test.ts | 0 9 files changed, 10 insertions(+), 30 deletions(-) rename {plugins/blog/components => components}/Share.tsx (100%) delete mode 100644 plugins/blog/mod.ts rename {plugins/blog/routes => routes}/blog/[slug].tsx (92%) rename {plugins/blog/routes => routes}/blog/index.tsx (95%) rename {plugins/blog/routes => routes}/feed.ts (96%) rename {plugins/blog/utils => utils}/posts.ts (100%) rename {plugins/blog/utils => utils}/posts_test.ts (100%) diff --git a/plugins/blog/components/Share.tsx b/components/Share.tsx similarity index 100% rename from plugins/blog/components/Share.tsx rename to components/Share.tsx diff --git a/fresh.config.ts b/fresh.config.ts index 95cd5313c..525259608 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -7,7 +7,6 @@ import securityHeaders from "./plugins/security_headers.ts"; import welcomePlugin from "./plugins/welcome.ts"; import type { FreshConfig } from "$fresh/server.ts"; import { ga4Plugin } from "https://deno.land/x/fresh_ga4@0.0.4/mod.ts"; -import { blog } from "./plugins/blog/mod.ts"; export default { plugins: [ @@ -18,6 +17,5 @@ export default { tailwind(), errorHandling, securityHeaders, - blog(), ], } satisfies FreshConfig; diff --git a/fresh.gen.ts b/fresh.gen.ts index 95b1809f3..7045ab134 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -16,9 +16,12 @@ import * as $api_users_login_index from "./routes/api/users/[login]/index.ts"; import * as $api_users_login_items from "./routes/api/users/[login]/items.ts"; import * as $api_users_index from "./routes/api/users/index.ts"; import * as $api_vote from "./routes/api/vote.ts"; +import * as $blog_slug_ from "./routes/blog/[slug].tsx"; +import * as $blog_index from "./routes/blog/index.tsx"; import * as $dashboard_index from "./routes/dashboard/index.tsx"; import * as $dashboard_stats from "./routes/dashboard/stats.tsx"; import * as $dashboard_users from "./routes/dashboard/users.tsx"; +import * as $feed from "./routes/feed.ts"; import * as $index from "./routes/index.tsx"; import * as $pricing from "./routes/pricing.tsx"; import * as $submit from "./routes/submit.tsx"; @@ -45,9 +48,12 @@ const manifest = { "./routes/api/users/[login]/items.ts": $api_users_login_items, "./routes/api/users/index.ts": $api_users_index, "./routes/api/vote.ts": $api_vote, + "./routes/blog/[slug].tsx": $blog_slug_, + "./routes/blog/index.tsx": $blog_index, "./routes/dashboard/index.tsx": $dashboard_index, "./routes/dashboard/stats.tsx": $dashboard_stats, "./routes/dashboard/users.tsx": $dashboard_users, + "./routes/feed.ts": $feed, "./routes/index.tsx": $index, "./routes/pricing.tsx": $pricing, "./routes/submit.tsx": $submit, diff --git a/plugins/blog/mod.ts b/plugins/blog/mod.ts deleted file mode 100644 index 7b23002e1..000000000 --- a/plugins/blog/mod.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2023-2025 the Deno authors. All rights reserved. MIT license. -import type { Plugin } from "$fresh/server.ts"; -import BlogIndex from "./routes/blog/index.tsx"; -import BlogSlug from "./routes/blog/[slug].tsx"; -import Feed from "./routes/feed.ts"; -import { normalize } from "@std/path/normalize"; - -export function blog(): Plugin { - return { - name: "blog", - routes: [{ - path: "/blog", - component: BlogIndex, - }, { - path: "/blog/[slug]", - component: BlogSlug, - }, { - path: "/feed", - component: Feed, - }], - location: import.meta.url, - projectLocation: normalize(import.meta.url + "../../../"), - }; -} diff --git a/plugins/blog/routes/blog/[slug].tsx b/routes/blog/[slug].tsx similarity index 92% rename from plugins/blog/routes/blog/[slug].tsx rename to routes/blog/[slug].tsx index 9b765a387..005a39425 100644 --- a/plugins/blog/routes/blog/[slug].tsx +++ b/routes/blog/[slug].tsx @@ -1,9 +1,9 @@ // Copyright 2023-2025 the Deno authors. All rights reserved. MIT license. import { defineRoute } from "$fresh/server.ts"; import { CSS, render } from "jsr:@deno/gfm"; -import { getPost } from "../../utils/posts.ts"; +import { getPost } from "@/utils/posts.ts"; import Head from "@/components/Head.tsx"; -import Share from "../../components/Share.tsx"; +import Share from "@/components/Share.tsx"; export default defineRoute(async (_req, ctx) => { const post = await getPost(ctx.params.slug); diff --git a/plugins/blog/routes/blog/index.tsx b/routes/blog/index.tsx similarity index 95% rename from plugins/blog/routes/blog/index.tsx rename to routes/blog/index.tsx index 5e373c622..0ffc45574 100644 --- a/plugins/blog/routes/blog/index.tsx +++ b/routes/blog/index.tsx @@ -1,6 +1,6 @@ // Copyright 2023-2025 the Deno authors. All rights reserved. MIT license. import { defineRoute } from "$fresh/server.ts"; -import { getPosts, type Post } from "../../utils/posts.ts"; +import { getPosts, type Post } from "@/utils/posts.ts"; import Head from "@/components/Head.tsx"; function PostCard(props: Post) { diff --git a/plugins/blog/routes/feed.ts b/routes/feed.ts similarity index 96% rename from plugins/blog/routes/feed.ts rename to routes/feed.ts index bf59369c9..2ac3c6b4d 100644 --- a/plugins/blog/routes/feed.ts +++ b/routes/feed.ts @@ -1,6 +1,6 @@ // Copyright 2023-2025 the Deno authors. All rights reserved. MIT license. import { Feed } from "npm:feed@4.2.2"; -import { getPosts } from "../utils/posts.ts"; +import { getPosts } from "@/utils/posts.ts"; import { SITE_NAME } from "@/utils/constants.ts"; import { defineRoute } from "$fresh/server.ts"; diff --git a/plugins/blog/utils/posts.ts b/utils/posts.ts similarity index 100% rename from plugins/blog/utils/posts.ts rename to utils/posts.ts diff --git a/plugins/blog/utils/posts_test.ts b/utils/posts_test.ts similarity index 100% rename from plugins/blog/utils/posts_test.ts rename to utils/posts_test.ts