Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements rss feed #17

Merged
merged 1 commit into from
Aug 9, 2021
Merged

Conversation

bordalix
Copy link
Contributor

Related to #16

A SSR solution for a RSS feed:

  • feed has latest items (live)
  • each request impacts server (load)

It's also possible to use a SSG solution (ex: /public/rss.xml file):

  • static file, no load on the server (faster)
  • xml file is only created on build time (delay)

Note, I was not able to properly test the query.

@huumn
Copy link
Member

huumn commented Aug 9, 2021

Hey @bordalix thanks for your work here! Sorry it's taken me so long to respond. Been sick with the plague!

I don't know much about the expectations of RSS readers, but given that the feed isn't static and isn't simply adding items (the order changes with ranking), do we need to do anything special to account for this or will they work as expected?

@anthonyvardizzone
Copy link

Hey @bordalix thanks for your work here! Sorry it's taken me so long to respond. Been sick with the plague!

I don't know much about the expectations of RSS readers, but given that the feed isn't static and isn't simply adding items (the order changes with ranking), do we need to do anything special to account for this or will they work as expected?

Hey huumn,

I am the one who originally suggested the RSS capability both on the website itself and by opening up the GitHub issue.

One possible solution to the order change could be to have it implemented through the recent tab only. So the feed url could look something like this: https://stacker.news/recent/rss whereas https://stacker.news/rss would return an error for inability to find a feed if it were to be added.

Since the recent order does not change, it would function as a static feed for people who want to get updates to posts via RSS. That was my initial reason for requesting RSS functionality since I had originally bookmarked the recent link rather than the link to the actual home page.

As far as expectations, being able to see a new post when it's live is the idea. Unless there was a way to enable notifications, that would be the best way to "push" new content to people who might not want to check the website dozens of times a day to see if there is any new content. I never expected that I would be able to fully interact with the website through RSS. Just a link if there is one in the post and the content if there is any with a way to open up a link to the post in the browser if I wanted to boost the post or comment on it.

Hopefully you're feeling better!

@huumn
Copy link
Member

huumn commented Aug 9, 2021

Hi @anthonyvardizzone! Thanks for requesting the feature. I definitely think it's a value add to the site. Having a recent rss feed is a good addition too. I imagine we can make the main page rss feed work too but I just don't know enough about it to know if we need to do anything special to make it work. Hacker News has an RSS feed for their main page so it seems possible https://news.ycombinator.com/rss ... It seems like they just generate it periodically and don't do anything special to make it work so maybe we don't either.

(Thanks for the well wishes too. Feeling 100% now.)

@huumn
Copy link
Member

huumn commented Aug 9, 2021

@bordalix I'm inspecting this branch locally but struggling to see the RSS feed. Do you know why? I'm probably doing something dumb, but I just see a blank page even with curl or wget.

@bordalix
Copy link
Contributor Author

bordalix commented Aug 9, 2021

Hi huumm, 100% is excellent :)

I use the Hacker News RSS feed and its based on Created At.
And that is what I'm expecting from a RSS feed.
If I want to see the articles order, I go to the website.

@bordalix
Copy link
Contributor Author

bordalix commented Aug 9, 2021

Check the graphql query, I was not able to test it.
But I think you should always see the RSS headers, not a blank page.

@bordalix
Copy link
Contributor Author

bordalix commented Aug 9, 2021

With dummy data I have it working on my side:

export async function getServerSideProps({ req, res }) {
  const emptyProps = { props: {} } // to avoid server side warnings
  // const { error, data } = await (await ApolloClient(req)).query({
  //   query: gql`
  //     query Items {
  //       items {
  //         createdAt
  //         id
  //         title
  //       }
  //     }
  //   `,
  // })

  const error = false;
  const data = {
    items: [
      { id: 1, title: 'title 1', createdAt: '1/1/1970' },
      { id: 2, title: 'title 2', createdAt: '2/1/1970' },
      { id: 3, title: 'title 3', createdAt: '3/1/1970' },
    ]
  }
  
  if (!data.items || error) return emptyProps

  res.setHeader("Content-Type", "text/xml")
  res.write(generateRssFeed(data.items))
  res.end()

  return emptyProps
}

@huumn
Copy link
Member

huumn commented Aug 9, 2021

Yeah I have it working now. It was the graphql query like you said!

@huumn huumn merged commit ed961b7 into stackernews:master Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants