Content review is an indispensable part of website operation, not only does it concern the quality of content, but it is also an important guarantee for maintaining a healthy ecosystem of the platform and ensuring compliance. In AnQiCMS, in addition to the built-in sensitive word filtering and other security mechanisms, we can also cleverly utilize its powerful template filter function, especiallysplit/containandreplaceThese three text processing filters, to build a more flexible, more intelligent, and more practical content review auxiliary mechanism that meets the actual operation needs.

containFilter: quickly identify potential risks

Firstly, let's understandcontainFilter.This filter's function is very intuitive: it can determine whether a given text string contains a specific keyword or phrase, and returns a boolean value (true or false).This is particularly important in the initial screening stage of content moderation.

containYou 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,.com/http://, or certain specific advertising slogans. Whencontainthe 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 it directly, mark it 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 article content containshttp://or.comWhen, 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 one-time 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 provides the possibility for us to analyze the content in depth.

For example, you can split the article content into individual words by spaces or commas, then iterate over these words, and process each word.containCheck. This can avoid the situation where keywords are embedded in long sentences and are difficult to find.

Assuming we have a custom list of sensitive words, which may be stored in a configuration item in the form of a comma-separated list. We can first convert this list to an array, thensplituse this array.forLoop through the words in the content and compare them with the sensitive word list one by one.

{% 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 %}

PasssplitAuxiliary, we can perform 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 time,replacethe filter becomes a powerful assistant for achieving automated content purification.replaceFilter can replace the specified old text in a string with new text.

This is particularly useful in content moderation mechanisms, such as:

  1. Sensitive word masking: Replace detected sensitive words with asterisks***或其他符号,既保留了内容的上下文,又避免了直接展示不当信息。
  2. 链接清理:自动移除或转换不被允许的外部链接。
  3. 内容标准化Correct common misspellings or unify brand terminology.
{% set moderatedContent = archive.Content|replace:"广告,***" %}
{% set moderatedContent = moderatedContent|replace:"营销信息,【推广内容】" %}
{{ moderatedContent|safe }}

Through the above method, we can automatically replace the "ad" and "marketing information" in the article content, reducing the workload of manual intervention.

Combination use: Build an intelligent review workflow

Single filters are useful, but their true power lies in their combination use, building an intelligent content moderation workflow that can automatically identify, analyze, and correct content.

The following is a scenario imagination of a combination usage:

  1. Initial screening and marking: UtilizingcontainFilter quickly scans the content to identify whether it contains predefined sensitive features (such as specific link formats, extreme speech keywords). If a match is found, special HTML tags (such as a<span>Label),let background or front-end administrators identify at a glance.
  2. Deep analysis and correction: If preliminary screening finds suspicious content but cannot be directly deleted, further use can be madesplitSplit the content into words and then traverse these words. CombinecontainTo find specific sensitive words. Once found, use immediatelyreplaceFilter these sensitive words and block them or replace them with neutral words.
  3. Information extraction and recording:You can even use these filters to extract specific types of information (such as phone numbers, email addresses), and then record them for subsequent manual review or statistical analysis. AlthoughsplitandcontainIt cannot directly “extract” all complex patterns, but combined with the powerful regular expression capabilities of JavaScript or the more powerful Go language backend, template filters can serve as a data preprocessing tool for the frontend presentation layer.

For example, we hope to automatically identify and replace the advertisement language in the article detail page, and to mark paragraphs containing external links with special tags:

{% 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 such a combination of actions, you can achieve a considerable degree of automatic 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 provided by template filters are limited, mainly focusing on the display and simple processing of content output.For more complex deep semantic analysis, image recognition, etc., it is usually necessary to combine with the more powerful Go language business logic processing of AnQiCMS backend, or integrate with third-party AI review services.But as the last line of defense for front-end content display, flexibly using these filters will undoubtedly add a layer of intelligence and efficiency to your content review mechanism.


Common Questions and Answers (FAQ)

Q1: AnQiCMS backend itself has sensitive word filtering function, what else can the template filter do?A1: AnQiCMS后台的敏感词过滤通常在内容发布或保存时生效,直接阻止或标记问题内容。而模板过滤器则是在内容发布时进行,用于过滤掉不需要的HTML标签或样式,保证内容的整洁和一致性。presentationThe last layer of processing before the user.It can perform secondary processing on content that passes the background check but still poses risks, such as masking certain words, adding warning information, or even dynamically adjusting the display of the content without affecting the storage of the original content.Both are complementary rather than substitute relationships, jointly constructing a multi-layered content security defense.

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 the template variable form