Summary | This theme component allows users to block keywords. Requires three custom user fields to be created in Admin settings in order to function. | |
Preview | I can’t preview this on theme-creator because it requires creating user fields, but I’ve included screenshots below. | |
Repository | Github - a-very-old-sock/discourse-keyword-block | |
Install Guide | How to install a theme or theme component | |
New to Discourse Themes? | Beginner’s guide to using Discourse Themes |
Install this theme component
This theme component allows users to block keywords, specified by the user in Preferences > Profile. Requires three custom user fields to be created in Admin settings in order to function.
Block keywords in the topic title or topic excerpt:
Block topics or reply posts that contain the keyword, as well as suggested topics that contain the keyword:
This theme component allows an individual user to specify keywords they don’t want to see, and hides the topics and reply posts containing that keyword with a link to show anyway. Watched words is an admin setting that applies for all users across the whole site; this allows individual users to specify their own keywords that they don’t want to see.
Example scenario: a pets forum might have a general thread about dealing with pet hair where the main topic isn’t tagged with a specific kind of animal. User A replies about their dog, User B replies about their cat, but User A doesn’t want to see anything about cats at all. What this theme component does is lets User A put “cat” in their blocklist, and then anywhere that “cat” appears in a topic or rely, replaces it with “Blocked for containing cats” with a click to show anyway.
The user must specify a comma-separated list of their blocked keywords in a custom user field in Preferences > Profile, and can specify if the keywords to be blocked are case sensitive or must match on the whole word. (Case sensitivity and whole-word matching apply to the whole block list, not individual keywords).
This theme component requires you to make three custom user fields in Admin > Customize > User Fields in order to function. By default, the theme component settings expect these user fields to be 1, 2, and 3 in the order listed below. If you have other custom user fields defined, you’ll need to enter the correct user field numbers in the theme component settings. (User field numbering starts at 1, so count down the list of how many other user fields you have defined). See the Meta Create and configure custom user fields guide for further details.
1 - User’s blocked terms list
Field Type: Text Field
Field Name: (any name will work here) Blocked Terms
Field Description: (any description will work here) Block words or phrases that appear in posts or topics. Comma separated. To block a username, include @ if whole word matching is selected.
Editable after signup
Required at signup
Show on public profile
Show on user card
Searchable
2 - Case sensitivity
Field Type: Confirmation
Field Name: (any name will work here) Blocked terms - case sensitive
Field Description: (any description will work here) Words in the “Blocked terms” list are case sensitive.
Editable after signup
Required at signup
Show on public profile
Show on user card
Searchable
3 - Search whole or partial words
Field Type: Confirmation
Field Name: (any name will work here) Blocked terms - whole words
Field Description: (any description will work here) Blocked terms must appear as full words, not as partial words
Editable after signup
Required at signup
Show on public profile
Show on user card
Searchable
The css below is included in the theme component and will prevent any custom user fields from being displayed on the signup form. If you have other custom user fields you do want displayed on the signup form, you’ll need to override this with your own custom css.
.login-form .user-fields {
display: none;
}
I’ve only tested this with the Default theme. Posts and topics are blocked when categories are set to display Categories/Latest and Categories/Top, but not in Categories/Featured or any of the box category views. I’m unlikely to change this because I don’t need it for my own site, but pull requests are welcome.
This currently only blocks a post that contains a keyword in the title or the excerpt visible in the browser. I haven’t been able to figure out how to check the content of the whole post when viewing search results or a topic list, but I’d welcome any ideas how to do so.
I intend for this to also work on the full-page-search view, but as of 2/24/2023 I’m currently struggling to get that working. I’ll edit this if I’m able to get blocking to work on search.
This is compatible with the Topic Excerpts theme component; it is not compatible with Topic List Previews. I have not tested this extensively with other theme components.