From 596172870247bd1f59932d5ee3b6b2cedbe1fb6a Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Thu, 18 Jan 2024 23:54:07 +0900 Subject: [PATCH] refactor(feeds): avoid to refer config in service --- __tests__/unit/services/feed.test.ts | 2 +- src/pages/feeds/index.xml.tsx | 3 ++- src/services/feeds.ts | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/unit/services/feed.test.ts b/__tests__/unit/services/feed.test.ts index 50272f8..636fe2d 100644 --- a/__tests__/unit/services/feed.test.ts +++ b/__tests__/unit/services/feed.test.ts @@ -42,7 +42,7 @@ test('generate sitemap.xml', async () => { } ] - const result = await generateFeedsString('https://example.com', data); + const result = await generateFeedsString('https://example.com', 'yourSiteName', 'yourName', data); expect(result.replace(/\s/g,"")).toEqual( ` yourSiteName diff --git a/src/pages/feeds/index.xml.tsx b/src/pages/feeds/index.xml.tsx index cdf01f8..d61974b 100644 --- a/src/pages/feeds/index.xml.tsx +++ b/src/pages/feeds/index.xml.tsx @@ -3,6 +3,7 @@ import { getFeed } from '../../api/feed'; import { generateFeedsString } from '../../services/feeds'; import { url } from '../../../config'; import { getRequestContext } from '../../utils/requestContext'; +import { siteName, mainAuthor } from '../../../config'; const SitemapXml = () => null; @@ -29,7 +30,7 @@ export async function getServerSideProps(ctx: any) { } }) as Array; - const feedXmlString = await generateFeedsString(url, feeds); + const feedXmlString = await generateFeedsString(url, siteName, mainAuthor, feeds); ctx.res.setHeader("Content-Type", "text/xml"); ctx.res.write(feedXmlString); ctx.res.end(); diff --git a/src/services/feeds.ts b/src/services/feeds.ts index ef0bdc6..160d276 100644 --- a/src/services/feeds.ts +++ b/src/services/feeds.ts @@ -1,10 +1,9 @@ import { Feed } from '../models/feed'; import { convertUnixTimeToISODateSrting } from '../utils/time'; -import { siteName, mainAuthor } from '../../config'; const FEED_URL = '/feeds/index.xml'; -export async function generateFeedsString(url: string, feeds: Array): Promise { +export async function generateFeedsString(url: string, siteName: string, mainAuthor: string, feeds: Array): Promise { const latest = feeds[0]