giscus / giscus

A comment system powered by GitHub Discussions. :octocat: :speech_balloon: :gem:
https://giscus.app
MIT License
8.07k stars 322 forks source link

Feature Request: Latest Comments Summary in Home Page #1357

Open pourmand1376 opened 4 months ago

pourmand1376 commented 4 months ago

Hi.

First, I want to thank you for creating this beautiful commenting system. It's been a year or two since I'm using your comment system.

Now, I want to add a feature to it and I don't know where to start. I want to have a page / Section where it shows the latest comments in my blog. Pretty much like this one but without excerpt. Only showing the 10 latest comments in my blog.

How can I add this to my blog? I've seen this in lots of wordpress websites and I think this is needed in my blog.

weekdaycare commented 4 months ago

or is there any api to get latest comments?

weekdaycare commented 4 months ago

ok, we can use GraphQL API

pourmand1376 commented 4 months ago

Can you please provide more info on how to use that API? How does Github allow us to access it?

weekdaycare commented 4 months ago

https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions

pourmand1376 commented 1 month ago

Thanks for clarifying. I hold my answer since I didn't know anything about this graphql.

Today I could find this demo by github which I could run graphql queries on.

I worked on it to get a complete output of what I want.

query {
  repository(owner: "pourmand1376", name: "hugo-papermod-farsi-template") {
    discussions(first: 10) {
      # type: DiscussionConnection
      totalCount # Int!
      nodes {
        # type: Discussion
          url
          updatedAt
          title
          comments(last:2)
          {
            totalCount
            nodes {
              author {
                login
                url
              }
              url
            }
          }
      }
    }
  }
}

This is the query which works for me. I think I will combine it with this stackoverflow post to make what I want.

I left a comment here so that anyone interested would know that this is possible. I will update this comment to make it more complete if I finish this thing completely.

weekdaycare commented 1 month ago

sry, I completely forgot about this issue. In fact, I created a JS script and hosted it on Vercel to implement this functionality three months ago. you can check out my repository: https://github.com/weekdaycare/discussion-new-api

It will provide JSON data, which you can use to write the frontend display code.

pourmand1376 commented 1 month ago

Thanks for providing more info.

Yesterday, I also put in some time and implemented it here.

https://github.com/pourmand1376/python-github-action-template

It is a script which reads discussion's data and puts it in a html file which I read in my website loading page.

Similar like yours.

weekdaycare commented 1 month ago

Oh, it looks like you are using actions to schedule scraping discussion data and convert it into HTML. I've encapsulated it into an API and styled the HTML on the frontend. The advantage is that it can display new comments in real-time, but the downside is the connectivity issue with Vercel in different regions.

However, I have switched from Giscus to Twikoo now. This script is something I wrote for a blog friend🫠.