In the daily content operation of AnQi CMS, we often need to convert links in text to clickable hyperlinks to enhance user experience and the interactivity of website content. AnQi CMS provides a very practical template filter ——urlize。Many operators may wonder, likewww.example.comsuch aswwwdomains, or even directexample.comnaked domains like this,urlizeCan the filter intelligently identify and correctly convert them? The answer is yes.
urlize过滤器:智能链接识别与转换的深度解析(English)
urlizeThe main function of the filter is to automatically find URL strings and email addresses in the text content and automatically parse them into standard HTML<a>This greatly simplifies the work of content editors, avoiding the tediousness of manually adding HTML tags, while ensuring the uniformity and accuracy of link formats.
For core doubts, that isurlizewhether it can recognize and convertwww.example.comor bare domain namesexample.comURLs in the form, the examples in the document clearly demonstrate its intelligence. Whetherwww.florian-schlachter.deOrflorian-schlachter.denaked domains like this,urlizeCan accurately identify and automatically addhttp://The prefix of the protocol, which is finally converted into a complete, clickable hyperlink. This means that even if only the simplest domain form is provided in the content,urlizeAlso, it can standardize it intelligently. Of course, for those that already containhttp://orhttps://The complete URL of the protocol, it can also handle it perfectly.
For example, when we have a text containing the following two forms of domain names:
这是一个网站:www.example.com,欢迎访问。或者您也可以访问 example.com。
AfterurlizeAfter filtering, they will be converted to:
这是一个网站:<a href="http://www.example.com" rel="nofollow">www.example.com</a>,欢迎访问。或者您也可以访问 <a href="http://example.com" rel="nofollow">example.com</a>。
As you can see,urlizeNot only does it recognize these two forms, but it also thoughtfully completes them for them.http://Protocol, and automatically addedrel="nofollow"properties.rel="nofollow"It is a very important SEO practice, which tells search engines not to consider this link as a 'vote' from the site. This is very beneficial for preventing spam links and managing the SEO weight of user-generated content.
Content operations in actual application
In daily content operations,urlizeThe filter is undoubtedly a powerful assistant.
- Article publicationWhen the article references external resources or product links, there is no need to manually add them one by one.
<a>Tags, just make sure the text contains the URL,urlizeand the conversion can be completed. - User CommentsFor the review content submitted by users, it may contain various forms of URLs.
urlizeIt can automatically convert them into clickable links to enhance the interactivity of the comment section, and at the same time throughnofollowProperty management external link SEO impact. - Product descriptionWhen mentioning external partners or reference websites in product or service introductions,
urlizeEnsure the availability of the link.
In addition, the Aqy CMS also providesurlizetruncFilter, its function is withurlizeSimilar, but allows you to specify the display length of the link text, and the part that exceeds will be truncated....This is very useful when the page layout is limited or when beauty is required.
Simple and easy-to-use method
In the templates of Anqi CMS, useurlizeThe filter is very intuitive. Simply pass the text variable to be processed through the pipe|Pass tourlizeThe filter. It is important to note that,urlizeIt will generate HTML code. To make the browser parse it correctly rather than display it as plain text, it usually also needs to be combined with|safeFilter used together.
For example, if your article content is stored inarticle.ContentIn the variable, you can call it like this in the template:
{{ article.Content|urlize|safe }}
This code will ensurearticle.ContentAll URLs that meet the conditions are converted into clickable hyperlinks and output to the page in a safe HTML format.
In summary, the security CMS ofurlizeFilter is an intelligent, efficient, and SEO-optimized practical tool that can accurately identify including naked domain names andwwwThe URL formats including domain names are automatically converted to standard, clickable hyperlinks, greatly enhancing the efficiency of content management and user experience.
Common Questions (FAQ)
urlizeDoes the filter automatically add a protocol prefix to naked domain names?Yes,urlizeThe filter is very smart. When it recognizesexample.comorwww.example.comsuch domains without an explicit protocol (likehttp://orhttps://), it will automatically add one for them.http://As the default protocol, ensure that the converted link is complete and clickable.Besides the domain,
urlizewhat types of links can it recognize and convert?urlizeThe filter can not only identify various forms of domain names (including those with and without protocols), but also complete URLs (such ashttps://www.example.com/path?param=value) as well as email addresses (such as[email protected]),and convert them to the corresponding<a>ormailto:Link.Why
urlizeThe converted link defaults to havingrel="nofollow"What is the role of this attribute?urlizeThe filter is automatically addedrel="nofollow"Property, this is a SEO** practice.It tells the search engine not to consider this link as a recommendation or a 'vote' for the target page.This is particularly important when dealing with user-generated content (such as comments, messages) or external links that are not related to core business, as it helps website administrators better control the SEO weight distribution of their own websites and avoid unnecessary SEO risks.