From 2aa93f55f8dd17beca17204f4b6600061d600a6e Mon Sep 17 00:00:00 2001 From: sevichecc <91365763+Sevichecc@users.noreply.github.com> Date: Sat, 10 Sep 2022 11:13:07 +0800 Subject: [PATCH] merge with 894b532 --- src/hooks.ts | 7 +++++++ src/routes/feed.json/+server.ts | 3 ++- src/routes/posts.json/+server.ts | 8 ++------ src/routes/tags.json/+server.ts | 8 ++------ 4 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 src/hooks.ts diff --git a/src/hooks.ts b/src/hooks.ts new file mode 100644 index 00000000..00cbcc0a --- /dev/null +++ b/src/hooks.ts @@ -0,0 +1,7 @@ +import type { Handle } from '@sveltejs/kit' +import { site } from '$lib/config/site' + +export const handle: Handle = async ({ event, resolve }) => + await resolve(event, { + transformPageChunk: ({ html }) => html.replace('', ``) + }) diff --git a/src/routes/feed.json/+server.ts b/src/routes/feed.json/+server.ts index 77b00c73..401e20ad 100644 --- a/src/routes/feed.json/+server.ts +++ b/src/routes/feed.json/+server.ts @@ -1,4 +1,5 @@ import type { RequestHandler } from './$types' +import { json } from '@sveltejs/kit' import { site } from '$lib/config/site' import { feed } from '$lib/config/general' import { favicon, any } from '$lib/config/icon' @@ -43,7 +44,7 @@ const render = (posts = genPosts({ postHtml: true, postLimit: feed.limit, filter export const prerender = true export const GET: RequestHandler = async () => - new Response(JSON.stringify(render(), null, 2), { + json(render(), { headers: { 'content-type': 'application/feed+json; charset=utf-8' } diff --git a/src/routes/posts.json/+server.ts b/src/routes/posts.json/+server.ts index b101c3a4..911ae7ff 100644 --- a/src/routes/posts.json/+server.ts +++ b/src/routes/posts.json/+server.ts @@ -1,10 +1,6 @@ import type { RequestHandler } from './$types' +import { json } from '@sveltejs/kit' import { genPosts } from '$lib/utils/posts' export const prerender = true -export const GET: RequestHandler = async () => - new Response(JSON.stringify(genPosts(), null, 2), { - headers: { - 'content-type': 'application/json; charset=utf-8' - } - }) +export const GET: RequestHandler = async () => json(genPosts()) diff --git a/src/routes/tags.json/+server.ts b/src/routes/tags.json/+server.ts index b51df6d9..4742ba7a 100644 --- a/src/routes/tags.json/+server.ts +++ b/src/routes/tags.json/+server.ts @@ -1,10 +1,6 @@ import type { RequestHandler } from './$types' +import { json } from '@sveltejs/kit' import { genPosts, genTags } from '$lib/utils/posts' export const prerender = true -export const GET: RequestHandler = async () => - new Response(JSON.stringify(genTags(genPosts()), null, 2), { - headers: { - 'Content-Type': 'application/json; charset=utf-8' - } - }) +export const GET: RequestHandler = async () => json(genTags(genPosts()))