Original link: https://yufree.cn/cn/2023/05/17/disqus/
At the end of the last article, I said that the comment moved. In fact, half of the move was made, but there were many pitfalls. With the help of Xie Da, the move should be almost done this time. Record it here.
The initial motivation for the move was actually that Netlify’s traffic was not enough. I thought it was the fault of Disqus, but after Ye Xun reminded me, I found out that the previous RSS template did not set to keep the latest few articles, but kept outputting all articles. I read that the document of more than four megabytes contained about 2 million words, and I wrote almost three “Xinhua Dictionary”. It is probably possible to simulate a me with these. After the adjustment, the RSS full-text output is still output at present, but only the latest 10 articles will be output. Since then, the traffic has dropped from 3G a day to about 100M. In the middle, I also set up GHA to host the website on GitHub pages. The only thing I need is to configure DNS, which is unnecessary now.
In other words, I can actually restore the previous Disqus comments now, because the traffic is enough now. But there is a conceptual error here. If I download my article page, I will see that the Disqus script is about 2M, but in fact, I have set it to asynchronous loading before, that is, unless you see the end, Disqus will not load. And even if it is loaded, I don’t think it can be counted as Netlify’s traffic, but the browser downloads it from the CDN of the js script. At the same time, after I paid the Netlify protection fee, I saw that a large number of visits were to the homepage, but there were no comments on the homepage, and this visit did not show the traffic on the RSS side, which led me to think that Netlify used some black magic to calculate the traffic. Now It seems that Netlify has been wronged.
However, in the process of tossing, I have replaced Disqus with Giscus. After all, this js script is smaller and loads faster. Another reason for the change was mentioned earlier. Disqus is not available in China, and a window must be opened to allow different opinions to be sent out. Speaking of this, Disqus often swallows comments or asks me to review for no reason, and the algorithm is also very confusing, so I don’t regret changing it. The advantage of Giscus is that it relies entirely on GitHub’s forum function, and you can set the title to match, so that all comments on posts with the same topic will be directly linked to the forum posts, and the rest of the functions are similar to Disqus. The only thing I regret is that there is no anonymous or guest comment function. Now you have to have a GitHub account to use Giscus, which is not conducive to comments from readers who are not interested in GitHub, but Disqus allows it. If Giscus opens this feature later, I should also follow up and open anonymous comments, but this is also a double-edged sword, and it is likely to be covered by advertisements.
Then it was relocated, that is, the old comments were moved to Giscus. First of all, I have to export an xml document containing all comments from Disqus, and I am stuck at this step. According to the official document, I searched for a long time in the community of Disqus’s personal settings and couldn’t find the export function. Later, I found out that it was on the tool side. After exporting, the next step is to transfer to Giscus. I use title matching, mainly for the title to be more beautiful, and then step on the pit again. Here I copied Rob Hyndman’s homework . In fact, Xie Da wrote an English related blog , which also has many precautions. It felt amazing at the time, and I used the script to post the post directly, and then I remembered that I had configured RStudio’s GitHub access before, so I was not stuck logging in. Turning around, I clicked on a few and checked that there was no problem and then ignored it, but in fact I didn’t notice several pits.
I just saw Xie Da’s comment today, and then I realized that the previous comment did not link to the original text, and after a closer look, I found that the title was wrong. Xie Da gave an update method based on GraphQL API in the comments. I accepted it all, but after running it, I found that there was still no link. Then I wondered for a long time whether it was because the title had a space at the end and the script ignored it. Later, I found that even if the space was removed, the link could not be connected. Then I had to read the code I copied before, and found that one of the steps used Discussion’s post classification, and the first one was selected by default in the code, but my forum was empty at that time, and the first one was an announcement post, which caused all The categories of posts moved from the forum are different from the ones I set up before. Then I changed the category and was able to link.
Originally, the code given by Xie Da was to update the original comments, but there was a problem with the original comments, that is, they were all displayed as code blocks. It would be a bit troublesome to change this, my usual style is to cut through the mess quickly and delete it all, and then I found another embarrassing problem, how to delete it? In fact, it is not difficult, that is, to modify the GraphQL statement. Since there is a function of batch generation and update of posts, there will also be batch deletion. Use the statement of Xie Da’s download information to get the data and use the following to delete all up:
for (i in seq_len ( nrow (info))) { message (i, ': ' , info $ title[i]) print (gh :: gh_gql ( sprintf ( 'mutation { deleteDiscussion(input: {id: %s}) { discussion { id } } }' , str_json (info $ id[i]), str_json (info $ title[i]), str_json (info $ body[i])))) }
Of course I ignored all warnings. As for the code block problem, I simply and rudely changed the four quotation marks into one, then forgot to delete the header problem, and ran it again. In fact, there are still some problems left over from history. I have to move some comments from the old website and the English website. The main problem is that Disqus retains the title at that time. I changed the template later, so the change of the title caused the link to become invalid. I just changed it by hand, but fortunately there were not many.
After tossing for a long time, it should be considered that the move is over now. Now I am curious why everyone will receive all the reply emails. I suspect that many people reply directly to the forum instead of replying at the bottom of the post, and I find that the email reply is not A sub-reply of the original reply will be generated instead of a new reply. But it doesn’t matter, it’s fine now, GitHub should not be blocked, after all, Microsoft is still doing business in China, I hope it’s not poisonous milk.
This article is transferred from: https://yufree.cn/cn/2023/05/17/disqus/
This site is only for collection, and the copyright belongs to the original author.