自动链接词

:exclamation: Discourse 内置了一个名为 Watched Words 的功能,它可以 复制此主题组件的大部分功能。在安装此主题组件之前,请考虑使用该功能。

:discourse2: 摘要 Auto-Linkify Words 允许您自动将帖子中的特定单词或模式超链接到目标 URL。
:hammer_and_wrench: 仓库链接 https://github.com/discourse/discourse-linkify-words
:open_book: Discourse 主题新手? Discourse 主题使用入门指南

安装此主题组件

功能

如何配置?

使用以下格式配置主题设置:

WORD, https://destination.url.com

或使用正则表达式(在 JavaScript 实现 中),格式如下:

/regex/, https://destination.url.com

每行一个条目

使用正则表达式

使用正则表达式,您可以将某种模式匹配到单个 URL。这对于同义词或在句子中可呈现不同形式的单词等非常有用。

此外,您还可以根据匹配内容自动生成 URL。例如,假设您有一行产品,每个产品都有唯一的数字 ID,并且您希望将它们自动链接到各自的 URL。使用:

/product-([0-9]+)/, https://myshop.com/product/$1

product-42 将被自动链接到 https://myshop.com/product/42

注意正则表达式中的捕获括号以及 URL 中的 $1,它将被括号内的匹配内容替换。您还可以捕获字符串的多个部分,并使用 $2$3 等。

默认情况下,正则表达式区分大小写(而 WORD 不区分大小写)。但是,您可以使用标准的 “i” 修饰符来更改这一点,如下所示:

/foo/i, https://example.com

在这种情况下,FOO、Foo 或 foo 都将被匹配。

实际效果如何?

限制

  • 替换仅会出现在 Web UI 中,不会出现在电子邮件中。

设置

名称 描述
linked words
excluded tags
excluded classes

致谢

非常感谢 @Osama 构建主题设置,以及 https://stackoverflow.com/questions/8949445/javascript-bookmarklet-to-replace-text-with-a-link 提供的实现指导。


:discourse2: 由我们托管? 主题组件可在我们的标准版、商业版和企业版计划中使用。

104 个赞
Add <abbr> tags to words in posts
How to automatically convert Keywords to Affiliate Links?
Special inline commands
Discourse Linkify Google Sheets
Is there a plugin to make my forum a shop?
When a thread is too important to lose
Customizing your site with existing theme components
User preference persists through Safe Mode
Add settings to your Discourse theme
Discourse Dictionary Plugin :ab:
How to replace text and update dynamically
Redirecting internal links via routes
Watched Words to serve as shortcut command to insert links
Limit # of links for a watched word?
How can I enable: Auto-hyperlinking text to reference to other posts?
How can I enable: Auto-hyperlinking text to reference to other posts?
Notification email without external link
Rewrite external URLs
Rewrite external URLs
Linked/forcing search keywords to specific topics/posts
Replace text with more than just links?
Community glossary?
The most easy way to let my users insert a FinViz chart image based on values?
Options for integrating a wiki knowledge base
Abbreviations and acronyms plugin
Support for magnet links
Need proofread of this advise about using theme preview
Meta annotation sidepost for bots?
Add <abbr> tags to words in posts
Object Settings?
Add <abbr> tags to words in posts
Any Autolinker solution for Discourse?
Javascript in theme component only runs once?
Images in posts versus topic-list-previews
Replacing special text to linkify them on posts
Comment on a question instead of answering it
Auto-replace text with link to topic
What are the different ways to customize content inside a post (custom attributes and such)
Minor mod to Automatic Actions based on Words Found in Posts
Prevent hyperlink
Turn off automatic (c) to © substitution
Watched words links corrupt @mentions and #categories
Get only top level posts in topic via discourse API

fantastic, system-wide feature… was thinking about this just the other day!

Hi

First off, I’d just like to thank everyone for all the help provided to me over the past few weeks. I know I’ve been asking lots of questions - I am also a beginner to Discourse and coding in general, and the community here has been incredible.

I am wondering if it would be possible to add on a feature to this, which is very similar in nature. I think most of the functionality is built, my use case for this is slightly different however.

Would it be possible to have a box like this on a ‘Tags’ page, where the user can type in specific tag words manually, and it would create a customized url based on these words? For example, the image below would produce a url something like this: www.websitename.com/tags/■■■■■/■■■■■/■■■■■. This would be a great feature for Tags Intersection, and would allow the user to specify the words in their intersection.

image

Thanks.

1 个赞

seems to be not showing when you add it to a theme:

21%20AM

tried adding to default… but doesn’t seem to be working as intended:

It is not a problem related to this specific theme, see:

https://meta.discourse.org/t/js-error-on-click-adding-a-theme-component/82313

4 个赞

Sometimes one like is not enough. :heart: Office high-fives took place today as we thought through all the ways we could put this to use!

One question, though: Is the following a bug?

Most of my links are working, however urls that include appended parameters are failing.

For example, I want to use this link:
https://republicwireless.com/shop/phones/moto-x4/?icid=phones-cta-forums-moto-x4-post

but when it is created from linkified words, clicking it results in:
https://forums.republicwireless.com/clicks/track?url=%20https%3A%2F%2Frepublicwireless.com%2Fshop%2Fphones%2Fmoto-x4%2F%3Ficid%3Dphones-cta-forums-moto-x4-post&post_id=134361&topic_id=16863

The same link added to a post traditionally (pasted, or using the “link” icon from the toolbar) works.

5 个赞

Looks like @zogstrip fixed this FIX: don't track clicks · discourse/discourse-linkify-words@ef072b3 · GitHub … I just updated your component, can your refresh the problem page and try again?

6 个赞

That appears to have fixed it! Thank you!!

1 个赞

Keep in mind, we are going to elevate this to a proper feature in Discourse in the “special actions on words” section, but it will take a bit.

I love that this is a component though cause we get to “test out components” in anger. @Osama / @j.jaffeux one huge omission we have here is that it is ultra mega super painful working with long lists in settings, try this out with 50 or so links to experience the pain. We need a different “list” control for managing long lists of things.

14 个赞

do you have any idea in mind about this?

1 个赞

Honestly, I am not sure, but have a look at republic for an example of how painful this gets.

2 个赞

Agreed it’s a massive pain…

A first step would be to give it more width, but that wouldn’t make it perfect.

What do you think if I hide the part after the comma, and you can only see it when mouse overing ?

I think that would be good, you mostly care about the words you are linkifying when you look at the list.

2 个赞

I kind of think it needs another mode of item per row, that way at least you can tell what is going on in long lists

2 个赞

I see. Shouldn’t be hard to do, I already apply this kind of per multi-select modification for category colors, I have an idea, will work on it in the next days.

4 个赞

Here is my proposal:

A new site-setting type: dictionary.

  • one item per row
  • explicitly shows the key/value relation
  • ellipsis the end of the value so it’s always readable
  • will limit the height for the component so it becomes scrollable after something like 10 rows

If it works for you I will work on it beginning next week.

8 个赞

Do we have other site settings that need this?

not to my knowledge, but AFAIK it doesn’t have to be an explicit new type server side, it could only be a new type client site like (url-list, host-list…)

So in the end it would be very little code, it’s mostly a subclass of list-setting where I split the label and present it differently.

We should split this topic

I feel there are a few settings that list urls like allowed iframes and some others that can easily benefit from item-per-row, maybe even the user list in admin groups as well

I think we should start with a simple item per row mode prior to adding dictionary

8 个赞

After a discussion with sam:

  • rename our current “list” to “compact-list”, which will display as many items per row it can (list current behavior)
  • “list” will now only display one item per row
  • this shouldn’t touch server side client setting, default UI for list will be modified, and the new client side site setting “compact-list” will rely on “list”
8 个赞

I think, there is a missing step in configuring Linkify component.

After this

Then, activate the linkify components in every theme.

I hope the last step should help others newbie like me.

I am certainly love this feature. :heart:

9 个赞