Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pluginify blog #660

Merged
merged 14 commits into from
Mar 3, 2024
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
"imports": {
"@/": "./",
"$fresh/": "https://deno.land/x/fresh@1.6.3/",
"$fresh/": "https://raw.githubusercontent.com/deer/fresh/2159_plugin_routes_tailwind/",
deer marked this conversation as resolved.
Show resolved Hide resolved
"$gfm": "https://deno.land/x/gfm@0.2.5/mod.ts",
"preact": "https://esm.sh/preact@10.19.2",
"preact/": "https://esm.sh/preact@10.19.2/",
Expand Down
2 changes: 2 additions & 0 deletions fresh.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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: [
Expand All @@ -17,5 +18,6 @@ export default {
tailwind(),
errorHandling,
securityHeaders,
blog(),
],
} satisfies FreshConfig;
6 changes: 0 additions & 6 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ 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";
Expand All @@ -48,12 +45,9 @@ 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,
Expand Down
24 changes: 24 additions & 0 deletions plugins/blog/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023-2024 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 { toFileUrl } from "std/path/to_file_url.ts";

export function blog() {
return {
name: "blog",
routes: [{
path: "/blog",
component: BlogIndex,
}, {
path: "/blog/[slug]",
component: BlogSlug,
}, {
path: "/feed",
component: Feed,
}],
location: import.meta.url,
projectLocation: toFileUrl(Deno.cwd()).href,
Copy link
Contributor

@iuioiua iuioiua Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a blocker, but I observed that Tailwind styling appeared to break when I used projectLocation: Deno.cwd(). It must have something to do with the omission of file:// at the start of the string.

} satisfies Plugin;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-2024 the Deno authors. All rights reserved. MIT license.
import { defineRoute } from "$fresh/server.ts";
import { CSS, render } from "$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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023-2024 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) {
Expand Down
2 changes: 1 addition & 1 deletion routes/feed.ts → plugins/blog/routes/feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023-2024 the Deno authors. All rights reserved. MIT license.
import { Feed } from "feed";
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";

Expand Down
File renamed without changes.
File renamed without changes.
Loading