Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 1, 2024
1 parent 9f5e407 commit 67eb496
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/app/archives/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { headers } from 'next/headers'
import { headers } from 'next/headers';

import Renderer from './renderer';
import { getArchives } from '../../api/archives';
Expand Down
42 changes: 0 additions & 42 deletions src/app/feeds/index.xml.tsx

This file was deleted.

34 changes: 34 additions & 0 deletions src/app/feeds/index.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { headers } from 'next/headers';

import { Feed } from '../../../models/feed';
import { getFeed } from '../../../api/feed';
import { generateFeedsString } from '../../../services/feeds';
import { url } from '../../../../config';
import { getRequestContext } from '../../../utils/requestContext';

//export async function get(ctx: any) {
export async function GET() {
const response: Response = await getFeed(getRequestContext(headers()));
// ctx.res.statusCode = response.status; // TODO

if (response.status !== 200) {
return new Response(new Blob(), { status: 404 });
}
let feedResponses = await response.json() as Array<Feed>;
const feeds = feedResponses.map(feed => {
return {
title: feed.title,
link: feed.link,
id: feed.id,
published: feed.published,
updated: feed.updated
}
}) as Array<Feed>;

const feedXmlString = await generateFeedsString(url, feeds);
return new Response(feedXmlString, {
headers: {
"Content-Type": "text/xml",
},
});
}
39 changes: 0 additions & 39 deletions src/app/sitemap.xml.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions src/app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { headers } from 'next/headers';

import { Sitemap } from '../../models/sitemap';
import { getSitemap } from '../../api/sitemap';
import { generateSitemapString } from '../../services/sitemap';
import { url } from '../../../config';
import { getRequestContext } from '../../utils/requestContext';

export async function GET() {
const response: Response = await getSitemap(getRequestContext(headers()));

/* TODO
ctx.res.statusCode = response.status;
let sitemapResponse = null;
if (response.status !== 200) {
return {
props: {
statusCode: 404
}
}
}
*/
let sitemapResponse = await response.json() as Array<Sitemap>;
const sitemap = sitemapResponse.map(sitemap => {
return {
loc: sitemap.loc,
lastMod: sitemap.lastMod
}
}) as Array<Sitemap>;

const sitemapXmlString = await generateSitemapString(url, sitemap);
return new Response(sitemapXmlString, {
headers: {
"Content-Type": "text/xml",
},
});
}

0 comments on commit 67eb496

Please sign in to comment.