Add RSS feeds for ~bitcoin and ~nostr
This commit is contained in:
parent
236ee552c6
commit
d98421d9cd
|
@ -78,6 +78,24 @@ const handleThemeChange = (dark) => {
|
|||
})
|
||||
}
|
||||
|
||||
const RssPopover = (
|
||||
<Popover>
|
||||
<Popover.Content style={{ fontWeight: 500, fontSize: '.9rem' }}>
|
||||
<a href='/rss' className='text-dark d-inline-flex'>
|
||||
home
|
||||
</a>
|
||||
<span className='mx-2 text-dark'> \ </span>
|
||||
<a href='/~bitcoin/rss' className='text-dark d-inline-flex'>
|
||||
bitcoin
|
||||
</a>
|
||||
<span className='mx-2 text-dark'> \ </span>
|
||||
<a href='/~nostr/rss' className='text-dark d-inline-flex'>
|
||||
nostr
|
||||
</a>
|
||||
</Popover.Content>
|
||||
</Popover>
|
||||
)
|
||||
|
||||
const ChatPopover = (
|
||||
<Popover>
|
||||
<Popover.Content style={{ fontWeight: 500, fontSize: '.9rem' }}>
|
||||
|
@ -181,9 +199,11 @@ export default function Footer ({ noLinks }) {
|
|||
</div>
|
||||
</OverlayTrigger>
|
||||
<span className='mx-2 text-muted'> \ </span>
|
||||
<a href='/rss' className='nav-link p-0 d-inline-flex' target='_blank'>
|
||||
rss
|
||||
</a>
|
||||
<OverlayTrigger trigger='click' placement='top' overlay={RssPopover} rootClose>
|
||||
<div className='nav-link p-0 d-inline-flex' style={{ cursor: 'pointer' }}>
|
||||
rss
|
||||
</div>
|
||||
</OverlayTrigger>
|
||||
</div>
|
||||
<div className='mb-2' style={{ fontWeight: 500 }}>
|
||||
<Link href='/faq' passHref>
|
||||
|
|
22
lib/rss.js
22
lib/rss.js
|
@ -1,3 +1,5 @@
|
|||
import getSSRApolloClient from '../api/ssrApollo'
|
||||
|
||||
const SITE_URL = 'https://stacker.news'
|
||||
const SITE_TITLE = 'Stacker News'
|
||||
const SITE_SUBTITLE = 'Like Hacker News, but we pay you Bitcoin.'
|
||||
|
@ -29,7 +31,7 @@ const generateRssItem = (item) => {
|
|||
`
|
||||
}
|
||||
|
||||
export default function generateRssFeed (items) {
|
||||
function generateRssFeed (items) {
|
||||
const itemsList = items.map(generateRssItem)
|
||||
return `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
|
@ -45,3 +47,21 @@ export default function generateRssFeed (items) {
|
|||
</rss>
|
||||
`
|
||||
}
|
||||
|
||||
export default function getGetRssServerSideProps(query, variables = null) {
|
||||
return async function ({ req, res }) {
|
||||
const emptyProps = { props: {} } // to avoid server side warnings
|
||||
const client = await getSSRApolloClient(req)
|
||||
const { error, data: { items: { items } } } = await client.query({
|
||||
query, variables
|
||||
})
|
||||
|
||||
if (!items || error) return emptyProps
|
||||
|
||||
res.setHeader('Content-Type', 'text/xml; charset=utf-8')
|
||||
res.write(generateRssFeed(items))
|
||||
res.end()
|
||||
|
||||
return emptyProps
|
||||
}
|
||||
}
|
||||
|
|
19
pages/rss.js
19
pages/rss.js
|
@ -1,24 +1,9 @@
|
|||
|
||||
import getSSRApolloClient from '../api/ssrApollo'
|
||||
import generateRssFeed from '../lib/rss'
|
||||
import getGetRssServerSideProps from '../lib/rss'
|
||||
import { ITEMS } from '../fragments/items'
|
||||
|
||||
export default function RssFeed () {
|
||||
return null
|
||||
}
|
||||
|
||||
export async function getServerSideProps ({ req, res }) {
|
||||
const emptyProps = { props: {} } // to avoid server side warnings
|
||||
const client = await getSSRApolloClient(req)
|
||||
const { error, data: { items: { items } } } = await client.query({
|
||||
query: ITEMS
|
||||
})
|
||||
|
||||
if (!items || error) return emptyProps
|
||||
|
||||
res.setHeader('Content-Type', 'text/xml; charset=utf-8')
|
||||
res.write(generateRssFeed(items))
|
||||
res.end()
|
||||
|
||||
return emptyProps
|
||||
}
|
||||
export const getServerSideProps = getGetRssServerSideProps(ITEMS);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
import getGetRssServerSideProps from '../../../lib/rss'
|
||||
import { ITEMS } from '../../../fragments/items'
|
||||
|
||||
export default function RssFeed () {
|
||||
return null
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ req, res, params }) => getGetRssServerSideProps(ITEMS, { sub: params.sub })({ req, res });
|
Loading…
Reference in New Issue