Skip to content

Commit

Permalink
chore: use markup_fmt, malva and pretty_yaml internally (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored Jul 11, 2024
1 parent a668846 commit ea071c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
7 changes: 6 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"malva": {
"blockSelectorLinebreak": "always"
},
"excludes": [
"**/node_modules",
"**/*-lock.json"
Expand All @@ -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"
]
}
30 changes: 20 additions & 10 deletions handleRequest.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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")) {
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ea071c9

Please # to comment.