From 236ac565f74ae28b4ee5df6390ad6ba5906bb48f Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Tue, 31 Jan 2023 20:34:20 +0100 Subject: [PATCH] Get feed to work again Without any breaking changes --- src/routes/blog/articles/[...params]/+server.ts | 1 - src/routes/feed.json/+server.ts | 12 ++++++++++++ src/routes/{feed/_feed.ts => feed.ts} | 2 +- src/routes/feed.xml/+server.ts | 12 ++++++++++++ src/routes/feed/index.json.ts | 10 ---------- src/routes/feed/index.xml.ts | 13 ------------- .../egg-fetcher/{index.svelte => +page.svelte} | 0 7 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 src/routes/feed.json/+server.ts rename src/routes/{feed/_feed.ts => feed.ts} (96%) create mode 100644 src/routes/feed.xml/+server.ts delete mode 100644 src/routes/feed/index.json.ts delete mode 100644 src/routes/feed/index.xml.ts rename src/routes/showcase/egg-fetcher/{index.svelte => +page.svelte} (100%) diff --git a/src/routes/blog/articles/[...params]/+server.ts b/src/routes/blog/articles/[...params]/+server.ts index 4eeec13..450b23c 100644 --- a/src/routes/blog/articles/[...params]/+server.ts +++ b/src/routes/blog/articles/[...params]/+server.ts @@ -7,7 +7,6 @@ import { getBlogListing } from '../../content' import type { RequestHandler } from './$types' export const GET = (async ({ params }) => { - console.log('article-params', params) const handledParams = params.params === 'index' ? '' : params.params const { page = 1, pageSize = 7, ...filters } = parseParams(handledParams) const paginationParams = getDropTakeFromPageParams( diff --git a/src/routes/feed.json/+server.ts b/src/routes/feed.json/+server.ts new file mode 100644 index 0000000..cf7eeb2 --- /dev/null +++ b/src/routes/feed.json/+server.ts @@ -0,0 +1,12 @@ +import type { RequestHandler } from '@sveltejs/kit' +import { getFeed } from '../feed' + +export const GET = (async ({ setHeaders }) => { + const feed = await getFeed() + + setHeaders({ + 'Content-Type': 'application/json', + 'Cache-Control': 'max-age=86400', + }) + return new Response(feed.json1()) +}) satisfies RequestHandler diff --git a/src/routes/feed/_feed.ts b/src/routes/feed.ts similarity index 96% rename from src/routes/feed/_feed.ts rename to src/routes/feed.ts index 62e0028..00cb063 100644 --- a/src/routes/feed/_feed.ts +++ b/src/routes/feed.ts @@ -1,5 +1,5 @@ import { Feed } from 'feed' -import { getBlogListing } from '../blog/content' +import { getBlogListing } from './blog/content' export async function getFeed() { const feed = new Feed({ diff --git a/src/routes/feed.xml/+server.ts b/src/routes/feed.xml/+server.ts new file mode 100644 index 0000000..f97c20a --- /dev/null +++ b/src/routes/feed.xml/+server.ts @@ -0,0 +1,12 @@ +import type { RequestHandler } from '@sveltejs/kit' +import { getFeed } from '../feed' + +export const GET = (async ({ setHeaders }) => { + const feed = await getFeed() + + setHeaders({ + 'Content-Type': 'application/xml', + 'Cache-Control': 'max-age=86400', + }) + return new Response(feed.rss2()) +}) satisfies RequestHandler diff --git a/src/routes/feed/index.json.ts b/src/routes/feed/index.json.ts deleted file mode 100644 index d01c31b..0000000 --- a/src/routes/feed/index.json.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { getFeed } from './_feed' - -export async function get() { - const feed = await getFeed() - - return { - status: 200, - body: feed.json1(), - } -} diff --git a/src/routes/feed/index.xml.ts b/src/routes/feed/index.xml.ts deleted file mode 100644 index 0ae090c..0000000 --- a/src/routes/feed/index.xml.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getFeed } from './_feed' - -export async function get(req, res) { - const feed = await getFeed() - - return { - status: 200, - headers: { - 'Content-Type': 'application/xml', - }, - body: feed.rss2(), - } -} diff --git a/src/routes/showcase/egg-fetcher/index.svelte b/src/routes/showcase/egg-fetcher/+page.svelte similarity index 100% rename from src/routes/showcase/egg-fetcher/index.svelte rename to src/routes/showcase/egg-fetcher/+page.svelte