In daily content publishing work, we often need to insert various URLs in articles, some starting with HTTP, and some with HTTPS. Manually adding each URL<a href="...">Tags are not only inefficient but also prone to errors, especially when dealing with large amounts of content. This repetitive work is time-consuming and labor-intensive. Anqi CMS understands the pain points of content creators and therefore integrates a powerful and intelligenturlizeFilter, designed to make the automation of URL link processing easy and simple.

urlizeFilter: Intelligent recognition and protocol retention

Anqi CMS'surlizeThe filter is designed to address this pain point.Its core function is to automatically identify and convert URLs and email addresses in plain text into clickable HTML links, greatly reducing the burden on content editors.

About the URLs containing both HTTP and HTTPS protocols in the text,urlizeThe filter performs very intelligently and respects the original text. It does not arbitrarily convert all links to a single protocol, but rather accurately identifies and maintains the protocol declared in the URL:

  • When your text explicitly contains a URL that starts withhttp://,urlizeit will preserve this protocol and generate ahttp://protocol link. For example, if you enter这是我的网站:http://www.example.comit will be converted to<a href="http://www.example.com" rel="nofollow">http://www.example.com</a>.

  • Similarly, if the URL starts withhttps://.urlizeit will also ensure that the generated link uses a securehttps://protocol. For example,请访问我的安全页面:https://secure.example.comwill be converted to<a href="https://secure.example.com" rel="nofollow">https://secure.example.com</a>.

  • It is worth mentioning that even if you only enter something likewww.example.comorexample.comThis URL without a protocol prefix,urlizewill also be automatically supplementedhttp://with a protocol, ensuring it becomes an effective clickable link.

This fine-grained processing of URLs for different protocols brings great convenience to content operations, you need not worry about the protocol being incorrectly converted, causing links to fail or security alerts. At the same time, in order to follow SEO practices, urlizeThe filter will also automatically add these generated links.rel="nofollow"This means that the search engine will not pass weight through these links when crawling your website, which helps you better control the SEO effect of your website.

How to useurlizeFilter

In the templates of Anqi CMS, useurlizeThe filter is very intuitive. You just need to pass the text variable containing the URL through the pipe symbol|Pass tourlize过滤器即可。由于EnglishurlizeThe filter generates HTML code, so it usually needs to be used in conjunction with|safeThe filter is used together to ensure that the browser can correctly parse these HTML and not display them as plain text.

For example, if your article content is stored in a file namedarchiveContentThe variable can be called like this in the template:

<div>
    {{ archiveContent|urlize|safe }}
</div>

This way,archiveContentAll URLs and email addresses in it will be automatically converted to those with the correct protocols andnofollowThe HTML link of the attribute, greatly enhances the efficiency and standardization of content editing and website content. If you wish to display the generated link more concisely, for example, only showing part of the URL,urlizetruncThe filter provides additional truncation functionality, which will be abbreviated with an ellipsis after the specified length...replacing the redundant part, but its processing logic for HTTP and HTTPS protocols is the same asurlizeis completely consistent.

Summary

Anqi CMS'surlizeThe filter identifies and automatically links conversion functions through its intelligent protocol, greatly simplifying the work of content editors. It can not only handle HTTP and HTTPS links accurately, but also automatically add SEO-friendlyrel="nofollow"Properties, ensure that your website content achieves a good balance between aesthetics, user experience, and search engine optimization.This feature is another demonstration of how Safe CMS is committed to providing an efficient and easy-to-use content management solution, allowing you to focus more on creating high-quality content.


Common Questions (FAQ)

  1. urlizeDoes the filter process email addresses in text?Yes,urlizeThe filter not only recognizes and converts URLs, it also recognizes email addresses in text and converts them into clickablemailto:links, for example[email protected]will be converted to<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.

  2. Does the generated link support custom attributes, such as removingrel="nofollow"?According to the document description of AnQi CMS,urlizeThe filter will automatically add to the generated linksrel="nofollow"Property, this is to follow SEO**practices.The method to cancel or customize this property through parameters is not mentioned directly in the current document.If you need more flexible link attribute control, you may need to manually write HTML links, or consider using custom template tags or JavaScript for more advanced processing.

  3. urlizeandurlizetruncWhat are the differences between filters? urlizeThe filter will convert the URL in the text to a full clickable link, displaying the original URL.urlizetruncThe filter adds a truncation feature on this basis, allowing you to specify the maximum display length of the link text. The part exceeding the specified length will be...Replace it to make the display more concise. Both handle the logic for HTTP/HTTPS protocols in the same way.