-
Notifications
You must be signed in to change notification settings - Fork 3
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 #69 from oxen-io/dev
Foundation Site Blog Fixes
- Loading branch information
Showing
9 changed files
with
115 additions
and
9 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
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,73 @@ | ||
import fs from 'fs'; | ||
import { generateXMLFromObject } from '@session/sanity-cms/lib/xml'; | ||
import { getSiteSettings } from '@session/sanity-cms/queries/getSiteSettings'; | ||
import { client } from '@/lib/sanity/sanity.client'; | ||
import { BASE_URL, SANITY_SCHEMA_URL } from '@/lib/constants'; | ||
import { getPostsWithMetadata } from '@session/sanity-cms/queries/getPosts'; | ||
|
||
export async function generateRssFeed() { | ||
const posts = await getPostsWithMetadata({ client }); | ||
|
||
posts.sort((a, b) => { | ||
const dateA = new Date(a.date ?? a._updatedAt); | ||
const dateB = new Date(b.date ?? b._updatedAt); | ||
|
||
return dateB.getTime() - dateA.getTime(); | ||
}); | ||
|
||
const date = new Date(); | ||
|
||
const settings = await getSiteSettings({ client }); | ||
|
||
const copyright = settings?.copyright; | ||
|
||
const title = | ||
settings?.blogSeo?.metaTitle ?? | ||
settings?.blogSeo?.openGraph?.title ?? | ||
settings?.seo?.metaTitle ?? | ||
settings?.seo?.openGraph?.title; | ||
|
||
const json = { | ||
rss: { | ||
'@version': '2.0', | ||
'@xmlns:atom': 'http://www.w3.org/2005/Atom', | ||
'@xmlns:content': 'http://purl.org/rss/1.0/modules/content/', | ||
'@xmlns:dc': 'http://purl.org/dc/elements/1.1/', | ||
channel: { | ||
title, | ||
description: 'RSS feed for Session Technology Foundation updates.', | ||
link: BASE_URL, | ||
image: { | ||
url: `${BASE_URL}/images/logo.svg`, | ||
title: `Session Technology Foundation updates`, | ||
link: BASE_URL, | ||
}, | ||
generator: 'mini-xml for Node.js', | ||
lastBuildDate: date, | ||
'atom:link': { | ||
'@href': `${BASE_URL}/rss.xml`, | ||
'@rel': 'self', | ||
'@type': 'application/rss+xml', | ||
}, | ||
copyright, | ||
item: posts.map((post) => { | ||
const url = `${BASE_URL}${SANITY_SCHEMA_URL.POST}${post.slug.current}`; | ||
return { | ||
title: post.title.trim(), | ||
description: post.summary.trim(), | ||
link: url, | ||
guid: { | ||
'@isPermaLink': 'true', | ||
'#text': url, | ||
}, | ||
pubDate: new Date(post.date ?? post._updatedAt), | ||
}; | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
const feed = generateXMLFromObject(json, { pretty: true, indentSpaces: 2 }); | ||
|
||
fs.writeFileSync('./public/rss.xml', feed); | ||
} |
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