docs: zh-cn translation for static analyze features

This commit is contained in:
Harttle
2024-12-28 21:49:29 +08:00
parent 3492ff63f4
commit 94a6715667
3 changed files with 303 additions and 6 deletions
+10 -6
View File
@@ -4,8 +4,12 @@ title: Static Template Analysis
{% since %}v10.20.0{% endsince %}
{% note warn Experimental %}
Note that this is an experimental feature and future APIs are subject to change. And internal structures returned can be changed w/o a major version bump.
{% endnote %}
{% note info Sync and Async %}
There are synchronous and asynchronous versions of each of the methods demonstrated on this page. See the [Liquid API](liquid-api) for a complete reference.
There are synchronous and asynchronous versions of each of the methods demonstrated on this page. See the [Liquid API][liquid-api] for a complete reference.
{% endnote %}
## Variables
@@ -17,7 +21,7 @@ import { Liquid } from 'liquidjs'
const engine = new Liquid()
const template = engine.parse(`\
const template = engine.parse(`
<p>
{% assign title = user.title | capitalize %}
{{ title }} {{ user.first_name | default: user.name }} {{ user.last_name }}
@@ -129,7 +133,7 @@ By default, LiquidJS will try to load and analyze any included and rendered temp
```javascript
import { Liquid } from 'liquidjs'
const footer = `\
const footer = `
<footer>
<p>&copy; {{ "now" | date: "%Y" }} {{ site_name }}</p>
<p>{{ site_description }}</p>
@@ -137,7 +141,7 @@ const footer = `\
const engine = new Liquid({ templates: { footer } })
const template = engine.parse(`\
const template = engine.parse(`
<body>
<h1>Hi, {{ you | default: 'World' }}!</h1>
{% assign some = 'thing' %}
@@ -171,7 +175,7 @@ If an `{% include %}` tag uses a dynamic template name (one that can't be determ
### Advanced Usage
The examples so far all use convenience methods of the `Liquid` class, intended to cover the most common use cases. Instead, you can work with [analysis results](static-analysis-interface) directly, which expose the row, column and file name for every occurrence of each variable.
The examples so far all use convenience methods of the `Liquid` class, intended to cover the most common use cases. Instead, you can work with [analysis results][static-analysis-interface] directly, which expose the row, column and file name for every occurrence of each variable.
This is an example of an object returned from `Liquid.analyze()`, passing it the template from the [Partial Template](#partial-templates) section above.
@@ -238,7 +242,7 @@ The [`blockScope()`](/api/interfaces/Template.html#blockScope) method is respons
Whether a tag is an inline tag or a block tag, if it accepts arguments it should implement [`arguments()`](/api/interfaces/Template.html#arguments), which is responsible for returning the tag's arguments as a sequence of [`Value`](/api/classes/Value.html) instances or tokens of type [`ValueToken`](/api/types/ValueToken.html).
This example demonstrates these methods for a block tag. See LiquidJS's [built-in tags](built-in) for more examples.
This example demonstrates these methods for a block tag. See LiquidJS's [built-in tags][built-in] for more examples.
```javascript
import { Liquid, Tag, Hash } from 'liquidjs'