No internet connection
  1. Home
  2. Ideas

Read API

By @sam
    2021-01-28 12:00:46.659Z

    An API which allows you to read information about one or more disscusionid's. I want it because I need to get the comment count on each of my blog cards. So before they opened the post, so people have an idea how much discussion is going on.

    If I take a look at one of these links:
    Then you'll receive html back, in it you see something like this:
    <script id="theVolatileJson" type="application/json">
    <script id="thePageJson" type="application/json">
    <script id="theStaticJson" type="application/json">

    Now these seem to have useful information already. But requests to those pages are CORS protected which is fine.
    Anyway something that gives back useful information like that would already be helpful.

    If you want to make it really user friendly, which for me isn't necessary but maybe some people prefer it. You could do what commento does.

    All you do is add a pre-made js file to your html page and add #commento behind you links and will automatically add the comment count to the card. Eitherway something like this would be very helpful.


    NOTE: It's good to mention that this API should NOT contain sensitive information. It's meant for something you could use as an ajax call without allowing people to read things like all the users, etc. So export-site-json is too much,

    Linked from:

    1. support-chat
    • 5 replies
    1. In reply tosam:
      KajMagnus @KajMagnus2021-02-04 15:30:18.114Z2021-02-04 15:42:42.882Z

      I see here:
      that Commento replaces the contents of the <a href=..> tag with the comment count,
      if the href ends with #commento, like so:

      <a href=""></a>
      // becomes:
      <a href="">12 comments</a>

      That seems like a good approach.

      Hmm I think one wouldn't always want to use an <a> tag for displaying the comments count.
      Because ... could that slightly encourage people to jump to the comments before reading the blog post?
      & I'd like to lookup the tags to insert the comment count in, via a CSS class, (a tiny bit faster)

      maybe something like:

      <a href=""><span>Blog Post Title</span> <span class="talkyard-num-comments"></span></a>

      and then the Talkyard script finds the href=... url in the enclosing <a> tag and replaces with the comment count — I suppose this'd need to be language specific, e.g. "1 comment" or "3 comments" in English, but "3 kommentarer" if Swedish.

      And you could do like this if you wanted to get the Commento behavior:

      <a href="" class="talkyard-num-comments"></a>

      It's meant for something you could use as an ajax call without allowing people to read things like all the users, etc.

      Probably the upcoming API endpoint for this will be able to return different kinds of data: Num replies, latest reply on each page, latest replyer (author). And there's authorization checks so only public data gets returned, yes

      1. S@sam
          2021-02-07 16:59:21.715Z2021-02-07 17:09:39.304Z

          Hmm yea, now that you mention it, there are some caveats to commento's approach. I think youre on the right thinking path.

          Things to consider, maybe not everybody wants their comments to be a part to be clickable to the blog link? So another option is to do a span with a class and a custom attribute that has the link included?
          Another thing is that I don't think you have to worry about languages, it should just say the number, People can add their own text on it afterwards (either with css or in a span next to it). Or you can also let that be handeled by a custom attribute for example:
          <span class="talkyard-num-comments" link="" singular="comment" plural="comments"></span>

          Then if people don't want text (like me) they could do this:
          <span class="talkyard-num-comments" link="" singular="" plural=""></span>

          The reason I don't want any text is because my design looks as follows:

          For me personally the commento thing is not a must-have but I did think it was a nice feature for those not tech savy.

          1. a span with a class and a custom attribute that has the link included?

            Good idea — now I'm thinking Talyard can find the blog post iink either from a data-href="..." directly on the num-comments tag (or the closest tag with such an attr),
            or if absent, the closest <a href=...>.
            Now in step 1: looking only at the closest <a href=...> probably.

            I don't think you have to worry about languages, it should just say the number

            Good point. Now when I think about it, all blogs / websites that I can remember now, shows a comments icon (just like you do), not any "NN comments" text. So, just the number then.

            The screenshot: It's nice to see num Likes too (num Medium "claps") — maybe this'll make the implementation just a tiny bit different, good that I get to think about now directly.

            1. S@sam
                2021-02-12 10:58:17.579Z

                I don't use the talkyard likes, reason is that I can't seperate that from the iframe (or don't know how to).
                I would prefer to use talkyards likes so I don't have to use multiple different tools but right now I don't see that as a viable option. Perhaps another idea for the future?

                1. KajMagnus @KajMagnus2021-03-18 13:20:23.718Z2021-08-24 18:28:33.723Z

                  Hi @sam , this now fixed since some weeks back (I forgot to reply about it, sorry).

                  Here's how it works — by loading the blog comments script,
                  adding a class="ty_NumCmts" either

                  1. directly on a <a>,
                    like so: <a href="" class="ty_NumCmts"></a> comments
                  2. or on a tag wrapped in a <a href=...> that points to the bog post.

                  enabling CORS, Cross-Origin Resource Sharing, at your Talkyard site, here: /-/admin/settings/features — in the Allow CORS requests from field, type the address to your blog.


                  <script async defer src='${tyServerOrigin}/-/talkyard-comments.js'></script>
                  <h2>Test blog posts list</h2>
                       <a href="https://your website/some-blog-post.html">
                          <span>Blog post title</span>
                          <span class="ty_NumCmts"></span>  comments
                       <a href="https://your website/another.html">Blog post title</a>
                       <a href="https://your website/another#comments" class="ty_NumCmts"></a> comments

                  (Here's an end-to-end test: )

                  (Now, August 2021, I wrote an How To page about this: How to Show Blog Post Comment Counts)

          2. Progress
            with doing this idea
          3. @KajMagnus marked this topic as Planned 2021-01-29 09:26:23.825Z.
          4. @KajMagnus marked this topic as Done 2021-08-24 18:29:03.172Z.