From 90992cf03527121002f96cba8c1539b75479e67a Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Wed, 24 Jan 2024 09:11:06 +0100 Subject: [PATCH 01/12] feat: pluginify blog --- deno.json | 2 +- fresh.config.ts | 2 ++ fresh.gen.ts | 4 ---- plugins/blog.ts | 22 ++++++++++++++++++++++ {routes => plugins/routes}/blog/[slug].tsx | 4 ++-- {routes => plugins/routes}/blog/index.tsx | 2 +- 6 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 plugins/blog.ts rename {routes => plugins/routes}/blog/[slug].tsx (92%) rename {routes => plugins/routes}/blog/index.tsx (95%) diff --git a/deno.json b/deno.json index 953d01ad8..607f3f493 100644 --- a/deno.json +++ b/deno.json @@ -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/", "$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/", diff --git a/fresh.config.ts b/fresh.config.ts index 9cbeeaff5..237169210 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.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..a3e34945f 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -16,8 +16,6 @@ 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"; @@ -48,8 +46,6 @@ 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, diff --git a/plugins/blog.ts b/plugins/blog.ts new file mode 100644 index 000000000..69ab20c32 --- /dev/null +++ b/plugins/blog.ts @@ -0,0 +1,22 @@ +// 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"; + +export function blog() { + const currentUrl = new URL(import.meta.url); + currentUrl.pathname = currentUrl.pathname.split("/").slice(0, -2).join("/") + + "/"; + return { + name: "blog", + routes: [{ + path: "/blog", + component: BlogIndex, + }, { + path: "/blog/[slug]", + component: BlogSlug, + }], + location: import.meta.url, + projectLocation: currentUrl.href, + } satisfies Plugin; +} diff --git a/routes/blog/[slug].tsx b/plugins/routes/blog/[slug].tsx similarity index 92% rename from routes/blog/[slug].tsx rename to plugins/routes/blog/[slug].tsx index a7047de9d..1381917c9 100644 --- a/routes/blog/[slug].tsx +++ b/plugins/routes/blog/[slug].tsx @@ -2,8 +2,8 @@ import { defineRoute } from "$fresh/server.ts"; import { CSS, render } from "$gfm"; import { getPost } from "@/utils/posts.ts"; -import Head from "@/components/Head.tsx"; -import Share from "@/components/Share.tsx"; +import Head from "../../../components/Head.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/routes/blog/index.tsx similarity index 95% rename from routes/blog/index.tsx rename to plugins/routes/blog/index.tsx index 68f9dc2d0..fe849193b 100644 --- a/routes/blog/index.tsx +++ b/plugins/routes/blog/index.tsx @@ -1,7 +1,7 @@ // 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 Head from "@/components/Head.tsx"; +import Head from "../../../components/Head.tsx"; function PostCard(props: Post) { return ( From 240c7422d1388bc0fedbc9115f014a443a497b35 Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Wed, 24 Jan 2024 14:34:28 +0100 Subject: [PATCH 02/12] fix: revert hack --- plugins/blog.ts | 4 ++-- plugins/routes/blog/[slug].tsx | 4 ++-- plugins/routes/blog/index.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/blog.ts b/plugins/blog.ts index 69ab20c32..f035b5505 100644 --- a/plugins/blog.ts +++ b/plugins/blog.ts @@ -1,7 +1,7 @@ // 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 BlogIndex from "@/plugins/routes/blog/index.tsx"; +import BlogSlug from "@/plugins/routes/blog/[slug].tsx"; export function blog() { const currentUrl = new URL(import.meta.url); diff --git a/plugins/routes/blog/[slug].tsx b/plugins/routes/blog/[slug].tsx index 1381917c9..a7047de9d 100644 --- a/plugins/routes/blog/[slug].tsx +++ b/plugins/routes/blog/[slug].tsx @@ -2,8 +2,8 @@ import { defineRoute } from "$fresh/server.ts"; import { CSS, render } from "$gfm"; import { getPost } from "@/utils/posts.ts"; -import Head from "../../../components/Head.tsx"; -import Share from "../../../components/Share.tsx"; +import Head from "@/components/Head.tsx"; +import Share from "@/components/Share.tsx"; export default defineRoute(async (_req, ctx) => { const post = await getPost(ctx.params.slug); diff --git a/plugins/routes/blog/index.tsx b/plugins/routes/blog/index.tsx index fe849193b..68f9dc2d0 100644 --- a/plugins/routes/blog/index.tsx +++ b/plugins/routes/blog/index.tsx @@ -1,7 +1,7 @@ // 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 Head from "../../../components/Head.tsx"; +import Head from "@/components/Head.tsx"; function PostCard(props: Post) { return ( From 8ddbc4841bea3e34b1b39ac710ea79c6247d4b44 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 25 Jan 2024 18:18:24 +1100 Subject: [PATCH 03/12] tweaks --- plugins/blog.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/blog.ts b/plugins/blog.ts index f035b5505..cdec1b599 100644 --- a/plugins/blog.ts +++ b/plugins/blog.ts @@ -1,12 +1,10 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import type { Plugin } from "$fresh/server.ts"; -import BlogIndex from "@/plugins/routes/blog/index.tsx"; -import BlogSlug from "@/plugins/routes/blog/[slug].tsx"; +import BlogIndex from "./routes/blog/index.tsx"; +import BlogSlug from "./routes/blog/[slug].tsx"; +import { toFileUrl } from "std/path/to_file_url.ts"; export function blog() { - const currentUrl = new URL(import.meta.url); - currentUrl.pathname = currentUrl.pathname.split("/").slice(0, -2).join("/") + - "/"; return { name: "blog", routes: [{ @@ -17,6 +15,6 @@ export function blog() { component: BlogSlug, }], location: import.meta.url, - projectLocation: currentUrl.href, + projectLocation: toFileUrl(Deno.cwd()).href, } satisfies Plugin; } From 66c7b092c5bcf9328c134eceadb05e2de609ba4e Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Thu, 25 Jan 2024 15:54:12 +0100 Subject: [PATCH 04/12] move all blog content into one folder --- fresh.config.ts | 2 +- plugins/{ => blog}/blog.ts | 0 plugins/{ => blog}/routes/blog/[slug].tsx | 2 +- plugins/{ => blog}/routes/blog/index.tsx | 2 +- {utils => plugins/blog/utils}/posts.ts | 0 {utils => plugins/blog/utils}/posts_test.ts | 0 routes/feed.ts | 2 +- 7 files changed, 4 insertions(+), 4 deletions(-) rename plugins/{ => blog}/blog.ts (100%) rename plugins/{ => blog}/routes/blog/[slug].tsx (96%) rename plugins/{ => blog}/routes/blog/index.tsx (95%) rename {utils => plugins/blog/utils}/posts.ts (100%) rename {utils => plugins/blog/utils}/posts_test.ts (100%) diff --git a/fresh.config.ts b/fresh.config.ts index 237169210..3aaf7d7a9 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -7,7 +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.ts"; +import { blog } from "./plugins/blog/blog.ts"; export default { plugins: [ diff --git a/plugins/blog.ts b/plugins/blog/blog.ts similarity index 100% rename from plugins/blog.ts rename to plugins/blog/blog.ts diff --git a/plugins/routes/blog/[slug].tsx b/plugins/blog/routes/blog/[slug].tsx similarity index 96% rename from plugins/routes/blog/[slug].tsx rename to plugins/blog/routes/blog/[slug].tsx index a7047de9d..a910076c5 100644 --- a/plugins/routes/blog/[slug].tsx +++ b/plugins/blog/routes/blog/[slug].tsx @@ -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"; diff --git a/plugins/routes/blog/index.tsx b/plugins/blog/routes/blog/index.tsx similarity index 95% rename from plugins/routes/blog/index.tsx rename to plugins/blog/routes/blog/index.tsx index 68f9dc2d0..9bb1f3da1 100644 --- a/plugins/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/utils/posts.ts b/plugins/blog/utils/posts.ts similarity index 100% rename from utils/posts.ts rename to plugins/blog/utils/posts.ts diff --git a/utils/posts_test.ts b/plugins/blog/utils/posts_test.ts similarity index 100% rename from utils/posts_test.ts rename to plugins/blog/utils/posts_test.ts diff --git a/routes/feed.ts b/routes/feed.ts index 362401cd3..00c04e982 100644 --- a/routes/feed.ts +++ b/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 { getPosts } from "@/plugins/blog/utils/posts.ts"; import { SITE_NAME } from "@/utils/constants.ts"; import { defineRoute } from "$fresh/server.ts"; From 2e250339a901651b1b7ba13a01f5909e0232d398 Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Fri, 26 Jan 2024 05:28:35 +0100 Subject: [PATCH 05/12] chore: include feed and rename to mod.ts --- fresh.config.ts | 2 +- fresh.gen.ts | 2 -- plugins/blog/{blog.ts => mod.ts} | 4 ++++ {routes => plugins/blog/routes}/feed.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) rename plugins/blog/{blog.ts => mod.ts} (86%) rename {routes => plugins/blog/routes}/feed.ts (95%) diff --git a/fresh.config.ts b/fresh.config.ts index 3aaf7d7a9..922ba6837 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -7,7 +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/blog.ts"; +import { blog } from "./plugins/blog/mod.ts"; export default { plugins: [ diff --git a/fresh.gen.ts b/fresh.gen.ts index a3e34945f..95b1809f3 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -19,7 +19,6 @@ import * as $api_vote from "./routes/api/vote.ts"; 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"; @@ -49,7 +48,6 @@ const manifest = { "./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/blog.ts b/plugins/blog/mod.ts similarity index 86% rename from plugins/blog/blog.ts rename to plugins/blog/mod.ts index cdec1b599..18fdcad6c 100644 --- a/plugins/blog/blog.ts +++ b/plugins/blog/mod.ts @@ -2,6 +2,7 @@ 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() { @@ -13,6 +14,9 @@ export function blog() { }, { path: "/blog/[slug]", component: BlogSlug, + }, { + path: "/feed", + component: Feed, }], location: import.meta.url, projectLocation: toFileUrl(Deno.cwd()).href, diff --git a/routes/feed.ts b/plugins/blog/routes/feed.ts similarity index 95% rename from routes/feed.ts rename to plugins/blog/routes/feed.ts index 00c04e982..7d19800d0 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 "@/plugins/blog/utils/posts.ts"; +import { getPosts } from "../utils/posts.ts"; import { SITE_NAME } from "@/utils/constants.ts"; import { defineRoute } from "$fresh/server.ts"; From c6ac731ddf58fff1979c442843ee0a5dfba3d663 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 8 Feb 2024 15:00:57 +1100 Subject: [PATCH 06/12] refactor: use `$std` import --- deno.json | 2 +- e2e_test.ts | 6 +++--- islands/ItemsList.tsx | 2 +- plugins/blog/mod.ts | 2 +- plugins/blog/utils/posts.ts | 4 ++-- plugins/blog/utils/posts_test.ts | 2 +- plugins/error_handling.ts | 2 +- routes/api/stripe-webhooks.ts | 2 +- routes/api/vote.ts | 2 +- routes/submit.tsx | 2 +- tasks/check_license.ts | 4 ++-- tasks/db_seed.ts | 2 +- utils/db.ts | 4 ++-- utils/db_test.ts | 4 ++-- utils/display.ts | 4 ++-- utils/display_test.ts | 4 ++-- utils/github_test.ts | 8 ++++---- utils/http.ts | 2 +- utils/http_test.ts | 6 +++--- utils/stripe.ts | 2 +- utils/stripe_test.ts | 2 +- 21 files changed, 34 insertions(+), 34 deletions(-) diff --git a/deno.json b/deno.json index 4678ad949..1de9ae0d9 100644 --- a/deno.json +++ b/deno.json @@ -30,7 +30,7 @@ "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/", 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/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/plugins/blog/mod.ts b/plugins/blog/mod.ts index 18fdcad6c..7570cd4bc 100644 --- a/plugins/blog/mod.ts +++ b/plugins/blog/mod.ts @@ -3,7 +3,7 @@ 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"; +import { toFileUrl } from "$std/path/to_file_url.ts"; export function blog() { return { diff --git a/plugins/blog/utils/posts.ts b/plugins/blog/utils/posts.ts index 4e9a79d42..002116488 100644 --- a/plugins/blog/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/plugins/blog/utils/posts_test.ts b/plugins/blog/utils/posts_test.ts index a3b92a658..6d207ee5e 100644 --- a/plugins/blog/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 b490768f4..212e8b53f 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()", () => { From d467c89b86e16915916b43814e7876fbd341098c Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 8 Feb 2024 15:05:48 +1100 Subject: [PATCH 07/12] refactor: move `` component --- {components => plugins/blog/components}/Share.tsx | 0 plugins/blog/routes/blog/[slug].tsx | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {components => plugins/blog/components}/Share.tsx (100%) 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/routes/blog/[slug].tsx b/plugins/blog/routes/blog/[slug].tsx index a910076c5..596fb528a 100644 --- a/plugins/blog/routes/blog/[slug].tsx +++ b/plugins/blog/routes/blog/[slug].tsx @@ -3,7 +3,7 @@ import { defineRoute } from "$fresh/server.ts"; import { CSS, render } from "$gfm"; 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); From 35b43f10a5924a42a8ba13aa0aac39f78c11bc21 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 8 Feb 2024 15:09:03 +1100 Subject: [PATCH 08/12] refactor: remove import-mapped `$gfm` specifier --- deno.json | 1 - plugins/blog/routes/blog/[slug].tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 1de9ae0d9..8128beeef 100644 --- a/deno.json +++ b/deno.json @@ -21,7 +21,6 @@ "imports": { "@/": "./", "$fresh/": "https://raw.githubusercontent.com/deer/fresh/2159_plugin_routes_tailwind/", - "$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/", "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2", diff --git a/plugins/blog/routes/blog/[slug].tsx b/plugins/blog/routes/blog/[slug].tsx index 596fb528a..55c01b9cf 100644 --- a/plugins/blog/routes/blog/[slug].tsx +++ b/plugins/blog/routes/blog/[slug].tsx @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { defineRoute } from "$fresh/server.ts"; -import { CSS, render } from "$gfm"; +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"; From 8fe2d34d695b51a7d07bdaccfca8adb1bbdd587f Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 8 Feb 2024 15:10:34 +1100 Subject: [PATCH 09/12] refactor: remove import-mapped `feed` specifier --- deno.json | 1 - plugins/blog/routes/feed.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 8128beeef..217a24dd3 100644 --- a/deno.json +++ b/deno.json @@ -31,7 +31,6 @@ "tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js", "$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/plugins/blog/routes/feed.ts b/plugins/blog/routes/feed.ts index 7d19800d0..6647ff09b 100644 --- a/plugins/blog/routes/feed.ts +++ b/plugins/blog/routes/feed.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { Feed } from "feed"; +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"; From 2adce23620d4d740bf105e2f8b334c85a288efb5 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 8 Feb 2024 15:12:58 +1100 Subject: [PATCH 10/12] refactor: tweak `blog()` plugin function --- plugins/blog/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/blog/mod.ts b/plugins/blog/mod.ts index 7570cd4bc..f6818c90a 100644 --- a/plugins/blog/mod.ts +++ b/plugins/blog/mod.ts @@ -5,7 +5,7 @@ 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() { +export function blog(): Plugin { return { name: "blog", routes: [{ @@ -20,5 +20,5 @@ export function blog() { }], location: import.meta.url, projectLocation: toFileUrl(Deno.cwd()).href, - } satisfies Plugin; + }; } From a1511c2788f5ed20e4083981e7a76230445885ff Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Mon, 19 Feb 2024 09:01:08 +0100 Subject: [PATCH 11/12] pin version to 1.6.5 merge commit --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 217a24dd3..4f26f20bf 100644 --- a/deno.json +++ b/deno.json @@ -20,7 +20,7 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, "imports": { "@/": "./", - "$fresh/": "https://raw.githubusercontent.com/deer/fresh/2159_plugin_routes_tailwind/", + "$fresh/": "https://raw.githubusercontent.com/denoland/fresh/3cb107bbd1fcf94986e4207097e555e1b41ab926/", "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", From a26406ca3897ff5f065fcd4489c7773a4c1a6bf0 Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Sun, 25 Feb 2024 07:25:43 +0100 Subject: [PATCH 12/12] don't rely on cwd for project location --- deno.json | 2 +- plugins/blog/mod.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deno.json b/deno.json index 4f26f20bf..ecd0a97cd 100644 --- a/deno.json +++ b/deno.json @@ -20,7 +20,7 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, "imports": { "@/": "./", - "$fresh/": "https://raw.githubusercontent.com/denoland/fresh/3cb107bbd1fcf94986e4207097e555e1b41ab926/", + "$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", diff --git a/plugins/blog/mod.ts b/plugins/blog/mod.ts index f6818c90a..c2f27cb66 100644 --- a/plugins/blog/mod.ts +++ b/plugins/blog/mod.ts @@ -3,7 +3,7 @@ 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"; +import { normalize } from "$std/url/normalize.ts"; export function blog(): Plugin { return { @@ -19,6 +19,6 @@ export function blog(): Plugin { component: Feed, }], location: import.meta.url, - projectLocation: toFileUrl(Deno.cwd()).href, + projectLocation: normalize(import.meta.url + "../../../").href, }; }