mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
feat: slugify filter from Jekyll, #443
This commit is contained in:
@@ -11,7 +11,7 @@ LiquidJS 共支持 40+ 个过滤器,可以分为如下几类:
|
||||
--- | ---
|
||||
数学 | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
|
||||
字符串 | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last, remove, remove_first, remove_last, truncate, truncatewords, normalize_whitespace, number_of_words, array_to_sentence_string
|
||||
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br, xml_escape, cgi_escape, uri_escape
|
||||
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br, xml_escape, cgi_escape, uri_escape, slugify
|
||||
数组 | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
|
||||
日期 | date, date_to_xmlschema, date_to_rfc822, date_to_string, date_to_long_string
|
||||
其他 | default, json, jsonify, inspect, raw, to_integer
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
title: slugify
|
||||
---
|
||||
|
||||
将字符串转换为小写的 URL “slug”。`slugify` 过滤器接受两个选项:
|
||||
|
||||
1. `mode: string`。默认为`"default"`,它可选的值如下:
|
||||
- `"none"`:没有字符
|
||||
- `"raw"`:空格
|
||||
- `"default"`:空格和非字母数字字符
|
||||
- `"pretty"`:空格和非字母数字字符,但排除 `._~!$&'()+,;=@`
|
||||
- `"ascii"`:空格、非字母数字和非 ASCII 字符
|
||||
- `"latin"`:与默认相同,但拉丁字符首先进行音译(例如,àèïòü 转换为 aeiou)。
|
||||
2. `case: boolean`。默认为 `false`。如果为 `true`,则保留 `slug` 原本的大小写。
|
||||
|
||||
输入
|
||||
```liquid
|
||||
{{ "The _config.yml file" | slugify }}
|
||||
```
|
||||
输出
|
||||
```
|
||||
the-config-yml-file
|
||||
```
|
||||
|
||||
输入
|
||||
```liquid
|
||||
{{ "The _config.yml file" | slugify: "pretty" }}
|
||||
```
|
||||
输出
|
||||
```
|
||||
the-_config.yml-file
|
||||
```
|
||||
|
||||
输入
|
||||
```liquid
|
||||
{{ "The _cönfig.yml file" | slugify: "ascii" }}
|
||||
```
|
||||
输出
|
||||
```
|
||||
the-c-nfig-yml-file
|
||||
```
|
||||
|
||||
输入
|
||||
```liquid
|
||||
{{ "The cönfig.yml file" | slugify: "latin" }}
|
||||
```
|
||||
输出
|
||||
```
|
||||
the-config-yml-file
|
||||
```
|
||||
|
||||
输入
|
||||
```liquid
|
||||
{{ "The cönfig.yml file" | slugify: "latin", true }}
|
||||
```
|
||||
输出
|
||||
```
|
||||
The-config-yml-file
|
||||
```
|
||||
Reference in New Issue
Block a user