Content review is an indispensable part of website operation, not only does it relate to content quality, but it is also an important guarantee for maintaining a healthy platform ecosystem and ensuring compliance. In AnQiCMS, in addition to the built-in sensitive word filtering and other security mechanisms, we can also cleverly make use of its powerful template filter function, especiallysplit/containandreplaceThese text processing filters are used to build a more flexible, intelligent, and practical operation-oriented content review assistance mechanism.
containFilter: quickly identify potential risks
First, let's understandcontainThe filter works very intuitively: it can determine whether a text string contains a specified keyword or phrase and returns a boolean value (true or false).This is particularly important in the initial screening stage of content review.
Imagine that the content published by users on your website may contain some inappropriate advertising links, sensitive words, or specific expressions that do not conform to the brand image.If relying solely on manual review line by line, efficiency would undoubtedly be low. With the help ofcontainYou can perform a quick 'risk identification' before the content is output to the front-end page.
For example, you can check if the article content contains keywords that indicate external links, such as.com/http://Or some specific advertising phrases. WhencontainWhen the filter detects these keywords, you can combine the conditional judgment in the AnQiCMS template (ifThe statement decides how to handle this content: whether to hide directly, mark for review, or make further corrections.
{% if archive.Content|contain:"http://" or archive.Content|contain:".com" %}
<p class="warning-message">这段内容可能包含外部链接,请谨慎阅读!</p>
{% endif %}
{{ archive.Content|safe }}
The above example shows when the content of the article containshttp://or.comAt the time, a warning message is displayed at the top of the article.
splitFilter: Fine-grained content decomposition and analysis
containThe filter is powerful, but it usually makes a single judgment on the entire string. If we need to analyze the content more finely, such as checking whether each word contains sensitive information, or splitting a long text into smaller units for processing,splitThe filter comes into play.
splitThe filter can split a string into an array of strings based on the delimiter you specify. This allows us to delve deeper into the content.
For example, you can split the content of the article into individual words according to spaces or commas, then iterate over these words, and process each word.containCheck. This can avoid the difficulty of finding keywords embedded in long sentences.
Assuming we have a custom list of sensitive words, these words may be stored in a configuration item in the form of a comma-separated list. We can first usesplitConvert this list to an array, and then useforLoop through the words in the content and compare them one by one with the sensitive word list.
{% set sensitiveWordsList = "赌博,毒品,诈骗,暴力"|split:"," %}
{% set contentWords = archive.Content|split:" " %}
{% set hasSensitiveWord = false %}
{% for word in contentWords %}
{% for sensitiveWord in sensitiveWordsList %}
{% if word|contain:sensitiveWord %}
{% set hasSensitiveWord = true %}
{% break %}
{% endif %}
{% endfor %}
{% if hasSensitiveWord %}{% break %}{% endif %}
{% endfor %}
{% if hasSensitiveWord %}
<p class="moderation-alert">此内容可能包含敏感词汇,请注意。</p>
{% endif %}
BysplitAs an auxiliary, we can make more accurate review and judgment on a word-by-word basis.
replaceFilter: Automated correction and purification.
After identifying the content of the problem, we usually need to correct it. At this point,replacethe filter becomes a powerful assistant for achieving automated content purification.replaceThe filter can replace the specified old text with new text in a string.
This is particularly useful in content review mechanisms, such as:
- Sensitive word masking: Replace detected sensitive words with asterisks
***Or other symbols, which preserves the context of the content while avoiding the direct display of inappropriate information. - Link cleaning: Automatically remove or convert external links that are not allowed.
- Content standardization: Correct common misspellings or unify brand terms.
{% set moderatedContent = archive.Content|replace:"广告,***" %}
{% set moderatedContent = moderatedContent|replace:"营销信息,【推广内容】" %}
{{ moderatedContent|safe }}
By this method, we can automatically replace "advertising" and "marketing information" in the content of the article, reducing the workload of manual intervention.
Use in combination: Build an intelligent review workflow
The power of a single filter is useful, but its true strength lies in combination use, building a set of intelligent review workflows that can automatically identify, analyze, and correct content.
The following is an imaginative scenario for combination use:
- Initial screening and markingUtilize
containThe filter quickly scans the content, identifying whether it contains preset sensitive features (such as specific link formats, extreme speech keywords). If a match is found, a special HTML tag (such as one<span>Label), allowing backend or frontend administrators to identify it at a glance. - Deep analysis and correction: If preliminary screening finds suspicious content but cannot be directly deleted, further use can be made.
splitSplit the content into words, then iterate over these words. CombinecontainTo find specific sensitive words. Once found, use them immediately.replaceThe filter hides or replaces sensitive words with neutral terms. - Information extraction and recordingYou can even use these filters to extract specific types of information (such as phone numbers, email addresses), then record them for subsequent manual review or statistical analysis. Although
splitandcontainIt cannot directly "extract" all complex patterns, but combined with the powerful regular expression capabilities of JavaScript or the more powerful Go language in the backend, template filters can be used as a data preprocessing tool for the front-end display layer.
For example, we hope to automatically identify and replace advertisements in the article detail page and mark paragraphs containing external links:
{% set contentToReview = archive.Content %}
{# 定义需要替换的广告语规则:旧词,新词 #}
{% set adReplaceRules = "免费建站,查看详情,最新优惠,立即注册,立即购买,点击这里"|split:"," %}
{% set moderatedContent = contentToReview %}
{% for rule in adReplaceRules %}
{% set parts = rule|split:"," %}
{% if parts|length >= 2 %}
{% set oldText = parts[0] %}
{% set newText = parts[1] %}
{% set moderatedContent = moderatedContent|replace: (oldText ~ "," ~ newText) %}
{% endif %}
{% endfor %}
{# 检查是否存在外部链接,并标记整个段落 #}
{% set paragraphs = moderatedContent|split:"\n" %} {# 假设段落以换行符分隔 #}
{% for paragraph in paragraphs %}
{% if paragraph|contain:"http://" or paragraph|contain:".com" or paragraph|contain:".cn" %}
<p class="external-link-paragraph">注意:此段落包含外部链接,请谨慎。<br>{{ paragraph|safe }}</p>
{% else %}
<p>{{ paragraph|safe }}</p>
{% endif %}
{% endfor %}
Through this set of combinations, you can achieve a considerable degree of automated review and correction in the content presentation layer of AnQiCMS, greatly reducing the pressure on the operation team and improving the overall quality and security of the website content.
Of course, the capabilities of the template filter are limited, mainly focusing on the display and simple processing of content output.For more complex deep semantic analysis, image recognition, and so on, it is usually necessary to combine with the more powerful Go language business logic processing of the AnQiCMS background or integrate third-party AI review services.But as the last line of defense for front-end content display, flexibly using these filters can undoubtedly add intelligence and efficiency to your content review mechanism.
Frequently Asked Questions (FAQ)
Q1: AnQiCMS backend itself has a sensitive word filtering function, what else can the template filter do?A1: The sensitive word filtering on AnQiCMS backend usually takes effect when content is published or saved, directly blocking or marking problematic content. The template filter is for contentdisplayThe last layer of processing before it reaches the user. It can further process content that has passed the backend but still poses risks, such as obscuring some words, adding prompt information, or even dynamically adjusting the display of content without affecting the storage of the original content.Both are complementary rather than替代关系,共同构建多层内容安全防线。
Q2: Can these text filters handle all types of content? For example, image descriptions or custom fields?A2: Yes, as long as the content can be passed through template variables.