主题网址包括其类别

I am investigating the possibility of including the category in the topic URL for retargeting purposes.

For example: https://meta.discourse.org/t/support/where-can-i-create-tags/31094 or https://meta.discourse.org/support/t/where-can-i-create-tags/31094

From previous responses on this subject, it seems as though this will wreck havoc on the routing system, correct?

What about the possibility of including the category in query string? https://meta.discourse.org/t/where-can-i-create-tags/31094/?category=support

Thoughts, suggestions, answers?

1 个赞

I think if you put it before the topic ID at the end there’s no problem… but you can’t add more slashes or other delimiters.

Maybe you can use underscore to delimit if you need it, e.g. these two links go to the same place without any problem:

https://meta.discourse.org/t/topic-url-to-include-its-category/39996

https://meta.discourse.org/t/_support_topic-url-to-include-its-category/39996

your URL with question mark at the end might work - seems to work here. Not sure what the effect of that is.

https://meta.discourse.org/t/where-can-i-create-tags/31094/?category=support
3 个赞

这是可以通过网站设置还是插件实现的?

您好,

我对 Discourse 以及论坛都非常陌生,我想问一下,论坛帖子的 URL 是否可以包含其所属的分类?

我的意思是,目前我看到的分类 URL 如下:
https://randomname.discourse.group/c/category-name/6

但是当我点击该分类下的帖子时,URL 中却不包含分类的引用:
https://randomname.discourse.group/t/what-a-great-thread/18

抱歉,我尝试搜索并理解答案,但运气不佳。

非常感谢您的帮助。

非常感谢。

一个好的想法,可以确保命名正确。在 Discourse 中,一个帖子被称为一个主题(Topic)。

与分类(Category)的关联是隐含的,所以不需要。

另外,如果主题被移动到新的分类,URL 将会过时且基本上无效。

如果你一定要添加查询字符串参数,通常也没有坏处。

但你的用例是什么?你想实现什么目标?

2 个赞

我正在使用一个抓取论坛的第三方软件。我受限于它的查询功能,因此当它抓取一个帖子(主题)时,需要推断它属于哪个类别,而它似乎是通过 URL 来实现的。

从应用程序的角度来看,这毫无意义,正如我已经指出的那样,但您也许可以构建一个插件或脚本来更改所有 URL。

我认为类别在爬虫视图的 HTML 中很清楚,所以也许您可以更改该工具以利用这一点?

2 个赞

如果你是明确向抓取器提供 URL 并定义如何从中提取类别的人,你可能可以使用 Tobias 建议的技巧——例如,你可以为它提供 /t/category-name__topic-slug/topic-id。Discourse 将根据 topic-id 提供一个 301 重定向响应到最终 URL。

但如果它在抓取过程中获取 URL,那么为了满足抓取策略的限制而付出大量努力,感觉有点得不偿失。

据我所知不行。通过插件提供 /t/category-name/topic-slug/topic_id 路由似乎是可行的,但然后有一个选项让所有 Discourse 中的主题引用都优先使用这个替代路由,这(对我个人而言)似乎是费力不讨好的。

2 个赞

只是有个想法,您是否考虑过使用 RSS feed?Discourse 内置了 RSS feed 输出功能。

2 个赞

这是什么软件?您可以通过几种方式在不更改 URL 的情况下获取类别(在 HTML 和 JSON 中)。

对于 JSON,请抓取此内容,而不是抓取:
https://meta.discourse.org/t/topic-url-to-include-its-category/39996

抓取此内容:
https://meta.discourse.org/t/topic-url-to-include-its-category/39996.json

并查找 category_id 字段。

另一种可能性是使用 Data Explorer 来提取您需要的内容。

4 个赞