generated from mateusfg7/nextjs-setup
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): create function to generate atom feed
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getSortedPosts } from '@/shared/lib/get-sorted-posts' | ||
import { host } from '@/shared/lib/webserver-constants' | ||
import { allPosts } from 'contentlayer/generated' | ||
import { Feed } from 'feed' | ||
import { markdownToHtml } from './markdown-to-html' | ||
|
||
export function generateFeed() { | ||
const date = new Date() | ||
|
||
const posts = getSortedPosts(allPosts).filter( | ||
post => post.status === 'published' | ||
) | ||
|
||
const feed = new Feed({ | ||
title: "Mateus Felipe's interests", | ||
description: | ||
'This is my "corner of internet", where I take some tests, document my studies and write about some subjects I like...', | ||
id: host, | ||
link: host, | ||
favicon: `${host}/assets/brain.png`, | ||
copyright: `All rights reserved ${date.getFullYear()}, Mateus Felipe.`, | ||
updated: posts.length > 0 ? new Date(posts[0].date) : date, | ||
feedLinks: { | ||
rss2: `${host}/feed` | ||
}, | ||
docs: 'https://github.com/mateusfg7/mfg-b', | ||
generator: 'Feed for Node.js', | ||
author: { | ||
name: 'Mateus Felipe Gonçalves', | ||
email: '[email protected]', | ||
link: 'https://mateusf.vercel.app' | ||
} | ||
}) | ||
|
||
posts.forEach(post => { | ||
const { name, email, url } = post.author_info | ||
|
||
feed.addItem({ | ||
title: post.title, | ||
id: post.id, | ||
link: `${host}/post/${post.id}`, | ||
description: post.description, | ||
content: markdownToHtml(post.body.raw), | ||
author: [{ name, email, link: url }], | ||
date: new Date(post.date), | ||
category: post.tags.split(',').map(tag => ({ name: tag.trim() })) | ||
}) | ||
}) | ||
|
||
return feed.atom1() | ||
} |