When using AnQiCMS to manage website content, we often encounter the need to automatically convert URL addresses or email addresses in text to clickable links.urlizeandurlizetruncThis is a powerful tool to implement this function. It can not only automatically identify links in text but also automatically add links after conversion.rel="nofollow"Properties, which is very practical for SEO optimization.
However, when using these filters, many friends may be curious: Is there a global option in the AnQiCMS backend settings that can control them uniformly?urlizeandurlizetruncWhat about the behavior? For example, can they be turned on or off with one click, or set uniformly?urlizetruncWhat is the truncation length? Today, let's delve deeply into this issue.
Deeply Understandurlizeandurlizetrunc
First, let's briefly review.urlizeandurlizetruncThese two tools.
urlizeFilterIt mainly scans text content, automatically identifies it, and recognizes the URLs (such ashttp://www.example.com/www.example.comevenexample.com) and email addresses (such as[email protected]),<a>tags. The converted links will be default withrel="nofollow"This attribute helps inform search engines not to pass PR value to these external links, thus better controlling the flow of weight on our website.urlizetruncFilter: withurlizeSimilar, it also has the function of automatically converting links. But on this basis,urlizetruncIt allows us to specify a number to truncate the displayed text of the link. If the length of the original URL string exceeds the number we set, it will add an ellipsis at the truncation point....)Make the page display more tidy.
These filters are very flexible in their use in the template, and we usually apply them to the variables that need to be processed like this:
{{ content|urlize|safe }}
{{ description|urlizetrunc:30|safe }}
Here are the|safeIt is a feature of the Django template engine, used to inform the system that this content is safe and does not require HTML escaping to ensure that the link is displayed normally as a clickable HTML tag.
Explore Global Options: AnQiCMS Back-end Settings Analysis
With the question of 'Does it have global options', we carefully reviewed all the settings of AnQiCMS backend. AnQiCMS provides rich configuration options covering all aspects of the website, but justurlizeandurlizetruncFor the direct behavior control, the situation is as follows:
- [en] Global function settings(
help-setting-system.mdThis section is mainly responsible for the website name, LOGO, filing number, copyright information, website address, multilingual settings, and custom global parameters. No direct control was found here.urlizeorurlizetruncThe option to enable, disable, or truncate length. - Content Settings(
help-setting-content.mdThis area focuses on content processing methods, such as whether to download remote images, whether to automatically compress large images, and thumbnail processing methods, etc. There is a very relevant option that isWhether to automatically filter external links.- If selected“Do not filter external links”External links within the document will be retained, and the system willautomatically add
rel="nofollow"tags. - If selected“filter external links”, and the system will directly remove external links from the content.
- If selected“Do not filter external links”External links within the document will be retained, and the system willautomatically add
This setting of 'Whether to automatically filter external links' is not a direct control, although it does affect all external links on the website (including those generated by)urlizeorurlizetruncthe filter itself, but it indeed influences all external links on the website (including those generated by)urlizethe filter) of the website.nofollowBehavior. It is worth noting that,urlizeThe filter is designed to automatically add,rel="nofollow"This means that even if "Content Settings" is selected to "Do not filter external links", and external links are also addednofollow,urlizeIt will also ensure that the link it generates has this attribute. It can be said,urlizeInrel="nofollow"It has its own 'halo' on this point.
The conclusion is:In the AnQiCMS backend, there is currently not oneDirect global optionsTo unify controlurlizeandurlizetruncThe specific behaviors such as 'whether to use' and 'truncation length' of the filter. They are more commonly considered as local tools during template rendering and need to be manually applied when used.
Why is there no direct global option?
This design is not accidental, it may hide AnQiCMS's considerations for flexibility and performance:
- Flexibility firstThe different areas of the website may have different requirements for handling links.For example, the comment section of the article detail page may wish to truncate all external links for display, while the friendship link page does not require truncation.If there is a global switch, it might limit such fine-grained control.
- Contextual relevanceThe truncation length of links, whether to automatically convert, etc., is often closely related to the specific context in which the content is located (such as article text, list summary, comment sections, etc.).Control at the template level can better adapt to different scenarios.
- Performance considerationsIf all text content needs to be scanned and processed globally on the server side, it may have a certain impact on the performance of the website.Lowering this type of processing to the template layer can trigger it only when needed, making it more efficient.
[en] Practical Tips
Since there is no direct global option, we can take the following strategies to maintain consistency and efficiency:urlizeandurlizetruncWhen using, we can adopt the following strategies to maintain consistency and efficiency:
- Use as needed, rather than blindly applyingAccording to the actual needs of the content, automatic link conversion should be applied only where necessary
urlizeorurlizetruncFor example, using them in user comment sections, automatically scraped content blocks, and other similar places is very appropriate. - Utilize
withLabel unified truncation lengthIf you want certain types of pages within the website (such as all article list summaries)urlizetruncThe truncation length is consistent, and can be kept at the top of the template or in common code segments (such aspartial/header.html), use{% with %}Define a variable to store this length using the tag, and then refer to this variableurlizetruncanywhere it is used.
Thus, when it is necessary to modify the truncation length in the future, it can be done by changing only one place.{% with link_truncate_length=30 %} {{ item.description|urlizetrunc:link_truncate_length|safe }} {% endwith %} - Understand the meaning of "Content Settings" in the background.: Always remember the "Content Settings" in the background.