Skip to content

Commit

Permalink
fix: Change address bar color on Mobile when using Dark Theme (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe-53 committed Jul 6, 2023
1 parent 0139043 commit 659f5b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
6 changes: 6 additions & 0 deletions blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ export async function handler(
],
};

const sharedMetaTags = {
"theme-color": blogState.theme === "dark" ? "#000" : null,
};

if (typeof blogState.favicon === "string") {
sharedHtmlOptions.links?.push({
href: blogState.favicon,
Expand Down Expand Up @@ -364,6 +368,7 @@ export async function handler(
...sharedHtmlOptions,
title: blogState.title ?? "My Blog",
meta: {
...sharedMetaTags,
"description": blogState.description,
"og:title": blogState.title,
"og:description": blogState.description,
Expand Down Expand Up @@ -397,6 +402,7 @@ export async function handler(
...sharedHtmlOptions,
title: post.title,
meta: {
...sharedMetaTags,
"description": post.snippet,
"og:title": post.title,
"og:description": post.snippet,
Expand Down
78 changes: 46 additions & 32 deletions blog_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ Deno.test("posts/ first", async () => {
);
assertStringIncludes(body, `First post`);
assertStringIncludes(body, `The author`);
assertStringIncludes(
body,
`<time dateTime="2022-03-20T00:00:00.000Z">`,
);
assertStringIncludes(body, `<time dateTime="2022-03-20T00:00:00.000Z">`);
assertStringIncludes(body, `<img src="first/hello.png" />`);
assertStringIncludes(body, `<p>Lorem Ipsum is simply dummy text`);
assertStringIncludes(body, `$100, $200, $300, $400, $500`);
Expand Down Expand Up @@ -110,10 +107,7 @@ Deno.test("posts/ second", async () => {
);
assertStringIncludes(body, `Second post`);
assertStringIncludes(body, `CUSTOM AUTHOR NAME`);
assertStringIncludes(
body,
`<time dateTime="2022-05-02T00:00:00.000Z">`,
);
assertStringIncludes(body, `<time dateTime="2022-05-02T00:00:00.000Z">`);
assertStringIncludes(body, `<img src="second/hello2.png" />`);
assertStringIncludes(body, `<p>Lorem Ipsum is simply dummy text`);
});
Expand All @@ -131,10 +125,7 @@ Deno.test("posts/ third", async () => {
);
assertStringIncludes(body, `Third post`);
assertStringIncludes(body, `CUSTOM AUTHOR NAME`);
assertStringIncludes(
body,
`<time dateTime="2022-08-19T00:00:00.000Z">`,
);
assertStringIncludes(body, `<time dateTime="2022-08-19T00:00:00.000Z">`);
assertStringIncludes(body, `<iframe width="560" height="315"`);
assertStringIncludes(body, `<p>Lorem Ipsum is simply dummy text`);
});
Expand Down Expand Up @@ -251,9 +242,7 @@ Deno.test("static files in posts/ directory", async () => {
const bytes = new Uint8Array(await resp.arrayBuffer());
assertEquals(
bytes,
await Deno.readFile(
join(TESTDATA_PATH, "./posts/first/hello.png"),
),
await Deno.readFile(join(TESTDATA_PATH, "./posts/first/hello.png")),
);
}
{
Expand All @@ -266,12 +255,7 @@ Deno.test("static files in posts/ directory", async () => {
const bytes = new Uint8Array(await resp.arrayBuffer());
assertEquals(
bytes,
await Deno.readFile(
join(
TESTDATA_PATH,
"./posts/second/hello2.png",
),
),
await Deno.readFile(join(TESTDATA_PATH, "./posts/second/hello2.png")),
);
}
});
Expand All @@ -282,12 +266,7 @@ Deno.test("static files in root directory", async () => {
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "image/png");
const bytes = new Uint8Array(await resp.arrayBuffer());
assertEquals(
bytes,
await Deno.readFile(
join(TESTDATA_PATH, "./cat.png"),
),
);
assertEquals(bytes, await Deno.readFile(join(TESTDATA_PATH, "./cat.png")));
});

Deno.test("RSS feed", async () => {
Expand All @@ -306,9 +285,47 @@ Deno.test("RSS feed", async () => {
assertStringIncludes(body, `https://blog.deno.dev/second`);
});

Deno.test(
"theme-color meta tag when dark theme is used [index page]",
async () => {
const darkThemeBlogHandler = createBlogHandler({
...BLOG_SETTINGS,
theme: "dark",
});
const darkThemeTestHandler = (req: Request) => {
return darkThemeBlogHandler(req, CONN_INFO);
};

const resp = await darkThemeTestHandler(
new Request("https://blog.deno.dev"),
);
const body = await resp.text();
assertStringIncludes(body, `<meta name="theme-color" content="#000" />`);
},
);

Deno.test(
"theme-color meta tag when dark theme is used [post page]",
async () => {
const darkThemeBlogHandler = createBlogHandler({
...BLOG_SETTINGS,
theme: "dark",
});
const darkThemeTestHandler = (req: Request) => {
return darkThemeBlogHandler(req, CONN_INFO);
};

const resp = await darkThemeTestHandler(
new Request("https://blog.deno.dev/first"),
);
const body = await resp.text();
assertStringIncludes(body, `<meta name="theme-color" content="#000" />`);
},
);

Deno.test("Plaintext response", async () => {
const plaintext = new Headers({
"Accept": "text/plain",
Accept: "text/plain",
});
const resp = await testHandler(
new Request("https://blog.deno.dev/first", {
Expand All @@ -317,10 +334,7 @@ Deno.test("Plaintext response", async () => {
);
assert(resp);
assertEquals(resp.status, 200);
assertEquals(
resp.headers.get("content-type"),
"text/plain;charset=UTF-8",
);
assertEquals(resp.headers.get("content-type"), "text/plain;charset=UTF-8");
const body = await resp.text();
assert(body.startsWith("It was popularised in the 1960s"));
});

0 comments on commit 659f5b9

Please sign in to comment.