generated from Blazity/next-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Blazity/rss
Rss
- Loading branch information
Showing
8 changed files
with
2,550 additions
and
3,670 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Feed } from "feed" | ||
import fs from "fs" | ||
import { HygraphClient } from "hygraphClient" | ||
|
||
export default async function generateRssFeed(locale: string) { | ||
const site_url = process.env.VERCEL_URL ?? "localhost:3000" | ||
|
||
const { getRecentArticlesWithMetadata } = HygraphClient() | ||
const { articles } = await getRecentArticlesWithMetadata({ locales: [locale] }) | ||
|
||
const feedOptions = { | ||
title: "Blog posts | RSS Feed", | ||
description: "Welcome to this blog posts!", | ||
id: site_url, | ||
link: site_url, | ||
language: locale, | ||
image: `${site_url}/logo.png`, | ||
favicon: `${site_url}/favicon.ico`, | ||
copyright: `All rights reserved ${new Date().getFullYear()}`, | ||
generator: "Feed for Node.js", | ||
feedLinks: { | ||
rss2: `${site_url}/rss.xml`, | ||
}, | ||
} | ||
|
||
const feed = new Feed(feedOptions) | ||
|
||
articles.forEach((article) => { | ||
const date = article?.updatedAt ? new Date(article?.updatedAt) : new Date() | ||
feed.addItem({ | ||
title: article?.title, | ||
id: `${site_url}/blog/${article?.slug}`, | ||
link: `${site_url}/blog/${article?.slug}`, | ||
description: "test", | ||
copyright: `All rights reserved ${new Date().getFullYear()}`, | ||
date: date, | ||
author: [{ name: article?.author?.name }], | ||
image: article?.coverImage?.url, | ||
}) | ||
}) | ||
|
||
fs.writeFile(`./public/${locale}.xml`, feed.rss2(), (err) => { | ||
if (err) return console.log(err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.