Skip to content

Commit

Permalink
feat: support chinese path (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
gofenix authored Jan 16, 2023
1 parent 4d94d64 commit 127ac2d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export async function handler(
});
}

const post = POSTS.get(pathname);
const post = POSTS.get(decodeURIComponent(pathname));
if (post) {
// Check for an Accept: text/plain header
if (
Expand Down
15 changes: 15 additions & 0 deletions blog_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ Deno.test("posts/ third", async () => {
assertStringIncludes(body, `<p>Lorem Ipsum is simply dummy text`);
});

Deno.test("posts/ 中文", async () => {
const resp = await testHandler(new Request("https://blog.deno.dev/中文"));
assert(resp);
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text();
assertStringIncludes(body, `<html lang="en-GB">`);
assertStringIncludes(
body,
`<link rel="canonical" href="https://blog.deno.dev/%E4%B8%AD%E6%96%87" />`,
);
assertStringIncludes(body, `中文`);
assertStringIncludes(body, `<p>你好,世界!`);
});

Deno.test("posts/ trailing slash redirects", async () => {
const resp = await testHandler(new Request("https://blog.deno.dev/second/"));
assert(resp);
Expand Down
8 changes: 8 additions & 0 deletions testdata/posts/中文.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: 中文
author: 自定义中文名
publish_date: 2022-08-19
abstract: 这是一篇中文路径文章。
---

你好,世界!

0 comments on commit 127ac2d

Please sign in to comment.