diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c1f08dc..972469d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,9 @@ jobs: uses: actions/checkout@v2 - name: Install Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x - name: Check formatting run: deno fmt --check diff --git a/blog.tsx b/blog.tsx index 08ed81a2..459b749a 100644 --- a/blog.tsx +++ b/blog.tsx @@ -1,35 +1,21 @@ // Copyright 2022 the Deno authors. All rights reserved. MIT license. /** @jsx h */ -/// -/// -/// -/// - -import { - callsites, - ColorScheme, - createReporter, - dirname, - Feed, - Fragment, - fromFileUrl, - frontMatter, - gfm, - h, - html, - HtmlOptions, - join, - relative, - removeMarkdown, - serve, - serveDir, - UnoCSS, - walk, -} from "./deps.ts"; -import { pooledMap } from "https://deno.land/std@0.187.0/async/pool.ts"; + +import * as gfm from "@deno/gfm"; +import { pooledMap } from "@std/async"; +import { extractYaml as frontMatter } from "@std/front-matter"; +import { walk, WalkEntry } from "@std/fs"; +import { serveDir } from "@std/http"; +import { dirname, fromFileUrl, join, relative } from "@std/path"; +import callsites from "callsites"; +import { Feed, type Item as FeedItem } from "feed"; +import { createReporter } from "ga"; +import html, { Fragment, h, HtmlOptions } from "htm/html.tsx"; +import ColorScheme from "htm/plugins/color-scheme.ts"; +import UnoCSS from "htm/plugins/unocss.ts"; +import removeMarkdown from "remove-markdown"; import { Index, PostPage } from "./components.tsx"; -import type { ConnInfo, FeedItem } from "./deps.ts"; import type { BlogContext, BlogMiddleware, @@ -37,7 +23,6 @@ import type { BlogState, Post, } from "./types.d.ts"; -import { WalkEntry } from "https://deno.land/std@0.176.0/fs/walk.ts"; export { Fragment, h }; @@ -110,17 +95,17 @@ export default async function blog(settings?: BlogSettings) { const blogState = await configureBlog(url, IS_DEV, settings); const blogHandler = createBlogHandler(blogState); - serve(blogHandler, { + Deno.serve({ port: blogState.port, hostname: blogState.hostname, onError: errorHandler, - }); + }, blogHandler); } export function createBlogHandler(state: BlogState) { const inner = handler; const withMiddlewares = composeMiddlewares(state); - return function handler(req: Request, connInfo: ConnInfo) { + return function handler(req: Request, connInfo: Deno.ServeHandlerInfo) { // Redirect requests that end with a trailing slash // to their non-trailing slash counterpart. // Ex: /about/ -> /about @@ -136,7 +121,7 @@ export function createBlogHandler(state: BlogState) { function composeMiddlewares(state: BlogState) { return ( req: Request, - connInfo: ConnInfo, + connInfo: Deno.ServeHandlerInfo, inner: (req: Request, ctx: BlogContext) => Promise, ) => { const mws = state.middlewares?.slice().reverse(); @@ -232,7 +217,7 @@ async function watchForChanges(postsDirectory: string) { socket.send("refresh"); }); } catch (err) { - console.error(`loadPost ${path} error:`, err.message); + console.error(`loadPost ${path} error:`, (err as Error).message); } } } @@ -436,7 +421,7 @@ export async function handler( } catch (e) { if (!(e instanceof Deno.errors.NotFound)) { console.error(e); - return new Response(e.message, { status: 500 }); + return new Response((e as Error).message, { status: 500 }); } } @@ -553,7 +538,7 @@ export function redirects(redirectMap: Record): BlogMiddleware { return await ctx.next(); } catch (e) { console.error(e); - return new Response(`Internal server error: ${e.message}`, { + return new Response(`Internal server error: ${(e as Error).message}`, { status: 500, }); } diff --git a/blog_test.ts b/blog_test.ts index 71f0c00a..196f8b78 100644 --- a/blog_test.ts +++ b/blog_test.ts @@ -1,12 +1,8 @@ // Copyright 2022 the Deno authors. All rights reserved. MIT license. import { configureBlog, createBlogHandler, redirects } from "./blog.tsx"; -import { - assert, - assertEquals, - assertStringIncludes, -} from "https://deno.land/std@0.193.0/testing/asserts.ts"; -import { fromFileUrl, join } from "https://deno.land/std@0.193.0/path/mod.ts"; +import { assert, assertEquals, assertStringIncludes } from "@std/assert"; +import { fromFileUrl, join } from "@std/path"; const BLOG_URL = new URL("./testdata/main.js", import.meta.url).href; const TESTDATA_PATH = fromFileUrl(new URL("./testdata/", import.meta.url)); @@ -26,17 +22,13 @@ const BLOG_SETTINGS = await configureBlog(BLOG_URL, false, { readtime: true, }); const CONN_INFO = { - localAddr: { - transport: "tcp" as const, - hostname: "0.0.0.0", - port: 8000, - }, remoteAddr: { transport: "tcp" as const, hostname: "0.0.0.0", - port: 8001, + port: 8000, }, -}; + completed: Promise.resolve(), +} satisfies Deno.ServeHandlerInfo; const blogHandler = createBlogHandler(BLOG_SETTINGS); const testHandler = (req: Request): Response | Promise => { diff --git a/components.tsx b/components.tsx index e75b180c..969a7d64 100644 --- a/components.tsx +++ b/components.tsx @@ -1,13 +1,9 @@ // Copyright 2022 the Deno authors. All rights reserved. MIT license. /** @jsx h */ -/** @jsxFrag Fragment */ -/// -/// -/// -/// -import { gfm, h } from "./deps.ts"; +import * as gfm from "@deno/gfm"; +import { h } from "htm/html.tsx"; import type { BlogState, DateFormat, Post } from "./types.d.ts"; const socialAppIcons = new Map([ diff --git a/deno.jsonc b/deno.jsonc index 97f2e81a..aadcce4e 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,7 +1,21 @@ { "lock": false, "tasks": { - "demo": "deno run --allow-net --allow-read --allow-env=NODE_DEBUG --watch --no-check testdata/my_blog.ts --dev", + "demo": "deno run --allow-net --allow-read --allow-env --watch --no-check testdata/my_blog.ts --dev", "test": "deno test --no-check=remote --allow-read" + }, + "imports": { + "@deno/gfm": "jsr:@deno/gfm@^0.10.0", + "@std/assert": "jsr:@std/assert@^1.0.11", + "@std/async": "jsr:@std/async@^1.0.10", + "@std/front-matter": "jsr:@std/front-matter@^1.0.5", + "@std/fs": "jsr:@std/fs@^1.0.11", + "@std/http": "jsr:@std/http@^1.0.13", + "@std/path": "jsr:@std/path@^1.0.8", + "callsites": "npm:callsites@^4.2.0", + "feed": "npm:feed@^4.2.2", + "ga": "https://deno.land/x/g_a@0.1.2/mod.ts", + "htm/": "https://deno.land/x/htm@0.1.3/", + "remove-markdown": "npm:remove-markdown@^0.6.0" } } diff --git a/deps.ts b/deps.ts deleted file mode 100644 index d10e46cf..00000000 --- a/deps.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2022 the Deno authors. All rights reserved. MIT license. - -export { serveDir } from "https://deno.land/std@0.193.0/http/file_server.ts"; -export { walk } from "https://deno.land/std@0.193.0/fs/walk.ts"; -export { - dirname, - fromFileUrl, - join, - relative, -} from "https://deno.land/std@0.193.0/path/mod.ts"; -export { - type ConnInfo, - serve, -} from "https://deno.land/std@0.193.0/http/mod.ts"; -export { extract as frontMatter } from "https://deno.land/std@0.193.0/front_matter/any.ts"; - -export * as gfm from "jsr:@deno/gfm@0.10.0"; -export { Fragment, h } from "https://deno.land/x/htm@0.1.3/mod.ts"; -export { - default as html, - type HtmlOptions, - type VNode, -} from "https://deno.land/x/htm@0.1.3/html.tsx"; -import UnoCSS from "https://deno.land/x/htm@0.1.3/plugins/unocss.ts"; -import ColorScheme from "https://deno.land/x/htm@0.1.3/plugins/color-scheme.ts"; - -export { - createReporter, - type Reporter as GaReporter, -} from "https://deno.land/x/g_a@0.1.2/mod.ts"; -export { default as callsites } from "https://raw.githubusercontent.com/kt3k/callsites/v1.0.0/mod.ts"; -export { Feed, type Item as FeedItem } from "https://esm.sh/feed@4.2.2"; -export { default as removeMarkdown } from "https://esm.sh/remove-markdown@0.5.0"; - -// Add syntax highlighting support for C by default -import "https://esm.sh/prismjs@1.29.0/components/prism-c?no-check"; - -export { ColorScheme, UnoCSS }; -export type UnoConfig = typeof UnoCSS extends ( - arg: infer P | undefined, -) => unknown ? P - : never; diff --git a/init.ts b/init.ts index 0cac8850..bf7a3a9f 100644 --- a/init.ts +++ b/init.ts @@ -1,6 +1,6 @@ // Copyright 2022 the Deno authors. All rights reserved. MIT license. -import { join, resolve } from "https://deno.land/std@0.193.0/path/mod.ts"; +import { join, resolve } from "@std/path"; const HELP = `deno_blog diff --git a/types.d.ts b/types.d.ts index 694be92b..693d29b9 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,10 +1,11 @@ // Copyright 2022 the Deno authors. All rights reserved. MIT license. -import type { ConnInfo, UnoConfig, VNode } from "./deps.ts"; +import { type VNode } from "htm/html.tsx"; +import UnoCSS from "htm/plugins/unocss.ts"; export interface BlogContext { state: BlogState; - connInfo: ConnInfo; + connInfo: Deno.ServeHandlerInfo; next: () => Promise; } @@ -103,3 +104,8 @@ export interface Post { readTime: number; renderMath?: boolean; } + +export type UnoConfig = typeof UnoCSS extends ( + arg: infer P | undefined, +) => unknown ? P + : never;