From ea071c96744a3609045f48b328edd485d08cfa94 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 11 Jul 2024 11:09:12 +0800 Subject: [PATCH] chore: use markup_fmt, malva and pretty_yaml internally (#21) --- dprint.json | 7 ++++++- handleRequest.ts | 30 ++++++++++++++++++++---------- style.css | 12 ++++++++++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/dprint.json b/dprint.json index 5473381..281ae36 100644 --- a/dprint.json +++ b/dprint.json @@ -1,4 +1,7 @@ { + "malva": { + "blockSelectorLinebreak": "always" + }, "excludes": [ "**/node_modules", "**/*-lock.json" @@ -7,6 +10,8 @@ "https://plugins.dprint.dev/typescript-0.88.7.wasm", "https://plugins.dprint.dev/json-0.19.1.wasm", "https://plugins.dprint.dev/markdown-0.16.3.wasm", - "https://plugins.dprint.dev/prettier-0.31.0.json@8808616145fecc35574b79e78620f7fb241afba445201e64042dc78e01a1022b" + "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.3.0.wasm", + "https://plugins.dprint.dev/g-plane/malva-v0.5.1.wasm", + "https://plugins.dprint.dev/g-plane/markup_fmt-v0.10.0.wasm" ] } diff --git a/handleRequest.ts b/handleRequest.ts index 0cf6232..074fa2a 100644 --- a/handleRequest.ts +++ b/handleRequest.ts @@ -1,5 +1,5 @@ import { renderHome } from "./home.tsx"; -import oldMappings from "./old_redirects.json" assert { type: "json" }; +import oldMappings from "./old_redirects.json" with { type: "json" }; import { tryResolveLatestJson, tryResolvePluginUrl, tryResolveSchemaUrl } from "./plugins.ts"; import { readInfoFile } from "./readInfoFile.ts"; import { Clock } from "./utils/clock.ts"; @@ -40,13 +40,19 @@ export function createRequestHandler(clock: Clock) { status: 404, }); } else { - return createJsonResponse(JSON.stringify(userLatestInfo, undefined, 2), request); + return createJsonResponse( + JSON.stringify(userLatestInfo, undefined, 2), + request, + ); } } if (url.pathname.startsWith("/info.json")) { const infoFileData = await readInfoFile(); - return createJsonResponse(JSON.stringify(infoFileData, null, 2), request); + return createJsonResponse( + JSON.stringify(infoFileData, null, 2), + request, + ); } if (url.pathname.startsWith("/cli.json")) { @@ -55,7 +61,7 @@ export function createRequestHandler(clock: Clock) { } if (url.pathname === "/style.css") { - return Deno.readTextFile("./style.css").then(text => + return Deno.readTextFile("./style.css").then((text) => new Response(text, { headers: { "content-type": "text/css; charset=utf-8", @@ -66,14 +72,14 @@ export function createRequestHandler(clock: Clock) { } if (url.pathname === "/") { - return renderHome().then(home => + return renderHome().then((home) => new Response(home, { headers: { "content-type": contentTypes.html, }, status: 200, }) - ).catch(err => + ).catch((err) => new Response(`${err.toString?.() ?? err}`, { headers: { "content-type": contentTypes.plain, @@ -96,7 +102,7 @@ export function createRequestHandler(clock: Clock) { }) { if (shouldDirectlyServeFile(params.request)) { return fetchCached(params) - .then(result => { + .then((result) => { if (result.kind === "error") { return result.response; } @@ -105,11 +111,13 @@ export function createRequestHandler(clock: Clock) { headers: { "content-type": params.contentType, // allow the playground to download this - "Access-Control-Allow-Origin": getAccessControlAllowOrigin(params.request), + "Access-Control-Allow-Origin": getAccessControlAllowOrigin( + params.request, + ), }, status: 200, }); - }).catch(err => { + }).catch((err) => { console.error(err); return new Response("Internal Server Error", { status: 500, @@ -129,7 +137,9 @@ async function resolvePluginOrSchemaUrl(url: URL) { function getAccessControlAllowOrigin(request: Request) { const origin = request.headers.get("origin"); - return origin != null && new URL(origin).hostname === "localhost" ? origin : "https://dprint.dev"; + return origin != null && new URL(origin).hostname === "localhost" + ? origin + : "https://dprint.dev"; } function shouldDirectlyServeFile(request: Request) { diff --git a/style.css b/style.css index 86c453a..ce11505 100644 --- a/style.css +++ b/style.css @@ -13,8 +13,16 @@ body { display: flex; flex: 1; flex-direction: column; - font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", - "Droid Sans", "Helvetica Neue", sans-serif; + font-family: + "Segoe UI", + Roboto, + Oxygen, + Ubuntu, + Cantarell, + "Fira Sans", + "Droid Sans", + "Helvetica Neue", + sans-serif; } h1 {