How to identify "about" topics?

AI 生成的摘要

Identifying “about” Topics

jack2 is using the API to delete a category and its related topics, but is unable to delete the “about” topic. To avoid attempting to delete it, jack2 wants to know if there is a field to check if a topic is an “about” topic.

fefrei suggests a good approximation is to request /t/<id>/1.json and check for a specific property. If the property is missing, it’s likely the “about” post.

Alternatively, fefrei recommends running a Ruby script in the Rails console to get the id of the “about” topic for a specific category.

jack2 finds a topic_url field in the category descriptor, which can be used to get the topic_id by parsing the URL.

fefrei acknowledges the discovery, noting that they had remembered the existence of an id, but didn’t notice the topic_url field.

I’m using the API to delete a category and all related topics. Here is what I do:

  • I get the category topic list
  • I iterate over category topics and delete them
  • I delete the empty category

The category “about” topic cannot be deleted. This is ok, because it is automatically removed when deleting the (almost) empty category. However, I would like to avoid trying to delete it when iterating over all topics (in order to avoid a server round-trip and an exception in my code). Is there a field I can check to see if a topic is an “about” topic?

A good approximation should be requesting /t/<id>/1.json and checking for this property:

If missing, it’s probably the about post. (There might be other reasons for not being able to delete it.)

You might be better off running a Ruby script, which will be able to do something like this way more quickly. In the Rails console, this is how you get the id of the about topic for the staff category:

Category.find_by_slug("staff").topic_id

Thanks a lot, @fefrei. Your advice about the Rails console incited me to look deeper into the category descriptor for a topic_id field. And I found… a topic_url field! Getting the topic_id is then just a matter of:

const topic_id = parseInt(topic_url.split('/').pop())

Thanks again!

Good catch! I saw that, but didn’t notice it, because I had remembered that there was an id. :blush: