-
Notifications
You must be signed in to change notification settings - Fork 52
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 #221 from arthur-vanpassel/develop
NEWIO_SITE-3626 add author name & avatar to feed.xml
- Loading branch information
Showing
4 changed files
with
48 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
import { escape } from '@/lib/utils/htmlEscaper' | ||
import { getAuthors } from '@/lib/authors' | ||
|
||
import siteMetadata from '@/data/siteMetadata' | ||
|
||
const generateRssItem = (post) => ` | ||
<item> | ||
<guid>${siteMetadata.siteUrl}/articles/${post.slug}</guid> | ||
<title>${escape(post.title)}</title> | ||
<link>${siteMetadata.siteUrl}/articles/${post.slug}</link> | ||
${post.summary && `<description>${escape(post.summary)}</description>`} | ||
<pubDate>${new Date(post.date).toUTCString()}</pubDate> | ||
<author>${siteMetadata.email} (${siteMetadata.author})</author> | ||
${post.tags && post.tags.map((t) => `<category>${t}</category>`).join('')} | ||
</item> | ||
` | ||
const generateRssItem = (post, authors) => ` | ||
<item> | ||
<guid>${siteMetadata.siteUrl}/articles/${post.slug}</guid> | ||
<title>${escape(post.title)}</title> | ||
<link>${siteMetadata.siteUrl}/articles/${post.slug}</link> | ||
${post.summary && `<description>${escape(post.summary)}</description>`} | ||
<pubDate>${new Date(post.date).toUTCString()}</pubDate> | ||
<author>${siteMetadata.email} (${siteMetadata.author})</author> | ||
${ | ||
post.authors | ||
? post.authors | ||
.map( | ||
(a) => ` | ||
<io:author> | ||
<name>${authors[a].name}</name> | ||
<avatar>${authors[a].avatar}</avatar> | ||
</io:author> | ||
` | ||
) | ||
.join('') | ||
: '' | ||
} | ||
${post.images ? post.images.map((i) => `<image>${i}</image>`).join('') : ''} | ||
${post.tags ? post.tags.map((t) => `<category>${t}</category>`).join('') : ''} | ||
</item> | ||
` | ||
|
||
const generateRss = (posts, page = 'feed.xml') => ` | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>${escape(siteMetadata.title)}</title> | ||
<link>${siteMetadata.siteUrl}/blog</link> | ||
<description>${escape(siteMetadata.description)}</description> | ||
<language>${siteMetadata.language}</language> | ||
<managingEditor>${siteMetadata.email} (${siteMetadata.author})</managingEditor> | ||
<webMaster>${siteMetadata.email} (${siteMetadata.author})</webMaster> | ||
<lastBuildDate>${new Date(posts[0].date).toUTCString()}</lastBuildDate> | ||
<atom:link href="${siteMetadata.siteUrl}/${page}" rel="self" type="application/rss+xml"/> | ||
${posts.map(generateRssItem).join('')} | ||
</channel> | ||
</rss> | ||
` | ||
const generateRss = async (posts, page = 'feed.xml') => { | ||
const authors = await getAuthors(posts) | ||
return ` | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>${escape(siteMetadata.title)}</title> | ||
<link>${siteMetadata.siteUrl}/blog</link> | ||
<description>${escape(siteMetadata.description)}</description> | ||
<language>${siteMetadata.language}</language> | ||
<managingEditor>${siteMetadata.email} (${siteMetadata.author})</managingEditor> | ||
<webMaster>${siteMetadata.email} (${siteMetadata.author})</webMaster> | ||
<lastBuildDate>${new Date(posts[0].date).toUTCString()}</lastBuildDate> | ||
<atom:link href="${siteMetadata.siteUrl}/${page}" rel="self" type="application/rss+xml"/> | ||
${posts.map((element) => generateRssItem(element, authors)).join('')} | ||
</channel> | ||
</rss> | ||
` | ||
} | ||
export default generateRss |
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
4543b5e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
io-technology – ./
io-technology-io-technology.vercel.app
io-technology-git-develop-io-technology.vercel.app
techhub.iodigital.com
io-technology-sigma.vercel.app