knap
它能做什么
它教你的智能体使用变量、过滤器和简单逻辑渲染模板,使同一版式可以填入不同的数据。适合需要制作大量相似笔记或文档的人。
适用场景
- ✓当你有一份数据列表,并希望为每个条目创建一条笔记的时候。
- ✓当你希望用 JSON 文件中的值填充模板的时候。
- ✓当你希望使用模板把网页内容整理成笔记的时候。
技能链接
https://github.com/kepano/obsidian-skills/blob/main/skills/knap/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能把这个 CSV 文件中的书名列表,用我的模板为每本书生成一条笔记吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体把模板与你的数据结合,生成 Markdown 输出,可以打印出来,也可以保存到文件中。它会使用工具内置的帮助来查询模板语法。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Knap
Use Knap CLI to render Markdown templates with variables, filters, and logic.
If not installed: npm install -g knap (requires Node.js 20 or later). Alternatively, use npx knap.
Run knap --help for available commands and options. Discover the language through the CLI's offline reference:
knap help syntax
knap help filters
knap help filter date
knap help tags
knap help tag for
Use the lists to find names, then request individual help for syntax, parameters, and examples with expected output.
Usage
Render a template with JSON variables:
knap render template.md --data article.json -o note.md
Supply a template and data inline:
knap render -t '# {{ title | trim }}' --data-json '{"title":"Hello"}'
Override a variable or pipe JSON data:
knap render template.md --data article.json --set 'title=Custom title'
cat article.json | knap render template.md --data -
Data must be a JSON object; its properties become template variables. --set overrides literal top-level keys with strings. Use JSON for nested objects, arrays, numbers, and booleans.
Choose one template source (file, -t, or stdin) and one data source (--data or --data-json). Only one input can read stdin. Without a template file or -t, Knap reads the template from stdin.
Output defaults to stdout. -o creates parent directories and overwrites the destination after rendering succeeds. Errors exit with status 1; diagnostics go to stderr. Warnings can accompany successful output.
Templates
Use {{ variable }} for values, | for filters, and {% ... %} for logic. For example, save this as template.md:
---
{{ title | yaml_property:"title" }}
{{ tags | yaml_property:"tags" }}
---
# {{ title | trim }}
{% if author %}
By {{ author }}
{% endif %}
{{ content }}
Use yaml_property for complete frontmatter properties so values are quoted and indented correctly. The CLI includes standard filters, but does not supply Web Clipper browser variables, selectors, prompts, or DOM-dependent HTML filters. Supply variables through JSON.
Check a template before rendering:
knap validate template.md
Validation checks syntax, filter names, and static filter arguments without data or file output. It does not check variable existence, runtime values, or dynamic arguments; render with real data to check runtime behavior. Diagnostics go to stderr and include relevant help commands.
Defuddle pipeline
Extract a web page as JSON with Markdown content, then render it into a note:
defuddle parse https://example.com/article --md --json \
| knap render template.md --data - -o note.md
Defuddle's JSON properties, such as title and content, become template variables directly.
Batch rendering
Create one file per CSV row, JSON array object, or JSON file in a folder:
knap batch template.md --data articles.csv --output-dir notes \
--filename '{{ title | safe_name }}.md'
Use --data articles.json for an array or --data ./articles for a folder of JSON objects. CSV headers become variable names and values remain strings. Piped data defaults to JSON; add --format csv for piped CSV.
Use --dry-run to validate and list output paths without writing files. Existing files require --overwrite, including during a dry run. Duplicate output names within a batch are errors even with --overwrite.
Filename templates must produce a single filename with its extension, without directories. Use safe_name for data-derived names. Without --filename, Knap preserves source JSON basenames or numbers CSV rows and array items as 1.md, 2.md, and so on.
常见问题
数据需要是什么格式?
该技能说明,数据必须是一个 JSON 对象,其属性会成为模板变量。
它可以一次创建很多文件吗?
可以。该技能涵盖根据数据批量生成 Markdown 文件。
它需要安装吗?
需要。它需要 Knap 命令行工具,该技能说明应使用 npm 安装它,并且需要 Node.js 20 或更高版本。
详情
作者的原始描述
Render Markdown from templates and structured data using Knap CLI. Use when the user asks to apply a Knap template, turn JSON or CSV data into notes, batch-generate Markdown files, or format Defuddle output into a note.
repo: kepano/obsidian-skills
热度
- GitHub 星标
- 51k
- 排名
- #3417
- 许可证
- MIT
- 更新时间
- 2026/9/15
评论
- …