跳转至

变量 Obsidian 帮助 Variables Obsidian Help

~~文章来源~~

https://help.obsidian.md/web-clipper/variables 作者:Obsidian Help 2025-01-19T23:09:38-07:00

~~文章摘要~~

Web Clipper 模板可以使用变量自动预填充模板中页面的数据。变量可用于注释名称、注释位置、属性和注释内容。也可以使用过滤器修改变量。

~~关键事实~~

  • Web Clipper 模板支持五种变量类型:预设变量、提示变量、元变量、选择器变量和 Schema.org 变量。
  • 预设变量如 {{content}} 提取页面主要内容,{{author}} 提取页面作者。
  • 提示变量使用自然语言查询提取数据,适用于不一致格式的数据。
  • 元变量从页面的元元素中提取数据。
  • 选择器变量使用 CSS 选择器提取页面元素内容。
  • Schema.org 变量从页面的 schema.org JSON-LD 中提取数据。

~~文章正文~~

permalink: web-clipper/variables

Web Clipper templates can use variables to automatically pre-populate data from the page in a template. Variables can be used in the note name, note location, properties, and note content. Variables can also be modified using filters.
Web Clipper 模板可以使用变量自动预填充模板中页面的数据。变量可用于注释名称注释位置属性注释内容。也可以使用过滤器修改变量。

Use the ... icon in the Web Clipper extension to access the current page variables for use in templates. There are five types of variables you can use:
使用 Web Clipper 扩展中的 ... 图标可访问当前页面变量以在模板中使用。您可以使用五种类型的变量:

Preset variables  预设变量

Preset variables are automatically generated based on the page content. These typically work for most websites.
预设变量是根据页面内容自动生成的。这些通常适用于大多数网站。

The main content variable is {{content}}, which contains the article content, or the highlights, or the selection if there is any selected text on the page. Note that {{content}} attempts to extract the main content of the page, which may not always be what you want. In that case, you can use other preset variables or selector variables to extract the content you need.
主要内容变量是 {{content}},它包含文章内容、亮点或选择(如果页面上有任何选定的文本)。请注意,{{content}} 会尝试提取页面的主要内容,这可能并不总是您想要的。在这种情况下,您可以使用其他预设变量或选择器变量来提取所需的内容。

Variable  变量 Description  描述
{{author}}  {{作者}} Author of the page  页面作者
{{content}}  {{内容}} Article content, highlights, or selection, in Markdown format 文章内容、亮点或选择,采用 Markdown 格式
{{contentHtml}} Article content, highlights, or selection, in HTML format 文章内容、突出显示或选择,HTML 格式
{{date}}  {{日期}} Current date, can be formatted using the date filter 当前日期,可以使用日期筛选器进行格式设置
{{description}} Description or excerpt  说明或摘录
{{domain}}  {{域名}} Domain  域
{{favicon}}  {{网站图标}} Favicon URL  网站图标 URL
{{fullHtml}} Unprocessed HTML for the full page content 完整页面内容的未处理 HTML
{{highlights}} Highlights with text and timestamps 带有文本和时间戳的高亮显示
{{image}} Social share image URL  社交分享图片 URL
{{published}}  {{已发布}} Published date, can be formatted using the date filter 发布日期,可以使用日期筛选器进行格式设置
{{site}} Site name or publisher  站点名称或发布者
{{title}} Title of the page  页面标题
{{time}}  {{时间}} Current date and time  当前日期和时间
{{url}} Current URL  当前 URL

Prompt variables  提示变量

Prompt variables leverage language models to extract and modify data using natural language. Prompt variables require Interpreter to be enabled and configured.
提示变量利用语言模型来使用自然语言提取和修改数据。提示变量需要启用和配置 Interpreter

Prompt variables use the syntax Web Clipper templates can use variables to automatically pre-populate data from the page in a template. Variables can be used in the note name, note location, properties, and note content. Variables can also be modified using filters.. The double quotes around the prompt are important and distinguish prompts from preset variables. Prompt responses can be post-processed with filters, e.g. > Web Clipper templates can use variables to automatically pre-populate data from the page in a template. Variables can be used in the note name, note location, properties, and note content. Variables can also be modified using filters..
提示变量使用语法 {{“a summary of the page”}}。提示周围的双引号很重要,用于区分提示和预设变量。可以使用过滤器对提示响应进行后处理,例如 > Web Clipper templates can use variables to automatically pre-populate data from the page in a template. Variables can be used in the note name, note location, properties, and note content. Variables can also be modified using filters. .

When to use prompt variables

何时使用提示变量

Prompt variables have the benefit of being extremely flexible and easy to write, however they come with several tradeoffs: they are slower to run, and may have cost and privacy considerations depending on the provider you choose.
提示变量的优点是非常灵活且易于编写,但它们也有一些权衡:它们的运行速度较慢,并且可能需要考虑成本和隐私,具体取决于您选择的

Unlike other variable types, prompt variables need to be processed by an external language model, so they are replaced only once Interpreter has run.
与其他变量类型不同,提示变量需要由外部语言模型处理,因此只有在 Interpreter 运行后才会替换它们。

It is best to not use prompt variables if the data you want to extract is in a consistent format that could be extracted with other variable types.
如果要提取的数据采用一致的格式,并且可以使用其他变量类型提取,则最好不要使用提示变量。

On the other hand, prompt variables can be useful if the data you want to extract is an inconsistent format across websites. For example, you can make a template to save books that is agnostic of the book site. Prompt variables like {{author}} will work across any book site, whereas selector variables typically only work for one site.
另一方面,如果要提取的数据在网站之间的格式不一致,则提示变量可能很有用。例如,您可以制作一个模板来保存与图书网站无关的书籍。像 {{“author of the book”}} 这样的提示变量可以在任何图书网站中使用,而选择器变量通常只适用于一个网站。

Examples  例子

Prompts can use almost any natural language query. Depending on the model you use, prompts can query or translate data across languages.
提示几乎可以使用任何自然语言查询。根据您使用的模型,提示可以跨语言查询或翻译数据。

  • `- Point 1
  • Point 2
  • Point 3to extract bullet points about the page, and translate them to French.- Point 1
  • Point 2
  • Point 3` 提取有关页面的项目符号,并将其翻译成法语。
  • `- Point 1
  • Point 2
  • Point 3to extract three bullet points using a prompt in French.- Point 1
  • Point 2
  • Point 3` 使用法语提示提取三个项目符号。

Prompts can transform page content into JSON that can be manipulated with filters. For example:
提示可以将页面内容转换为可通过过滤器进行操作的 JSON。例如:

— @, [[]]

Meta variables  元变量

Meta variables allow you to extract data from meta elements in the page, including Open Graph data used to populate social share previews.
元变量允许您从页面中的元元素中提取数据,包括用于填充社交分享预览的 Open Graph 数据。

  • {{meta:name}} returns the content of the meta name tag with the given name, e.g. {{meta:name:description}} for the description meta tag.
    {{meta:name}} 返回具有给定名称的元名称标签的内容,例如,{{meta:name:description}} 表示描述元标签。
  • {{meta:property}} returns the content of the meta property tag with the given property, e.g. {{meta:property:og:title}} for the og:title meta tag.
    {{meta:property}} 返回具有给定属性的 meta property 标签的内容,例如 {{meta:property:og:title}} 表示 og:title 元标签。

Selector variables  选择器变量

Selector variables allow you to extract text content from elements on the page using CSS selectors.
选择器变量允许您使用 CSS 选择器从页面上的元素中提取文本内容。

The syntax is {{selector:cssSelector?attribute}}, where ?attribute is optional. If no attribute is specified, the text content of the element is returned. You can also use {{selectorHtml:cssSelector}} to get the HTML content of the element. Selector variables tend to work best on a specific website or set of websites that have consistent HTML structure.
语法为 {{selector:cssSelector?attribute}} ,其中 ?attribute 是可选的。如果未指定 attribute,则返回元素的文本内容。您还可以使用 {{selectorHtml:cssSelector}} 来获取元素的 HTML 内容。选择器变量往往在具有一致 HTML 结构的特定网站或一组网站上效果最佳。

  • {{selector:h1}} returns text content of the first h1 element on the page.
    {{selector:h1}} 返回页面上第一个 h1 元素的文本内容。
  • {{selector:.author}} returns text content of the first .author element on the page.
    {{selector:.author}} 返回页面上第一个 .author 元素的文本内容。
  • {{selector:img.hero?src}} returns the src attribute of the first image with class hero.
    {{selector:img.hero?src}} 返回 hero 类的第一个图像的 src 属性。
  • {{selector:a.main-link?href}} returns the href attribute of the first anchor tag with class main-link.
    {{selector:a.main-link?href}} 返回类为 main-link 的第一个锚点标签的 href 属性。
  • {{selectorHtml:body|markdown}} returns the entire HTML of the body element, converted to Markdown using the markdown filter.
  • Nested CSS selectors and combinators are supported if you need more specificity.
  • If multiple elements match the selector, an array is returned, which you can process with array and object filters like join or map.

Schema.org variables

Schema variables allow you to extract data from schema.org JSON-LD on the page. Schema.org data can also be used to automatically trigger a template.

  • {{schema:@Type:key}} returns the value of the key from the schema.
  • {{schema:@Type:parent.child}} returns the value of a nested property.
  • {{schema:@Type:arrayKey}} returns the first item in an array.
  • {{schema:@Type:arrayKey[index].property}} returns the item at the specified index in an array.
  • {{schema:@Type:arrayKey[*].property}} returns a specific property from all items in an array.

You can also use a shorthand notation without specifying the schema type:

  • {{schema:author}} will match the first author property found in any schema type.
  • {{schema:name}} will match the first name property found in any schema type.

This shorthand is particularly useful when you don't know or don't care about the specific schema type, but you know the property name you're looking for.

Nested properties and array access work as well, both with and without the schema @Type specified:

  • {{schema:author.name}} will find the first author property and then access its name sub-property.
  • {{schema:author[0].name}} will access the name of the first author in an array of authors.
  • {{schema:author[*].name}} will return an array of all author names.