From 0a43328bc1d890ed21ea8938bac049d78001250a Mon Sep 17 00:00:00 2001
From: Lino Le Van <11367844+lino-levan@users.noreply.github.com>
Date: Fri, 3 Feb 2023 11:25:28 -0800
Subject: [PATCH] feat: add disable_html_sanitization frontmatter option (#114)
---
blog.tsx | 4 +++-
blog_test.ts | 26 ++++++++++++++++++++++++--
components.tsx | 1 +
deps.ts | 25 +++++++++++++------------
init.ts | 4 ++--
testdata/posts/fourth.md | 10 ++++++++++
types.d.ts | 1 +
7 files changed, 54 insertions(+), 17 deletions(-)
create mode 100644 testdata/posts/fourth.md
diff --git a/blog.tsx b/blog.tsx
index efb65f6..bdd8880 100644
--- a/blog.tsx
+++ b/blog.tsx
@@ -8,6 +8,7 @@
import {
callsites,
+ ColorScheme,
createReporter,
dirname,
Feed,
@@ -101,6 +102,7 @@ function errorHandler(err: unknown) {
*/
export default async function blog(settings?: BlogSettings) {
html.use(UnoCSS(settings?.unocss)); // Load custom unocss module if provided
+ html.use(ColorScheme("auto"));
const url = callsites()[1].getFileName()!;
const blogState = await configureBlog(url, IS_DEV, settings);
@@ -266,6 +268,7 @@ async function loadPost(postsDirectory: string, path: string) {
ogImage: data.get("og:image"),
tags: data.get("tags"),
allowIframes: data.get("allow_iframes"),
+ disableHtmlSanitization: data.get("disable_html_sanitization"),
readTime: readingTime(content),
};
POSTS.set(pathname, post);
@@ -310,7 +313,6 @@ export async function handler(
}
const sharedHtmlOptions: HtmlOptions = {
- colorScheme: blogState.theme ?? "auto",
lang: blogState.lang ?? "en",
scripts: IS_DEV ? [{ src: "/hmr.js" }] : undefined,
links: [
diff --git a/blog_test.ts b/blog_test.ts
index 08dca93..2da36eb 100644
--- a/blog_test.ts
+++ b/blog_test.ts
@@ -5,8 +5,8 @@ import {
assert,
assertEquals,
assertStringIncludes,
-} from "https://deno.land/std@0.171.0/testing/asserts.ts";
-import { fromFileUrl, join } from "https://deno.land/std@0.171.0/path/mod.ts";
+} from "https://deno.land/std@0.176.0/testing/asserts.ts";
+import { fromFileUrl, join } from "https://deno.land/std@0.176.0/path/mod.ts";
const BLOG_URL = new URL("./testdata/main.js", import.meta.url).href;
const TESTDATA_PATH = fromFileUrl(new URL("./testdata/", import.meta.url));
@@ -138,6 +138,28 @@ Deno.test("posts/ third", async () => {
assertStringIncludes(body, `
Lorem Ipsum is simply dummy text`);
});
+Deno.test("posts/ fourth", async () => {
+ const resp = await testHandler(new Request("https://blog.deno.dev/fourth"));
+ assert(resp);
+ assertEquals(resp.status, 200);
+ assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
+ const body = await resp.text();
+ assertStringIncludes(body, ``);
+ assertStringIncludes(
+ body,
+ ``,
+ );
+ assertStringIncludes(body, `Fourth post`);
+ assertStringIncludes(
+ body,
+ `