diff --git a/deno.json b/deno.json index f05d8087f..ecd0a97cd 100644 --- a/deno.json +++ b/deno.json @@ -20,8 +20,7 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, "imports": { "@/": "./", - "$fresh/": "https://deno.land/x/fresh@1.6.3/", - "$gfm": "https://deno.land/x/gfm@0.2.5/mod.ts", + "$fresh/": "https://raw.githubusercontent.com/denoland/fresh/60220dd33b5b0f6b5c72927c933dbc32a3c4734e/", "preact": "https://esm.sh/preact@10.19.2", "preact/": "https://esm.sh/preact@10.19.2/", "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2", @@ -30,9 +29,8 @@ "tailwindcss": "npm:tailwindcss@3.4.1", "tailwindcss/": "npm:/tailwindcss@3.4.1/", "tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js", - "std/": "https://deno.land/std@0.208.0/", + "$std/": "https://deno.land/std@0.208.0/", "stripe": "npm:/stripe@13.5.0", - "feed": "npm:/feed@4.2.2", "kv_oauth/": "https://deno.land/x/deno_kv_oauth@v0.9.1/", "tabler_icons_tsx/": "https://deno.land/x/tabler_icons_tsx@0.0.4/tsx/", "fresh_charts/": "https://deno.land/x/fresh_charts@0.3.1/" diff --git a/e2e_test.ts b/e2e_test.ts index 10aabc57a..7ac8022f0 100644 --- a/e2e_test.ts +++ b/e2e_test.ts @@ -23,9 +23,9 @@ import { assertNotEquals, assertObjectMatch, assertStringIncludes, -} from "std/assert/mod.ts"; -import { isRedirectStatus, STATUS_CODE } from "std/http/status.ts"; -import { resolvesNext, returnsNext, stub } from "std/testing/mock.ts"; +} from "$std/assert/mod.ts"; +import { isRedirectStatus, STATUS_CODE } from "$std/http/status.ts"; +import { resolvesNext, returnsNext, stub } from "$std/testing/mock.ts"; import Stripe from "stripe"; import options from "./fresh.config.ts"; import { _internals } from "./plugins/kv_oauth.ts"; diff --git a/fresh.config.ts b/fresh.config.ts index 9cbeeaff5..922ba6837 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -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: [ @@ -17,5 +18,6 @@ export default { tailwind(), errorHandling, securityHeaders, + blog(), ], } satisfies FreshConfig; diff --git a/fresh.gen.ts b/fresh.gen.ts index 7045ab134..95b1809f3 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -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"; @@ -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, diff --git a/islands/ItemsList.tsx b/islands/ItemsList.tsx index ec6e6e7e8..f5e3dbca8 100644 --- a/islands/ItemsList.tsx +++ b/islands/ItemsList.tsx @@ -4,7 +4,7 @@ import { useEffect } from "preact/hooks"; import { type Item } from "@/utils/db.ts"; import IconInfo from "tabler_icons_tsx/info-circle.tsx"; import { fetchValues } from "@/utils/http.ts"; -import { decodeTime } from "std/ulid/mod.ts"; +import { decodeTime } from "$std/ulid/mod.ts"; import { timeAgo } from "@/utils/display.ts"; import GitHubAvatarImg from "@/components/GitHubAvatarImg.tsx"; diff --git a/components/Share.tsx b/plugins/blog/components/Share.tsx similarity index 100% rename from components/Share.tsx rename to plugins/blog/components/Share.tsx diff --git a/plugins/blog/mod.ts b/plugins/blog/mod.ts new file mode 100644 index 000000000..c2f27cb66 --- /dev/null +++ b/plugins/blog/mod.ts @@ -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 { normalize } from "$std/url/normalize.ts"; + +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 + "../../../").href, + }; +} diff --git a/routes/blog/[slug].tsx b/plugins/blog/routes/blog/[slug].tsx similarity index 88% rename from routes/blog/[slug].tsx rename to plugins/blog/routes/blog/[slug].tsx index a7047de9d..55c01b9cf 100644 --- a/routes/blog/[slug].tsx +++ b/plugins/blog/routes/blog/[slug].tsx @@ -1,9 +1,9 @@ // 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 { CSS, render } from "https://deno.land/x/gfm@0.2.5/mod.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/routes/blog/index.tsx b/plugins/blog/routes/blog/index.tsx similarity index 95% rename from routes/blog/index.tsx rename to plugins/blog/routes/blog/index.tsx index 68f9dc2d0..9bb1f3da1 100644 --- a/routes/blog/index.tsx +++ b/plugins/blog/routes/blog/index.tsx @@ -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) { diff --git a/routes/feed.ts b/plugins/blog/routes/feed.ts similarity index 93% rename from routes/feed.ts rename to plugins/blog/routes/feed.ts index 362401cd3..6647ff09b 100644 --- a/routes/feed.ts +++ b/plugins/blog/routes/feed.ts @@ -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 { Feed } from "npm:feed@4.2.2"; +import { getPosts } from "../utils/posts.ts"; import { SITE_NAME } from "@/utils/constants.ts"; import { defineRoute } from "$fresh/server.ts"; diff --git a/utils/posts.ts b/plugins/blog/utils/posts.ts similarity index 95% rename from utils/posts.ts rename to plugins/blog/utils/posts.ts index 4e9a79d42..002116488 100644 --- a/utils/posts.ts +++ b/plugins/blog/utils/posts.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { extract } from "std/front_matter/yaml.ts"; -import { join } from "std/path/join.ts"; +import { extract } from "$std/front_matter/yaml.ts"; +import { join } from "$std/path/join.ts"; /** * This code is based on the diff --git a/utils/posts_test.ts b/plugins/blog/utils/posts_test.ts similarity index 91% rename from utils/posts_test.ts rename to plugins/blog/utils/posts_test.ts index a3b92a658..6d207ee5e 100644 --- a/utils/posts_test.ts +++ b/plugins/blog/utils/posts_test.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { getPost, getPosts } from "./posts.ts"; -import { assert, assertEquals } from "std/assert/mod.ts"; +import { assert, assertEquals } from "$std/assert/mod.ts"; Deno.test("[blog] getPost()", async () => { const post = await getPost("first-post"); diff --git a/plugins/error_handling.ts b/plugins/error_handling.ts index c5a4d0f82..29e3cd36d 100644 --- a/plugins/error_handling.ts +++ b/plugins/error_handling.ts @@ -2,7 +2,7 @@ import type { Plugin } from "$fresh/server.ts"; import type { State } from "@/plugins/session.ts"; import { BadRequestError, redirect, UnauthorizedError } from "@/utils/http.ts"; -import { STATUS_CODE, STATUS_TEXT } from "std/http/status.ts"; +import { STATUS_CODE, STATUS_TEXT } from "$std/http/status.ts"; /** * Returns the HTTP status code corresponding to a given runtime error. By diff --git a/routes/api/stripe-webhooks.ts b/routes/api/stripe-webhooks.ts index aa5dafe44..e599ae42a 100644 --- a/routes/api/stripe-webhooks.ts +++ b/routes/api/stripe-webhooks.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { type Handlers } from "$fresh/server.ts"; -import { STATUS_CODE } from "std/http/status.ts"; +import { STATUS_CODE } from "$std/http/status.ts"; import { isStripeEnabled, stripe } from "@/utils/stripe.ts"; import Stripe from "stripe"; import { getUserByStripeCustomer, updateUser } from "@/utils/db.ts"; diff --git a/routes/api/vote.ts b/routes/api/vote.ts index 3398d6ef3..698a016f1 100644 --- a/routes/api/vote.ts +++ b/routes/api/vote.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { type Handlers } from "$fresh/server.ts"; -import { STATUS_CODE } from "std/http/status.ts"; +import { STATUS_CODE } from "$std/http/status.ts"; import type { SignedInState } from "@/plugins/session.ts"; import { createVote } from "@/utils/db.ts"; import { BadRequestError } from "@/utils/http.ts"; diff --git a/routes/submit.tsx b/routes/submit.tsx index c7511dc7f..f14f63029 100644 --- a/routes/submit.tsx +++ b/routes/submit.tsx @@ -10,7 +10,7 @@ import { type SignedInState, State, } from "@/plugins/session.ts"; -import { ulid } from "std/ulid/mod.ts"; +import { ulid } from "$std/ulid/mod.ts"; import IconInfo from "tabler_icons_tsx/info-circle.tsx"; const SUBMIT_STYLES = diff --git a/tasks/check_license.ts b/tasks/check_license.ts index 2c21149f9..5eb26b023 100644 --- a/tasks/check_license.ts +++ b/tasks/check_license.ts @@ -1,8 +1,8 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. // Copied from std/_tools/check_license.ts -import { walk } from "std/fs/walk.ts"; -import { globToRegExp } from "std/path/glob_to_regexp.ts"; +import { walk } from "$std/fs/walk.ts"; +import { globToRegExp } from "$std/path/glob_to_regexp.ts"; const EXTENSIONS = [".ts", ".tsx"]; const EXCLUDED_DIRS = [ diff --git a/tasks/db_seed.ts b/tasks/db_seed.ts index a242271ac..95395c51c 100644 --- a/tasks/db_seed.ts +++ b/tasks/db_seed.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. // Description: Seeds the kv db with Hacker News stories import { createItem, createUser } from "@/utils/db.ts"; -import { ulid } from "std/ulid/mod.ts"; +import { ulid } from "$std/ulid/mod.ts"; // Reference: https://github.com/HackerNews/API const API_BASE_URL = `https://hacker-news.firebaseio.com/v0`; diff --git a/utils/db.ts b/utils/db.ts index 0de59738c..444d40c7e 100644 --- a/utils/db.ts +++ b/utils/db.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { ulid } from "std/ulid/mod.ts"; +import { ulid } from "$std/ulid/mod.ts"; const DENO_KV_PATH_KEY = "DENO_KV_PATH"; let path = undefined; @@ -59,7 +59,7 @@ export function randomItem(): Item { * @example * ```ts * import { createItem } from "@/utils/db.ts"; - * import { ulid } from "std/ulid/mod.ts"; + * import { ulid } from "$std/ulid/mod.ts"; * * await createItem({ * id: ulid(), diff --git a/utils/db_test.ts b/utils/db_test.ts index eb4a7c3ca..7de65ef08 100644 --- a/utils/db_test.ts +++ b/utils/db_test.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "std/assert/mod.ts"; -import { ulid } from "std/ulid/mod.ts"; +import { assertEquals, assertRejects } from "$std/assert/mod.ts"; +import { ulid } from "$std/ulid/mod.ts"; import { collectValues, createItem, diff --git a/utils/display.ts b/utils/display.ts index 8c4cad5c9..6139d481a 100644 --- a/utils/display.ts +++ b/utils/display.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { difference } from "std/datetime/difference.ts"; +import { difference } from "$std/datetime/difference.ts"; /** * Returns a pluralized string for the given amount and unit. @@ -22,7 +22,7 @@ export function pluralize(amount: number, unit: string) { * @example * ```ts * import { timeAgo } from "@/utils/display.ts"; - * import { SECOND, MINUTE, HOUR } from "std/datetime/constants.ts"; + * import { SECOND, MINUTE, HOUR } from "$std/datetime/constants.ts"; * * timeAgo(new Date()); // Returns "just now" * timeAgo(new Date(Date.now() - 3 * HOUR)); // Returns "3 hours ago" diff --git a/utils/display_test.ts b/utils/display_test.ts index 50ab34796..7d7842090 100644 --- a/utils/display_test.ts +++ b/utils/display_test.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { formatCurrency, pluralize, timeAgo } from "./display.ts"; -import { DAY, HOUR, MINUTE, SECOND } from "std/datetime/constants.ts"; -import { assertEquals, assertThrows } from "std/assert/mod.ts"; +import { DAY, HOUR, MINUTE, SECOND } from "$std/datetime/constants.ts"; +import { assertEquals, assertThrows } from "$std/assert/mod.ts"; Deno.test("[display] pluralize()", () => { assertEquals(pluralize(0, "item"), "0 items"); diff --git a/utils/github_test.ts b/utils/github_test.ts index bdaab9316..07784cc93 100644 --- a/utils/github_test.ts +++ b/utils/github_test.ts @@ -1,9 +1,9 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { assertRejects } from "std/assert/assert_rejects.ts"; +import { assertRejects } from "$std/assert/assert_rejects.ts"; import { getGitHubUser } from "./github.ts"; -import { returnsNext, stub } from "std/testing/mock.ts"; -import { assertEquals } from "std/assert/assert_equals.ts"; -import { STATUS_CODE } from "std/http/status.ts"; +import { returnsNext, stub } from "$std/testing/mock.ts"; +import { assertEquals } from "$std/assert/assert_equals.ts"; +import { STATUS_CODE } from "$std/http/status.ts"; import { BadRequestError } from "@/utils/http.ts"; Deno.test("[plugins] getGitHubUser()", async (test) => { diff --git a/utils/http.ts b/utils/http.ts index 3b35b5268..084fb5aad 100644 --- a/utils/http.ts +++ b/utils/http.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { RedirectStatus, STATUS_CODE } from "std/http/status.ts"; +import { RedirectStatus, STATUS_CODE } from "$std/http/status.ts"; /** * Returns a response that redirects the client to the given location (URL). diff --git a/utils/http_test.ts b/utils/http_test.ts index c834ee179..621f64516 100644 --- a/utils/http_test.ts +++ b/utils/http_test.ts @@ -1,8 +1,8 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { returnsNext, stub } from "std/testing/mock.ts"; +import { returnsNext, stub } from "$std/testing/mock.ts"; import { fetchValues, getCursor, redirect } from "./http.ts"; -import { assert, assertEquals, assertRejects } from "std/assert/mod.ts"; -import { STATUS_CODE } from "std/http/status.ts"; +import { assert, assertEquals, assertRejects } from "$std/assert/mod.ts"; +import { STATUS_CODE } from "$std/http/status.ts"; import { Item, randomItem } from "@/utils/db.ts"; Deno.test("[http] redirect() defaults", () => { diff --git a/utils/stripe.ts b/utils/stripe.ts index 7a35b5323..f63033eeb 100644 --- a/utils/stripe.ts +++ b/utils/stripe.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import Stripe from "stripe"; -import { AssertionError } from "std/assert/assertion_error.ts"; +import { AssertionError } from "$std/assert/assertion_error.ts"; const STRIPE_SECRET_KEY = Deno.env.get("STRIPE_SECRET_KEY"); diff --git a/utils/stripe_test.ts b/utils/stripe_test.ts index b756b8ad4..22174b59f 100644 --- a/utils/stripe_test.ts +++ b/utils/stripe_test.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { AssertionError, assertThrows } from "std/assert/mod.ts"; +import { AssertionError, assertThrows } from "$std/assert/mod.ts"; import { assertIsPrice } from "./stripe.ts"; Deno.test("[stripe] assertIsPrice()", () => {