JSON link array does not match link order in post


(Sam Nazarko) #1

Hello

We are using Discourse to power our Wiki. It’s been working pretty well. Since updating to 1.7 we’ve run in to a slight snag. It seems that the ordering of the links to other Wiki pages is not necessarily respected.

If you see our Table of Contents for the Wiki here, you will see that Apple TV is the second to last link, and we would like it to be the second to last category to appear. Our script scrapes the links array. I have noticed that the JSON of the post lists Apple TV first. At first I thought Discourse may be ordering links by post ID, but this does not seem to be the case. I tried editing the post and removing all links, and then re-adding them, but this did not change the situation.

Is there an explanation for how the links array is ordered? Would it make sense for the links to be listed in the JSON in the order that they are referenced?

  "links":[  
     {  
        "url":"https://discourse.osmc.tv/t/apple-tv/10039",
        "title":"Apple TV",
        "fancy_title":null,
        "internal":true,
        "attachment":false,
        "reflection":false,
        "clicks":0,
        "user_id":1,
        "domain":"discourse.osmc.tv"
     },

]

Thanks

Sam


(Robin Ward) #2

I believe those links are ordered in terms of popularity. The most clicked on links will be at the top.


(Vinoth Kannan) #3

Yes.


(Sam Nazarko) #4

Thanks for the information. I’ll have to find an appropriate workaround.

Sam


(Sam Nazarko) #5

You have link_counts, so you could add correct ordering there, but preserve links as is in a future version of Discourse, or maybe add a ‘links_raw’. If you would accept a new JSON property that offers links in the correct order then I can PR this.

I will have to work around this temporarily by taking cooked and taking links from that or patching Discourse.

Sam