diff --git a/bin/build-changelog.js b/bin/build-changelog.js index 5c6b6c0ac..cfdfed37a 100644 --- a/bin/build-changelog.js +++ b/bin/build-changelog.js @@ -18,7 +18,5 @@ content = content .replace(/\{\{/g, '{% raw %}{{{% endraw %}') const enFrontmatter = '---\ntitle: Changelog\nauto: true\n---\n\n' -const zhFrontmatter = '---\ntitle: 更新日志\nauto: true\n---\n\n' fs.writeFileSync(path.join(root, 'docs/source/tutorials/changelog.md'), enFrontmatter + content) -fs.writeFileSync(path.join(root, 'docs/source/zh-cn/tutorials/changelog.md'), zhFrontmatter + content) diff --git a/docs/_config.yml b/docs/_config.yml index d28a0fbed..b2055096c 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,10 +1,8 @@ title: LiquidJS -subtitle: "A simple, expressive and safe template engine." -description: "LiquidJS is a simple, expressive and safe Shopify / GitHub Pages compatible template engine in pure JavaScript." +subtitle: "A simple, expressive, and safe template engine for JavaScript." +description: "LiquidJS is a simple, expressive, and safe template engine for JavaScript, compatible with Shopify and GitHub Pages." author: Harttle -language: - - en - - zh-cn +language: en timezone: UTC url: https://liquidjs.com diff --git a/docs/source/_data/languages.yml b/docs/source/_data/languages.yml index e4b3acd42..6cf5ad282 100644 --- a/docs/source/_data/languages.yml +++ b/docs/source/_data/languages.yml @@ -1,3 +1 @@ en: English -zh-cn: - name: 简体中文 diff --git a/docs/source/_data/news.yml b/docs/source/_data/news.yml deleted file mode 100644 index 0e2236057..000000000 --- a/docs/source/_data/news.yml +++ /dev/null @@ -1,24 +0,0 @@ -- - url: https://opencollective.com/liquidjs/#section-contribute - date: '2020-02-26' - title: - zh-cn: '赞助人:第一个 backer 通过 Open Collective 贡献于 LiquidJS。' - en: 'Backers: the first backer contributed to LiquidJS via Open Collective.' -- - url: https://github.com/harttle/liquidjs/pull/202 - date: '2020-03-11' - title: - zh-cn: '内存优化:用更精细的手法重写了解析器,来避免临时字符串的生成,内存占用降低 57.7% 以上。' - en: 'Memory Optimization: a more elaborate parser reducing the memory footprint by 57.7%.' -- - url: https://github.com/harttle/liquidjs/pull/205 - date: '2020-03-15' - title: - zh-cn: '性能提升:引入 AST 并重新设计 Token 类型系统,使渲染性能平均提升 100.3%。' - en: 'Performance Boost: a simple AST to improve render performance by 100.3%.' -- - url: https://github.com/harttle/liquidjs/milestone/3?closed=1 - date: '2021-09-30' - title: - zh-cn: '流式渲染:4 倍渲染速度,并增加了对流式渲染的支持。' - en: 'Streamed Rendering: now render is 4x faster and support streamed rendering.' diff --git a/docs/source/index.pug b/docs/source/index.pug index 41ba55af0..64048edf7 100644 --- a/docs/source/index.pug +++ b/docs/source/index.pug @@ -7,23 +7,23 @@ ul#intro-feature-list .intro-feature .intro-feature-icon i.icon-shield - h3.intro-feature-title Safe Rendering - p.intro-feature-desc Liquid templates are highly readable and fault-tolerant thus suitable for designers and customers. Operators and expressions are parsed to AST and no #[code eval] or #[code new Function] are used. + h3.intro-feature-title Safe & Typed + p.intro-feature-desc Templates are readable and fault-tolerant, parsed to an AST with no #[code eval] or #[code new Function]. The whole repo is written in TypeScript strict mode, so types stay precise and docs accurate. li.intro-feature-wrap .intro-feature .intro-feature-icon i.icon-rocket h3.intro-feature-title Pure JavaScript - p.intro-feature-desc Written with pure JavaScript with no native bindings, available in both Node.js and browsers. All of the CMD, ESM and CJS bundles are available on CDN. + p.intro-feature-desc Written in pure JavaScript with no native bindings, running in both Node.js and the browser. The CMD, ESM and CJS bundles are all available on CDN. li.intro-feature-wrap .intro-feature .intro-feature-icon i.icon-shopify - h3.intro-feature-title Shopify Compatible - p.intro-feature-desc All filters and tags from Ruby #[a(href="https://github.com/shopify/liquid") shopify/liquid] are supported by LiquidJS. #[a(href="https://jekyllrb.com/") Jekyll sites], #[a(href="https://pages.github.com/") GitHub Pages] and #[a(href="https://themes.shopify.com/") Shopify templates] can be ported to Node.js without pain. + h3.intro-feature-title Shopify & Jekyll + p.intro-feature-desc All filters and tags from Ruby #[a(href="https://github.com/shopify/liquid") shopify/liquid] are supported, so #[a(href="https://themes.shopify.com/") Shopify templates] work out of the box — as do #[a(href="https://jekyllrb.com/") Jekyll] sites and #[a(href="https://pages.github.com/") GitHub Pages]. li.intro-feature-wrap .intro-feature .intro-feature-icon - i.icon-typescript - h3.intro-feature-title TypeScript Strict - p.intro-feature-desc The whole repo is re-written in TypeScript strict mode to ensure a smooth experience using this lib and the document is precise and always up to date. \ No newline at end of file + i.icon-network + h3.intro-feature-title Streaming + p.intro-feature-desc Render directly to a Node.js stream with #[code renderToNodeStream], emitting output as it's produced — for a faster time to first byte and low memory usage on large pages. \ No newline at end of file diff --git a/docs/source/zh-cn/filters/abs.md b/docs/source/zh-cn/filters/abs.md deleted file mode 100644 index 84483954a..000000000 --- a/docs/source/zh-cn/filters/abs.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: abs ---- - -{% since %}v1.9.1{% endsince %} - -返回数字的绝对值。 - -输入 -```liquid -{{ -17 | abs }} -``` - -输出 -```text -17 -``` - -输入 -```liquid -{{ 4 | abs }} -``` - -输出 -```text -4 -``` - -对于只包含数字的字符串也好使: - -输入 -```liquid -{{ "-19.86" | abs }} -``` - -输出 -```text -19.86 -``` diff --git a/docs/source/zh-cn/filters/append.md b/docs/source/zh-cn/filters/append.md deleted file mode 100644 index 7fa4cca10..000000000 --- a/docs/source/zh-cn/filters/append.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: append ---- - -{% since %}v1.9.1{% endsince %} - -连接两个字符串并返回结果。 - -输入 -```liquid -{{ "/my/fancy/url" | append: ".html" }} -``` - -输出 -```text -/my/fancy/url.html -``` - -也可以用于变量。 - -输入 -```liquid -{% assign filename = "/index.html" %} -{{ "website.com" | append: filename }} -``` - -输出 -```text - -website.com/index.html -``` diff --git a/docs/source/zh-cn/filters/array_to_sentence_string.md b/docs/source/zh-cn/filters/array_to_sentence_string.md deleted file mode 100644 index 3e1d8b537..000000000 --- a/docs/source/zh-cn/filters/array_to_sentence_string.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: array_to_sentence_string ---- - -{% since %}v10.13.0{% endsince %} - -把数组转化为句子,用于做标签列表。有一个可选的连接词参数。 - -输入 -```liquid -{{ "foo,bar,baz" | split: "," | array_to_sentence_string }} -``` - -输出 -```text -foo, bar, and baz -``` - -输入 -```liquid -{{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }} -``` - -输出 -```text -foo, bar, or baz -``` diff --git a/docs/source/zh-cn/filters/at_least.md b/docs/source/zh-cn/filters/at_least.md deleted file mode 100644 index 0a1f2e85e..000000000 --- a/docs/source/zh-cn/filters/at_least.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: at_least ---- - -{% since %}v8.4.0{% endsince %} - -限制数字到某个最小值。 - -输入 -```liquid -{{ 4 | at_least: 5 }} -``` - -输出 -```text -5 -``` - -输入 -```liquid -{{ 4 | at_least: 3 }} -``` - -输出 -```text -4 -``` diff --git a/docs/source/zh-cn/filters/at_most.md b/docs/source/zh-cn/filters/at_most.md deleted file mode 100644 index 7410c1d06..000000000 --- a/docs/source/zh-cn/filters/at_most.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: at_most ---- - -{% since %}v8.4.0{% endsince %} - -限制数字到某个最大值。 - -输入 -```liquid -{{ 4 | at_most: 5 }} -``` - -输出 -```text -4 -``` - -输入 -```liquid -{{ 4 | at_most: 3 }} -``` - -输出 -```text -3 -``` diff --git a/docs/source/zh-cn/filters/capitalize.md b/docs/source/zh-cn/filters/capitalize.md deleted file mode 100644 index 5e7562931..000000000 --- a/docs/source/zh-cn/filters/capitalize.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: capitalize ---- - -{% since %}v1.9.1{% endsince %} - -把字符串首字母改为大写。 - -输入 -```liquid -{{ "title" | capitalize }} -``` - -输出 -```text -Title -``` - -`capitalize` 只会大写首字母,因此后续单词的不会受影响: - - Input -```liquid -{{ "my great title" | capitalize }} -``` - -输出 -```text -My great title -``` diff --git a/docs/source/zh-cn/filters/ceil.md b/docs/source/zh-cn/filters/ceil.md deleted file mode 100644 index 5217227d0..000000000 --- a/docs/source/zh-cn/filters/ceil.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: ceil ---- - -{% since %}v1.9.1{% endsince %} - -向上取整,取整前 LiquidJS 会首先把输入转换为数字。 - -输入 -```liquid -{{ 1.2 | ceil }} -``` - -输出 -```text -2 -``` - -输入 -```liquid -{{ 2.0 | ceil }} -``` - -输出 -```text -2 -``` - -输入 -```liquid -{{ 183.357 | ceil }} -``` - -输出 -```text -184 -``` - -下面的例子中输入是字符串: - -输入 -```liquid -{{ "3.5" | ceil }} -``` - -输出 -```text -4 -``` diff --git a/docs/source/zh-cn/filters/cgi_escape.md b/docs/source/zh-cn/filters/cgi_escape.md deleted file mode 100644 index 159dd5bdb..000000000 --- a/docs/source/zh-cn/filters/cgi_escape.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: cgi_escape ---- - -{% since %}v10.13.0{% endsince %} - -把字符串 CGI 转义,用于 URL。用对应的 `%XX` 替换特殊字符,空格会被转义为 `+` 号。 - -输入 -```liquid -{{ "foo, bar; baz?" | cgi_escape }} -``` - -输出 -```text -foo%2C+bar%3B+baz%3F -``` diff --git a/docs/source/zh-cn/filters/compact.md b/docs/source/zh-cn/filters/compact.md deleted file mode 100644 index 6760b62a4..000000000 --- a/docs/source/zh-cn/filters/compact.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: compact ---- - -{% since %}v9.22.0{% endsince %} - -从数组里移除任何 `null` 和 `undefined` 值。 - -假设 `site.pages` 是网页列表,有些网页包含 `category` 属性用来标明类别。如果把它们 `map` 到数组里,那么对于没有 `category` 属性的元素就会是 `undefined`。 - -输入 -```liquid -{% assign site_categories = site.pages | map: "category" %} - -{% for category in site_categories %} -- {{ category }} -{% endfor %} -``` - -输出 -```text -- business -- celebrities -- -- lifestyle -- sports -- -- technology -``` - -使用 `compact` 创建 `site_categories` 数组,可以移除所有 `null` 和 `undefined` 值。 - -输入 -```liquid -{% assign site_categories = site.pages | map: "category" | compact %} - -{% for category in site_categories %} -- {{ category }} -{% endfor %} -``` - -输出 -```text -- business -- celebrities -- lifestyle -- sports -- technology -``` diff --git a/docs/source/zh-cn/filters/concat.md b/docs/source/zh-cn/filters/concat.md deleted file mode 100644 index 376375039..000000000 --- a/docs/source/zh-cn/filters/concat.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: concat ---- - -{% since %}v2.0.0{% endsince %} - -连接多个数组,返回的数组包含所有传入数组的元素。 - -输入 -```liquid -{% assign fruits = "apples, oranges, peaches" | split: ", " %} -{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %} - -{% assign everything = fruits | concat: vegetables %} - -{% for item in everything %} -- {{ item }} -{% endfor %} -``` - -输出 -```text -- apples -- oranges -- peaches -- carrots -- turnips -- potatoes -``` - -可以链式地使用 `concat` 过滤器来连接多个数组: - -输入 -```liquid -{% assign furniture = "chairs, tables, shelves" | split: ", " %} - -{% assign everything = fruits | concat: vegetables | concat: furniture %} - -{% for item in everything %} -- {{ item }} -{% endfor %} -``` - -输出 -```text -- apples -- oranges -- peaches -- carrots -- turnips -- potatoes -- chairs -- tables -- shelves -``` diff --git a/docs/source/zh-cn/filters/date.md b/docs/source/zh-cn/filters/date.md deleted file mode 100644 index be922a665..000000000 --- a/docs/source/zh-cn/filters/date.md +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: date ---- - -{% since %}v1.9.1{% endsince %} - -把时间戳转换为字符串。LiquidJS 尝试跟 Shopify/Liquid 保持一致,它用的是 Ruby 核心的 [Time#strftime(string)](http://www.ruby-doc.org/core/Time.html#method-i-strftime)。此外 LiquidJS 会先通过 [new Date()][newDate] 尝试把输入转换为 Date 对象。 - -但 LiquidJS 支持的格式与 [Ruby 的 flag](https://ruby-doc.org/core/strftime_formatting_rdoc.html) 有些不同: - * `%Z`(自 v10.11.1 起支持)只有在传入了时区时才起作用(可以通过 `LiquidOption` 传入,也可以在创建日期时单独传入,见下文)。如果传入的时区是个数字,那么它的表现将会与 `%z` 相同。如果没有传入时区,将会返回 [运行时默认时区](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#timezone)。 - * LiquidJS 提供额外的 `%q` 用来处理序数:`{{ '2023/02/02' | date: '%d%q of %b'}}` => `02nd of Feb` -* 日期字面量会通过 [new Date()][jsDate] 转化为 `Date` 对象,这意味着字面量默认使用运行时默认时区。 -* 格式字参数是可选的: - * 如果不传,默认为 `%A, %B %-e, %Y at %-l:%M %P %z`。 - * 上述默认值可以通过 [`dateFormat`](/api/interfaces/LiquidOptions.html#dateFormat) 参数覆盖。 - -输入 -```liquid -{{ article.published_at | date: "%a, %b %d, %y" }} -``` - -输出 -```text -Fri, Jul 17, 15 -``` - -{% note info 时区 %} -日期在输出时会转换为当地时区,设置 `timezoneOffset` LiquidJS 参数可以指定一个不同的时区。或者设置 `preserveTimezones` 为 `true` 来保持字面量时间戳的时区,数据中的日期对象不受此参数的影响。 -{% endnote %} - -你也可以在使用 `date` 时再设置时区: - -输入 -```liquid -{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360}} // 等价于设置 `options.timezoneOffset` to `360`. -{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", "Asia/Colombo" }} -``` - -输出 -```liquid -1990-12-31T17:00:00 -1991-01-01T04:30:00 -``` - - -输入 -```liquid -{{ article.published_at | date: "%Y" }} -``` - -输出 -```text -2015 -``` - -输入也可以是符合 JavaScript `Date` 格式的字符串:: - -输入 -```liquid -{{ "March 14, 2016" | date: "%b %d, %y" }} -``` - -输出 -```text -Mar 14, 16 -``` - -{% note info 时间戳字符串 %} -LiquidJS 使用 JavaScript [Date][newDate] 来解析输入字符串,意味着支持 [IETF-compliant RFC 2822 时间戳](https://datatracker.ietf.org/doc/html/rfc2822#page-14) 和 [特定版本的 ISO8601](https://www.ecma-international.org/ecma-262/11.0/#sec-date.parse)。 -{% endnote %} - -可以用特殊值 `"now"`(或`"today"`)来获取当前时间: - -输入 -```liquid -This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}. -``` - -输出 -```text -This page was last updated at 2020-03-25 15:57. -``` - -{% note info 当前时间 %}注意得到的当前时间是模板渲染时的时间,如果你在用静态站点生成器或者模板有被缓存这一时间可能与用户看到的时间不同。{% endnote %} - -[newDate]: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date diff --git a/docs/source/zh-cn/filters/date_to_long_string.md b/docs/source/zh-cn/filters/date_to_long_string.md deleted file mode 100644 index 0cb54dc74..000000000 --- a/docs/source/zh-cn/filters/date_to_long_string.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: date_to_long_string ---- -{% since %}v10.13.0{% endsince %} - -把日期转换为长格式(只支持 US/UK 两种),与 Jekyll 的 `date_to_long_string` 过滤器一样。 - -输入 -```liquid -{{ site.time | date_to_long_string }} -``` - -输出 -```text -07 November 2008 -``` - -输入 -```liquid -{{ site.time | date_to_long_string: "ordinal" }} -``` - -输出 -```text -7th November 2008 -``` - - -注意 JavaScript `Date` 没有时区信息,详情请参考 [date][date] 过滤器。 - -[date]: ./date.html diff --git a/docs/source/zh-cn/filters/date_to_rfc822.md b/docs/source/zh-cn/filters/date_to_rfc822.md deleted file mode 100644 index fd704397e..000000000 --- a/docs/source/zh-cn/filters/date_to_rfc822.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: date_to_rfc822 ---- -{% since %}v10.13.0{% endsince %} - -把日期转换为 RFC-822 格式用于 RSS feed,与 Jekyll 的 `date_to_rfc822` 过滤器一样。 - -输入 -```liquid -{{ site.time | date_to_rfc822 }} -``` - -输入 -```text -Mon, 07 Nov 2008 13:07:54 -0800 -``` - -注意 JavaScript `Date` 没有时区信息,详情请参考 [date][date] 过滤器。 - -[date]: ./date.html diff --git a/docs/source/zh-cn/filters/date_to_string.md b/docs/source/zh-cn/filters/date_to_string.md deleted file mode 100644 index 569454bf4..000000000 --- a/docs/source/zh-cn/filters/date_to_string.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: date_to_string ---- -{% since %}v10.13.0{% endsince %} - -把日期转换为短格式(只支持 US/UK 两种),与 Jekyll 的 `date_to_string` 过滤器一样。 - -输入 -```liquid -{{ site.time | date_to_string }} -``` - -输出 -```text -07 Nov 2008 -``` - -输入 -```liquid -{{ site.time | date_to_string: "ordinal", "US" }} -``` - -输出 -```text -Nov 7th, 2008 -``` - -注意 JavaScript `Date` 没有时区信息,详情请参考 [date][date] 过滤器。 - -[date]: ./date.html diff --git a/docs/source/zh-cn/filters/date_to_xmlschema.md b/docs/source/zh-cn/filters/date_to_xmlschema.md deleted file mode 100644 index e1051cdc3..000000000 --- a/docs/source/zh-cn/filters/date_to_xmlschema.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: date_to_xmlschema ---- -{% since %}v10.13.0{% endsince %} - -把日期转换为 XML Schema (ISO 8601) 格式,与 Jekyll 的 `date_to_xmlschema` 过滤器一样。 - -输入 -```liquid -{{ site.time | date_to_xmlschema }} -``` - -输出 -```text -2008-11-07T13:07:54-08:00 -``` - -注意 JavaScript `Date` 没有时区信息,详情请参考 [date][date] 过滤器。 - -[date]: ./date.html diff --git a/docs/source/zh-cn/filters/default.md b/docs/source/zh-cn/filters/default.md deleted file mode 100644 index ad16cf45b..000000000 --- a/docs/source/zh-cn/filters/default.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: default ---- - -{% since %}v1.9.1{% endsince %} - -在值不存在时给一个默认值,如果左侧是 [falsy][falsy] 或空(`string` 或 `Array`)就会使用这个默认值。下面的例子中 `product_price` 没有定义,因此使用了默认值。 - -输入 -```liquid -{{ product_price | default: 2.99 }} -``` - -输出 -```text -2.99 -``` - -下面的例子中定义了 `product_price` 所以没有使用默认值。 - -输入 -```liquid -{% assign product_price = 4.99 %} -{{ product_price | default: 2.99 }} -``` - -输出 -```text -4.99 -``` - -下面例子中 `product_price` 为空,所以使用了默认值。 - -输入 -```liquid -{% assign product_price = "" %} -{{ product_price | default: 2.99 }} -``` - -输出 -```text -2.99 -``` - -## 允许 `false` - -{% since %}v9.32.0{% endsince %} - -为了允许让 `false` 直接输出而不是用默认值,可以用 `allow_false` 参数。 - -输入 - -```liquid -{% assign display_price = false %} -{{ display_price | default: true, allow_false: true }} -``` - -输出 - -```text -false -``` - -[falsy]: ../tutorials/truthy-and-falsy.html diff --git a/docs/source/zh-cn/filters/divided_by.md b/docs/source/zh-cn/filters/divided_by.md deleted file mode 100644 index 2eb2d4264..000000000 --- a/docs/source/zh-cn/filters/divided_by.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: divided_by ---- - -{% since %}v1.9.1{% endsince %} - -两数相除返回商,返回结果数字在 JavaScript 中 `.toString()` 得到的字符串。 - -输入 -```liquid -{{ 16 | divided_by: 4 }} -``` - -输出 -```text -4 -``` - -输入 -```liquid -{{ 5 | divided_by: 3 }} -``` - -输出 -```text -1.6666666666666667 -``` - -在 JavaScript 里数字没有浮点和整数的区分,它们的类型都是 `number`: - -```javascript -// always true -5.0 === 5 -``` - -因此如果需要做整数运算,需要传入额外的 `integerArithmetic` 参数: - -Input -```liquid -{{ 5 | divided_by: 3, true }} -``` - -Output -```text -1 -``` - -[floor]: ./floor.html diff --git a/docs/source/zh-cn/filters/downcase.md b/docs/source/zh-cn/filters/downcase.md deleted file mode 100644 index 4fb4cdbb9..000000000 --- a/docs/source/zh-cn/filters/downcase.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: downcase ---- - -{% since %}v1.9.1{% endsince %} - -字符串中每个字符都转为小写,对已经是小写的字符没有影响。 - -输入 -```liquid -{{ "Parker Moore" | downcase }} -``` - -输出 -```text -parker moore -``` - -输入 -```liquid -{{ "apple" | downcase }} -``` - -输出 -```text -apple -``` diff --git a/docs/source/zh-cn/filters/escape.md b/docs/source/zh-cn/filters/escape.md deleted file mode 100644 index 02e5c781e..000000000 --- a/docs/source/zh-cn/filters/escape.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: escape ---- - -{% since %}v1.9.1{% endsince %} - -把字符串中的 HTML 特殊字符转义,对不需要转义的字符串不会产生影响。 - -输入 -```liquid -{{ "Have you read 'James & the Giant Peach'?" | escape }} -``` - -输出 -
-{{"Have you read 'James & the Giant Peach'?" | escape}}
-
-
-输入
-```liquid
-{{ "Tetsuro Takara" | escape }}
-```
-
-输出
-```text
-Tetsuro Takara
-```
diff --git a/docs/source/zh-cn/filters/escape_once.md b/docs/source/zh-cn/filters/escape_once.md
deleted file mode 100644
index 14a2f2e8f..000000000
--- a/docs/source/zh-cn/filters/escape_once.md
+++ /dev/null
@@ -1,27 +0,0 @@
----
-title: escape_once
----
-
-{% since %}v1.9.1{% endsince %}
-
-把字符串中的特殊字符转义得到可用在 URL 里的字符串,对已经转义过的字符串和不需要转义的字符串不会产生影响。
-
-输入
-```liquid
-{{ "1 < 2 & 3" | escape_once }}
-```
-
-输出
-
-{{"1 < 2 & 3" | escape}}
-
-
-输入
-
-{{ "{{"1 < 2 & 3" | escape}}" | escape_once }}
-
-
-输出
-
-{{"1 < 2 & 3" | escape}}
-
diff --git a/docs/source/zh-cn/filters/find.md b/docs/source/zh-cn/filters/find.md
deleted file mode 100644
index baebe69b8..000000000
--- a/docs/source/zh-cn/filters/find.md
+++ /dev/null
@@ -1,25 +0,0 @@
----
-title: find
----
-
-{% since %}v10.11.0{% endsince %}
-
-在数组中找到给定的属性为给定的值的第一个元素并返回;如果没有这样的元素则返回 `nil`。对于 `members` 数组:
-
-```javascript
-const members = [
- { graduation_year: 2013, name: 'Jay' },
- { graduation_year: 2014, name: 'John' },
- { graduation_year: 2014, name: 'Jack' }
-]
-```
-
-输入
-```liquid
-{{ members | find: "graduation_year", 2014 | json }}
-```
-
-输出
-```text
-{"graduation_year":2014,"name":"John"}
-```
diff --git a/docs/source/zh-cn/filters/find_exp.md b/docs/source/zh-cn/filters/find_exp.md
deleted file mode 100644
index 60a55c70e..000000000
--- a/docs/source/zh-cn/filters/find_exp.md
+++ /dev/null
@@ -1,25 +0,0 @@
----
-title: find_exp
----
-
-{% since %}v10.11.0{% endsince %}
-
-找到数组中给定的表达式值为 `true` 的第一个元素,如果没有这样的元素则返回 `nil`。对于下面的 `members` 数组:
-
-```javascript
-const members = [
- { graduation_year: 2013, name: 'Jay' },
- { graduation_year: 2014, name: 'John' },
- { graduation_year: 2014, name: 'Jack' }
-]
-```
-
-输入
-```liquid
-{{ members | find_exp: "item", "item.graduation_year == 2014" | json }}
-```
-
-输出
-```text
-{"graduation_year":2014,"name":"John"}
-```
diff --git a/docs/source/zh-cn/filters/first.md b/docs/source/zh-cn/filters/first.md
deleted file mode 100644
index fd98ba7ea..000000000
--- a/docs/source/zh-cn/filters/first.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-title: first
----
-
-{% since %}v1.9.1{% endsince %}
-
-返回数组的第一个元素。
-
-输入
-```liquid
-{{ "Ground control to Major Tom." | split: " " | first }}
-```
-
-输出
-```text
-Ground
-```
-
-输入
-```liquid
-{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
-{{ my_array.first }}
-```
-
-输出
-```text
-
-zebra
-```
-
-需要在标签中使用的时候,可以用点来计算 `first`:
-
-```liquid
-{% if my_array.first == "zebra" %}
- Here comes a zebra!
-{% endif %}
-```
diff --git a/docs/source/zh-cn/filters/floor.md b/docs/source/zh-cn/filters/floor.md
deleted file mode 100644
index 3401b52a6..000000000
--- a/docs/source/zh-cn/filters/floor.md
+++ /dev/null
@@ -1,49 +0,0 @@
----
-title: floor
----
-
-{% since %}v1.9.1{% endsince %}
-
-数字下取整,LiquidJS 会尝试把输入转换为数字再做下取整操作。
-
-输入
-```liquid
-{{ 1.2 | floor }}
-```
-
-输出
-```text
-1
-```
-
-输入
-```liquid
-{{ 2.0 | floor }}
-```
-
-输出
-```text
-2
-```
-
-输入
-```liquid
-{{ 183.357 | floor }}
-```
-
-输出
-```text
-183
-```
-
-下面的例子中输入是个数字:
-
-输入
-```liquid
-{{ "3.5" | floor }}
-```
-
-输出
-```text
-3
-```
diff --git a/docs/source/zh-cn/filters/group_by.md b/docs/source/zh-cn/filters/group_by.md
deleted file mode 100644
index 2ce1b08ac..000000000
--- a/docs/source/zh-cn/filters/group_by.md
+++ /dev/null
@@ -1,48 +0,0 @@
----
-title: group_by
----
-
-{% since %}v10.11.0{% endsince %}
-
-把数组元素按照给定的属性的值分组。对于 `members` 数组:
-
-```javascript
-const members = [
- { graduation_year: 2003, name: 'Jay' },
- { graduation_year: 2003, name: 'John' },
- { graduation_year: 2004, name: 'Jack' }
-]
-```
-
-输入
-```liquid
-{{ members | group_by: "graduation_year" | json: 2 }}
-```
-
-输出
-```text
-[
- {
- "name": 2003,
- "items": [
- {
- "graduation_year": 2003,
- "name": "Jay"
- },
- {
- "graduation_year": 2003,
- "name": "John"
- }
- ]
- },
- {
- "name": 2004,
- "items": [
- {
- "graduation_year": 2004,
- "name": "Jack"
- }
- ]
- }
-]
-```
diff --git a/docs/source/zh-cn/filters/group_by_exp.md b/docs/source/zh-cn/filters/group_by_exp.md
deleted file mode 100644
index a68aaaee6..000000000
--- a/docs/source/zh-cn/filters/group_by_exp.md
+++ /dev/null
@@ -1,48 +0,0 @@
----
-title: group_by_exp
----
-
-{% since %}v10.11.0{% endsince %}
-
-把数组元素按照给定的 Liquid 表达式的值分组。对于 `members` 数组:
-
-```javascript
-const members = [
- { graduation_year: 2013, name: 'Jay' },
- { graduation_year: 2014, name: 'John' },
- { graduation_year: 2009, name: 'Jack' }
-]
-```
-
-输入
-```liquid
-{{ members | group_by_exp: "item", "item.graduation_year | truncate: 3, ''" | json: 2 }}
-```
-
-输出
-```text
-[
- {
- "name": "201",
- "items": [
- {
- "graduation_year": 2013,
- "name": "Jay"
- },
- {
- "graduation_year": 2014,
- "name": "John"
- }
- ]
- },
- {
- "name": "200",
- "items": [
- {
- "graduation_year": 2009,
- "name": "Jack"
- }
- ]
- }
-]
-```
diff --git a/docs/source/zh-cn/filters/inspect.md b/docs/source/zh-cn/filters/inspect.md
deleted file mode 100644
index e59dff12f..000000000
--- a/docs/source/zh-cn/filters/inspect.md
+++ /dev/null
@@ -1,42 +0,0 @@
----
-title: inspect
----
-
-{% since %}v10.13.0{% endsince %}
-
-类似于 `json`,但可以处理循环引用的情况。例如对于上下文:
-
-```
-const foo = {
- bar: 'BAR'
-}
-foo.foo = foo
-const scope = { foo }
-```
-
-输入
-```liquid
-{% foo | inspect %}
-```
-
-输出
-```text
-{"bar":"BAR","foo":"[Circular]"}
-```
-
-## 格式化
-
-可以指定一个 `space` 参数来缩进长度。
-
-输入
-```liquid
-{{ foo | inspect: 4 }}
-```
-
-输出
-```text
-{
- "bar": "BAR",
- "foo": "[Circular]"
-}
-```
diff --git a/docs/source/zh-cn/filters/join.md b/docs/source/zh-cn/filters/join.md
deleted file mode 100644
index cfda7ffb8..000000000
--- a/docs/source/zh-cn/filters/join.md
+++ /dev/null
@@ -1,19 +0,0 @@
----
-title: join
----
-
-{% since %}v1.9.1{% endsince %}
-
-把数组中的元素连接成为一个字符串,以传入的参数作为分隔符。
-
-输入
-```liquid
-{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
-{{ beatles | join: " and " }}
-```
-
-输出
-```text
-
-John and Paul and George and Ringo
-```
diff --git a/docs/source/zh-cn/filters/json.md b/docs/source/zh-cn/filters/json.md
deleted file mode 100644
index 3fc6e71f7..000000000
--- a/docs/source/zh-cn/filters/json.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-title: json
----
-
-{% since %}v9.10.0{% endsince %}
-
-通过 `JSON.stringify()` 把值转换为字符串,多用于调试用途。
-
-输入
-```liquid
-{% assign arr = "foo bar coo" | split: " " %}
-{{ arr | json }}
-```
-
-输出
-```text
-["foo","bar","coo"]
-```
-
-## 格式化
-
-{% since %}v10.11.0{% endsince %}
-
-可以指定一个 `space` 参数来格式化 JSON。
-
-输入
-```liquid
-{% assign arr = "foo bar coo" | split: " " %}
-{{ arr | json: 4 }}
-```
-
-输出
-```text
-[
- "foo",
- "bar",
- "coo"
-]
-```
diff --git a/docs/source/zh-cn/filters/jsonify.md b/docs/source/zh-cn/filters/jsonify.md
deleted file mode 100644
index 55ff26ed6..000000000
--- a/docs/source/zh-cn/filters/jsonify.md
+++ /dev/null
@@ -1,9 +0,0 @@
----
-title: jsonify
----
-
-{% since %}v10.13.0{% endsince %}
-
-见 [json][json]。
-
-[json]: ./json.html
diff --git a/docs/source/zh-cn/filters/last.md b/docs/source/zh-cn/filters/last.md
deleted file mode 100644
index 971acb5a2..000000000
--- a/docs/source/zh-cn/filters/last.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-title: last
----
-
-{% since %}v1.9.1{% endsince %}
-
-返回数组的最后一个元素。
-
-输入
-```liquid
-{{ "Ground control to Major Tom." | split: " " | last }}
-```
-
-输出
-```text
-Tom.
-```
-
-输入
-```liquid
-{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
-{{ my_array.last }}
-```
-
-输出
-```text
-
-tiger
-```
-
-需要在标签中使用的时候,可以用点来计算 `last`:
-
-```liquid
-{% if my_array.last == "tiger" %}
- There goes a tiger!
-{% endif %}
-```
diff --git a/docs/source/zh-cn/filters/lstrip.md b/docs/source/zh-cn/filters/lstrip.md
deleted file mode 100644
index f7e07a85e..000000000
--- a/docs/source/zh-cn/filters/lstrip.md
+++ /dev/null
@@ -1,17 +0,0 @@
----
-title: lstrip
----
-
-{% since %}v1.9.1{% endsince %}
-
-移除字符串左侧的空白字符(制表符、空格、换行),不影响词之间的空格。
-
-输入
-```liquid
-BEGIN{{ " So much room for activities! " | lstrip }}END
-```
-
-输出
-```text
-BEGINSo much room for activities! END
-```
diff --git a/docs/source/zh-cn/filters/map.md b/docs/source/zh-cn/filters/map.md
deleted file mode 100644
index 5686e8c8a..000000000
--- a/docs/source/zh-cn/filters/map.md
+++ /dev/null
@@ -1,27 +0,0 @@
----
-title: map
----
-
-{% since %}v1.9.1{% endsince %}
-
-按照属性名提取对象的属性形成另一个数组并返回。
-
-下面的例子中假设 `site.pages` 包含了站点的所有网页元信息。使用 `assign` 加 `map` 过滤器创建了一个 `site.pages` 中所有对象的 `category` 属性的值构成的数组。
-
-输入
-```liquid
-{% assign all_categories = site.pages | map: "category" %}
-
-{% for item in all_categories %}
-- {{ item }}
-{% endfor %}
-```
-
-输出
-```text
-- business
-- celebrities
-- lifestyle
-- sports
-- technology
-```
diff --git a/docs/source/zh-cn/filters/minus.md b/docs/source/zh-cn/filters/minus.md
deleted file mode 100644
index 8c7c45a04..000000000
--- a/docs/source/zh-cn/filters/minus.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-title: minus
----
-
-{% since %}v1.9.1{% endsince %}
-
-两数相减。
-
-输入
-```liquid
-{{ 4 | minus: 2 }}
-```
-
-输出
-```text
-2
-```
-
-输入
-```liquid
-{{ 16 | minus: 4 }}
-```
-
-输出
-```text
-12
-```
-
-输入
-```liquid
-{{ 183.357 | minus: 12 }}
-```
-
-输出
-```text
-171.357
-```
diff --git a/docs/source/zh-cn/filters/modulo.md b/docs/source/zh-cn/filters/modulo.md
deleted file mode 100644
index 037502bc4..000000000
--- a/docs/source/zh-cn/filters/modulo.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-title: modulo
----
-
-{% since %}v1.9.1{% endsince %}
-
-返回两数相除的余数。
-
-输入
-```liquid
-{{ 3 | modulo: 2 }}
-```
-
-输出
-```text
-1
-```
-
-输入
-```liquid
-{{ 24 | modulo: 7 }}
-```
-
-输出
-```text
-3
-```
-
-输入
-```liquid
-{{ 183.357 | modulo: 12 }}
-```
-
-输出
-```text
-3.3569999999999993
-```
diff --git a/docs/source/zh-cn/filters/newline_to_br.md b/docs/source/zh-cn/filters/newline_to_br.md
deleted file mode 100644
index 8c60e7725..000000000
--- a/docs/source/zh-cn/filters/newline_to_br.md
+++ /dev/null
@@ -1,23 +0,0 @@
----
-title: newline_to_br
----
-
-{% since %}v1.9.1{% endsince %}
-
-把字符串里的所有换行符(`\n`)替换为 HTML 换行(`| - Cool Shirt - | -- Alien Poster - | -- Batman Poster - | -- Bullseye Shirt - | -- Another Classic Vinyl - | -- Awesome Jeans - | -
| - Cool Shirt - | -- Alien Poster - | -
| - Batman Poster - | -- Bullseye Shirt - | -
| - Another Classic Vinyl - | -- Awesome Jeans - | -
toLiquid() 和 valueOf() 的区别 %}
-valueOf() 通常用来定义当前变量如何渲染,toLiquid() 通常用来把一个对象转换为 Drop 或另一个提供给模板的 scope。valueOf() 是 Drop 才有的方法;而 toLiquid() 可以用在任何 scope 对象上。valueOf() 是在自己即将被渲染时,用来替代自己;而 toLiquid() 在即将读取它的属性时才会被调用。empty 的实现 %}
-对于数组和字符串,LiquidJS 检查它们的 `.length` 属性。对于对象,LiquidJS 调用 `Object.keys()` 来检查它是否有键。
-{% endnote %}
-
-### nil
-
-`nil` Drop 用于检查变量是否未定义或定义为 `null` 或 `undefined`,本质上等同于 JavaScript 的 `== null` 检查。
-
-```liquid
-{% if notexist == nil %}
- 空变量
-{% endif %}
-```
-
-### 其他 Drop
-
-仍然有一些特定标签的 Drop,例如 `forloop`、`tablerowloop`、`block`,这些在各自的标签文档中有详细介绍。
-
-[shopify-drops]: https://github.com/Shopify/liquid/wiki/Introduction-to-Drops
diff --git a/docs/source/zh-cn/tutorials/escaping.md b/docs/source/zh-cn/tutorials/escaping.md
deleted file mode 100644
index 042bcc34e..000000000
--- a/docs/source/zh-cn/tutorials/escaping.md
+++ /dev/null
@@ -1,76 +0,0 @@
----
-title: 转义
----
-
-LiquidJS 种转义有两种含义:
-
-1. 输出语言的转义,即 HTML 转义。用来让输出的变量不包含 HTML 特殊字符,不影响 HTML 的结构,也就是输出 HTML 安全的字符串。
-2. 语言自己的转义,即 Liquid 转义。用来输出包含对于 Liquid 语言来说是特殊字符的字符串,比如你在使用 Liquid 模板语言来编写一篇介绍 Liquid 语法的文章时就会需要 Liquid 转义。
-
-## HTML 转义
-
-默认情况下输出是不转义的,但你可以用 [escape][escape] 过滤器来做 HTML 转义:
-
-输入
-```liquid
-{{ "1 < 2" | escape }}
-```
-
-输出
-```text
-1 < 2
-```
-
-LiquidJS 也提供了其他过滤器来支持不同的转义需求:[escape_once][escape_once], [newline_to_br][newline_to_br], [strip_html][strip_html]。
-
-当输出的变量不被信任时,可以把 [outputEscape][outputEscape] 参数设置为 `"escape"` 来启用默认 HTML 转义。这种情况下,如果你需要某个输出不被转义,则需要使用 [raw][raw] 过滤器:
-
-输入
-```liquid
-{{ "1 < 2" }}
-{{ "" | raw }}
-```
-
-输出
-```text
-1 < 2
-
-```
-
-## Liquid 转义
-
-为了输出 Liquid 的特殊字符比如 `{{` 和 `{%`,你需要 [raw][raw] 标签。
-
-输入
-```liquid
-{% raw %}
- In LiquidJS, {{ this | escape }} will be HTML-escaped, but
- {{{ that }}} will not.
-{% endraw %}
-```
-
-输出
-```text
-In LiquidJS, {{ this | escape }} will be HTML-escaped, but
-{{{ that }}} will not.
-```
-
-Within strings literals in LiquidJS template, `\` can be used to escape special characters in string syntax. For example:
-
-输入
-```liquid
-{{ "\"" }}
-```
-
-输出
-```liquid
-"
-```
-
-[outputEscape]: ./options.html#outputEscape
-[escape]: ../filters/escape.html
-[raw]: ../filters/raw.html
-[escape_once]: ../filters/escape.html
-[strip_html]: ../filters/strip_html.html
-[newline_to_br]: ../filters/newline_to_br.html
-[raw]: ../tags/raw.html
diff --git a/docs/source/zh-cn/tutorials/intro-to-liquid.md b/docs/source/zh-cn/tutorials/intro-to-liquid.md
deleted file mode 100644
index 2e9586561..000000000
--- a/docs/source/zh-cn/tutorials/intro-to-liquid.md
+++ /dev/null
@@ -1,60 +0,0 @@
----
-title: Liquid 模板语言
-description: Liquid 模板语言的介绍,和一些示例代码
----
-
-LiquidJS 是一个简单的、安全的、兼容 Shopify 的、纯 JavaScript 编写的模板引擎。这个项目的目的是为 JavaScript 社区提供一个 Liquid 模板引擎的实现。Liquid 最初用 Ruby 实现并用于 Github Pages, Jekyll 和 Shopify,参考 [和 Shopify/liquid 的区别][diff]。
-
-LiquidJS 语法相对简单。LiquidJS 中有两种标记:
-
-- **标签**。标签由标签名和参数构成,由 `{%raw%}{%{%endraw%}` 和 `%}` 包裹。
-- **输出**。输出由一个值和一组可选的过滤器构成,由 `{%raw%}{{{%endraw%}` 和 `}}` 包裹。
-
-{% note info 在线示例 %}
-在进一步了解细节之前,这里有一个在线示例:true 以兼容于 shopify/liquid,但如果你在使用 eleventy 它会设置默认值 false (参考 Quoted Include Paths)以兼容于 Jekyll。{% endnote %}
-
-## Jekyll include
-
-{% since %}v9.33.0{% endsince %}
-
-[jekyllInclude][jekyllInclude] 用来启用 Jekyll-like include 语法。默认为 `false`,当设置为 `true` 时:
-
-- 默认启用静态文件名:`dynamicPartials` 的默认值变为 `false`(而非 `true`)。但你也可以把它设置回 `true`。
-- 参数的键和值之间由 `=` 分隔(本来是 `:`)。
-- 参数放到了 `include` 变量下,而非当前作用域。
-
-例如下面的模板中,`name.html` 没有带引号,`header` 和 `"HEADER"` 以 `=` 分隔,`header` 参数通过 `include.header` 来引用。更多详情请参考 [include][include]。
-
-```liquid
-// entry template
-{% include article.html header="HEADER" content="CONTENT" %}
-
-// article.html
-extname 默认值为 `.liquid`。要禁用它需要明确设置为 extname: ''。详情参考 #41。
-{% endnote %}
-
-## fs
-
-**fs** 用来自定义文件系统实现,详情请参考 [Abstract File System][abstract-fs]。
-
-## globals
-
-**globals** 用来定义对所有模板可见的全局变量。包括 [render tag][render] 引入的子模板,见 [3185][185]。
-
-## jsTruthy
-
-**jsTruthy** 用来使用 Javascript 的真值判断,默认为 `false` 使用 Shopify 方式。
-
-例如,空字符串在 JavaScript 中为假(`jsTruthy` 为 `true` 时),在 Shopify 真值表中为真。
-
-## outputEscape
-
-[outputEscape][outputEscape] 用来自动转义输出。它的值可以是 `"escape"`、`"json"` 或 `(val: unknown) => string`,默认为 `undefined`。
-
-- 如果被输出的变量不被信任,可以设置 `outputEscape: "escape"` 来自动把它们 HTML 转义。如果要直接输出则需要使用 [raw][raw] 过滤器。
-- 如果你在用 LiquidJS 来生产 JSON 文件,可以设置为 `"json"`。
-- `outputEscape` 甚至可以是函数,你可以借此控制整个 LiquidJS 的变量输出。注意函数的输入不一定是字符串,因为过滤器的返回值可以不是字符串,你的函数将会接到这个值。
-
-## 时间日期和时区
-
-**timezoneOffset** 用来指定一个和你当地时区不同的时区,所有日期和时间输出时都转换到这个指定的时区。例如设置 `timezoneOffset: 0` 将会把所有日期按照 UTC/GMT 00:00 来输出。
-
-**preserveTimezones** 是一个布尔值,只影响时间戳字面量。当设置为 `true` 时,所有字面量的时间戳字符串会在输出时保持原状,即不论输入时采取怎样的时区,输出时仍然采用那一时区(和 Shopify Liquid 的行为一致)。注意这是一个解析器参数,渲染时传入的数据中的日期的输出不会受此参数影响。注意 `preserveTimezones` 比 `timezoneOffset` 的优先级更高。
-
-**dateFormat** 用于指定输出日期的默认格式. `%A, %B %-e, %Y at %-l:%M %P %z` 如果未指定,将使用. 例如,设置 `dateFormat: %Y-%m-%dT%H:%M:%S:%LZ` 以输出 [JavaSrcipt Date.toJson()][https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON] 格式.
-
-## 换行和缩进
-
-**greedy**, **trimOutputLeft**, **trimOutputRight**, **trimTagLeft**, **trimTagRight** 选项用来移除 Liquid 语法周围的换行和缩进,详情请参考 [Whitespace Control][wc]。
-
-## 自定义分隔符
-
-**outputDelimiterLeft**, **outputDelimiterRight**, **tagDelimiterLeft**, **tagDelimiterRight** 用来自定义 LiquidJS 中 [标签和过滤器][intro] 的分隔符。例如设置了 `outputDelimiterLeft: <%=, outputDelimiterRight: %>` 后我们可以避免跟其他模板引擎冲突:
-
-```ejs
-<%= username | append: ", welcome to LiquidJS!" %>
-```
-
-## 严格模式
-
-**strictFilters** 用来启用过滤器的严格模式,如果设置为 `true` 过滤器不存在时解析会抛出异常。默认为 `false`,这时会跳过不存在的过滤器。
-
-**strictVariables** 用来启用变量严格模式。如果设置为 `true` 变量不存在时渲染会抛出异常,默认为 `false` 这时不存在的变量会被渲染为空字符串。
-
-**ownPropertyOnly** 用来隐藏原型上的变量,如果你需要把未经处理过的对象传递给模板时,可以设置 `ownPropertyOnly` 为 `true`,默认为 `false`。
-
-{% note info 不存在的标签 %}
-不存在的标签总是会抛出一个解析异常,这一行为无法自定义。
-{% endnote %}
-
-## 参数顺序
-
-默认会忽略参数出现的顺序,例如 `{% for i in (1..8) reversed limit:3 %}` 里总是会先执行 `limit` 再执行 `reversed`,虽然 `reversed` 先出现。为了让 LiquidJS 按顺序执行参数,需要设置 **orderedFilterParameters** 为 `true`。它的默认值为 `false`。
-
-[liquid]: /api/classes/Liquid.html
-[caching]: ./caching.html
-[abstract-fs]: ./render-file.html#Abstract-File-System
-[render-file]: ./render-file.html
-[185]: https://github.com/harttle/liquidjs/issues/185
-[render]: ../tags/render.html
-[include]: ../tags/include.html
-[layout]: ../tags/layout.html
-[wc]: ./whitespace-control.html
-[intro]: ./intro-to-liquid.html
-[jekyllInclude]: /api/interfaces/LiquidOptions.html#jekyllInclude
-[raw]: ../filters/raw.html
-[outputEscape]: /api/interfaces/LiquidOptions.html#outputEscape
diff --git a/docs/source/zh-cn/tutorials/parse-parameters.md b/docs/source/zh-cn/tutorials/parse-parameters.md
deleted file mode 100644
index 3f5cbaa65..000000000
--- a/docs/source/zh-cn/tutorials/parse-parameters.md
+++ /dev/null
@@ -1,100 +0,0 @@
----
-title: 参数解析
----
-
-## 访问原始参数
-
-在 [注册过滤器和标签][register-tags] 中提到,可以通过 `tagToken.args` 来得到标签的原始参数字符串。例如:
-
-```javascript
-// Usage: {% random foo bar coo %}
-// Output: "foo", "bar" or "coo"
-engine.registerTag('random', {
- parse(tagToken) {
- // tagToken.args === "foo bar coo"
- this.items = tagToken.args.split(' ')
- },
- render(context, emitter) {
- // get a random index
- const index = Math.floor(this.items.length * Math.random())
- // output that item
- emitter.write(this.items[index])
- }
-})
-```
-
-见这个 JSFiddle:layout, render 和 include 里面文件名的 ".liquid" 后缀。详情请参考 extname 选项。
-{% endnote %}
-
-## 布局模板(模板继承)
-
-对于如下两个模板文件:
-
-```
-// 文件:default-layout.liquid
-Header
-{% block content %}My default content{% endblock %}
-Footer
-
-// 文件:page.liquid
-{% layout "default-layout" %}
-{% block content %}My page content{% endblock %}
-```
-
-渲染 `page.liquid` 将会输出:
-
-```
-Header
-My page content
-Footer
-```
-
-{% note tip Block %}
-root 中使用相对路径将会被解释为相对于 cwd()(当前工作目录)。{% endnote %}
-
-当模板中引入子模板时(`{% raw %}{% render "foo" %}{% endraw %}`),或者调用 `.renderFile('foo')` 时,LiquidJS 会依次查看如下几个文件,并渲染第一个存在的文件:
-
-- `cwd()`/views/foo.liquid
-- `cwd()`/views/partials/foo.liquid
-
-如果上述文件都不存在,将会抛出一个 `ENOENT` 错误。
-
-{% note info 示例 %} 在 Node.js 示例中展示了怎么渲染一个文件 liquidjs/demo/nodejs/。{% endnote %}
-
-在浏览器中使用 LiquidJS 时,比如当前路径为 - {% assign title = user.title | capitalize %} - {{ title }} {{ user.first_name | default: user.name }} {{ user.last_name }} - {% if user.address %} - {{ user.address.line1 }} - {% else %} - {{ user.email_addresses[0] }} - {% for email in user.email_addresses %} - - {{ email }} - {% endfor %} - {% endif %} - {{ a[b.c].d }} -
-`) - -console.log(engine.variablesSync(template)) -``` - -**输出** - -```javascript -[ 'user', 'title', 'email', 'a', 'b' ] -``` - -可以看到,标签和过滤器参数中的变量也会包含在内,例如示例中的嵌套变量 `b`。 -另外,可以使用 `Liquid.fullVariables(template)` 方法获取包含其属性的完整变量列表。 - -```javascript -// 上例继续 -engine.fullVariables(template).then(console.log) -``` - -**输出** - -```javascript -[ - 'user.title', - 'user.first_name', - 'user.name', - 'user.last_name', - 'user.address', - 'user.address.line1', - 'user.email_addresses[0]', - 'user.email_addresses', - 'title', - 'email', - 'a[b.c].d', - 'b.c' -] -``` - -或者,使用 `Liquid.variableSegments(template)` 获取每个变量路径的字符串和数字数组。 - -```javascript -// 上例继续 -engine.variableSegments(template).then(console.log) -``` - -**输出** - -```javascript -[ - [ 'user', 'title' ], - [ 'user', 'first_name' ], - [ 'user', 'name' ], - [ 'user', 'last_name' ], - [ 'user', 'address' ], - [ 'user', 'address', 'line1' ], - [ 'user', 'email_addresses', 0 ], - [ 'user', 'email_addresses' ], - [ 'title' ], - [ 'email' ], - [ 'a', [ 'b', 'c' ], 'd' ], - [ 'b', 'c' ] -] -``` - -### 全局变量 - -注意在上述示例中,`title` 和 `email` 被包含在结果中。通常你可能希望排除 `{% assign %}` 标签中定义的变量名,以及由 `{% for %}` 标签引入的临时变量。 - -为了获取 _全局_ 变量(即由应用开发者提供,而不是模板作者定义的变量)的名称,可以使用 `globalVariables`、`globalFullVariables` 或 `globalVariableSegments` 方法(及其同步版本)。 - -```javascript -// 上例继续 -engine.globalVariableSegments(template).then(console.log) -``` - -**输出** - -```javascript -[ - [ 'user', 'title' ], - [ 'user', 'first_name' ], - [ 'user', 'name' ], - [ 'user', 'last_name' ], - [ 'user', 'address' ], - [ 'user', 'address', 'line1' ], - [ 'user', 'email_addresses', 0 ], - [ 'user', 'email_addresses' ], - [ 'a', [ 'b', 'c' ], 'd' ], - [ 'b', 'c' ] -] -``` - -### 部分模板 - -默认情况下,LiquidJS 还会尝试加载和分析任何被包含和渲染的模板。 - -```javascript -import { Liquid } from 'liquidjs' - -const footer = ` -` - -const engine = new Liquid({ templates: { footer } }) - -const template = engine.parse(` -
-Promise 的标签会被渲染成 [object Promise]。
-
-## 把 LiquidJS 生成器转换成 Promise
-
-有些 LiquidJS API 会返回 `Promise`,有些会返回生成器。你可以用 [toPromise][toPromise] 来把生成器转换为 `Promise`,比如:
-
-```typescript
-import { TagToken, Context, Emitter, TopLevelToken, Value, Tag, Liquid, toPromise } from 'liquidjs'
-
-// Usage: {% upper "alice" %}
-// Output: ALICE
-engine.registerTag('upper', class UpperTag extends Tag {
- private value: Value
- constructor (token: TagToken, remainTokens: TopLevelToken[], liquid: Liquid) {
- super(token, remainTokens, liquid)
- this.value = new Value(token.args, liquid)
- }
- async render (ctx: Context, emitter: Emitter) {
- const title = await toPromise(this.value.value(ctx))
- emitter.write(title.toUpperCase())
- }
-})
-```
-
-## 纯异步标签
-
-如果你的标签就不打算支持同步,可以干脆实现成 `async render()`,这样就可以使用更熟悉的 `await` 了:
-
-```typescript
-import { toPromise, TagToken, Context, Emitter, TopLevelToken, Value, Tag, Liquid } from 'liquidjs'
-
-// Usage: {% upper "alice" %}
-// Output: ALICE
-engine.registerTag('upper', class UpperTag extends Tag {
- private value: Value
- constructor (token: TagToken, remainTokens: TopLevelToken[], liquid: Liquid) {
- super(token, remainTokens, liquid)
- this.value = new Value(token.args, liquid)
- }
- async render (ctx: Context, emitter: Emitter) {
- const title = await toPromise(this.value.value(ctx))
- emitter.write(`import { Liquid } from 'liquidjs'
const engine = new Liquid()
const tpl = engine.parse('Welcome to {% raw %}{{v}}{% endraw %}!')
engine.render(tpl, {v: "Liquid"}).then(console.log)
// Outputs "Welcome to Liquid!"
{{__('index.contributors.description')}}
+{{__('index.sponsors.description')}}
+{{__('index.sponsors.description')}}
+{{__('index.contributors.description')}}
-