Add sprig example to README

This commit is contained in:
Gabriel Garrido 2024-08-03 18:07:27 +02:00
parent 566e47a1f5
commit d18757447e

View file

@ -307,6 +307,22 @@ For both the post and filename templates, the following functions and variables
* `toMarkdown` to convert the post's HTML content to Markdown, without escaping any markdown syntax * `toMarkdown` to convert the post's HTML content to Markdown, without escaping any markdown syntax
* `toMarkdownEscaped` to convert the post's HTML content to Markdown, escaping any markdown syntax * `toMarkdownEscaped` to convert the post's HTML content to Markdown, escaping any markdown syntax
Sprig is particularly useful for arbitrary customization, such as [string manipulation](https://masterminds.github.io/sprig/strings.html).
For example, let's assume we want to convert the casing of the tags from Mastodon. The [default template](files/templates/post.tmpl) passes the tags as-is, but we want them in kebab-case. You would need to create a custom template, and use the `kebabcase` function where the tags are rendered:
```
---
date: {{ .Post.CreatedAt }}
tags:
{{- range .Post.AllTags }}
- {{ .Name | kebabcase }}
{{- end }}
---
```
You would keep this file somewhere, and pass its path to the `--template` argument when invoking the tool.
#### Variables #### Variables
* [Post](https://pkg.go.dev/git.garrido.io/gabriel/mastodon-markdown-archive/client#Post) * [Post](https://pkg.go.dev/git.garrido.io/gabriel/mastodon-markdown-archive/client#Post)