Skip to content

Commit

Permalink
refactor(feeds): avoid to refer config in service
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 18, 2024
1 parent 1a872ec commit 5961728
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/services/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`<feed xmlns="http://www.w3.org/2005/Atom">
<title>yourSiteName</title>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/feeds/index.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,7 +30,7 @@ export async function getServerSideProps(ctx: any) {
}
}) as Array<Feed>;

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();
Expand Down
3 changes: 1 addition & 2 deletions src/services/feeds.ts
Original file line number Diff line number Diff line change
@@ -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<Feed>): Promise<string> {
export async function generateFeedsString(url: string, siteName: string, mainAuthor: string, feeds: Array<Feed>): Promise<string> {

const latest = feeds[0]

Expand Down

0 comments on commit 5961728

Please sign in to comment.