docs(template): add formatDate custom format

This commit is contained in:
iyear 2023-10-15 01:38:36 +08:00
parent ace796f39f
commit 1cefc40140
2 changed files with 28 additions and 24 deletions

View File

@ -25,18 +25,18 @@ Template syntax is based on [Go's text/template](https://golang.org/pkg/text/tem
### Functions (beta)
| Func | Desc | Usage | Example |
|:------------:|:-----------------------------------------------:|:-------------------------:|:--------------------------------------:|
| `repeat` | Repeat `STRING` `N` times | `repeat STRING N` | `{{ repeat "test" 3 }}` |
| `replace` | Perform replacement on `STRING` with `PAIRS` | `replace STRING PAIRS...` | `{{ replace "Test" "t" "T" "e" "E" }}` |
| `upper` | Convert `STRING` to uppercase | `upper STRING` | `{{ upper "Test" }}` |
| `lower` | Convert `STRING` to lowercase | `lower STRING` | `{{ lower "Test" }}` |
| `snakecase` | Convert `STRING` to snake_case | `snakecase STRING` | `{{ snakecase "Test" }}` |
| `camelcase` | Convert `STRING` to camelCase | `camelcase STRING` | `{{ camelcase "Test" }}` |
| `kebabcase` | Convert `STRING` to kebab-case | `kebabcase STRING` | `{{ kebabcase "Test" }}` |
| `rand` | Generate random number in range `MIN` to `MAX` | `rand MIN MAX` | `{{ rand 1 10 }}` |
| `now` | Get current timestamp | `now` | `{{ now }}` |
| `formatDate` | Format `TIMESTAMP` with `20060102150405` format | `formatDate TIMESTAMP` | `{{ formatDate 1600000000 }}` |
| Func | Desc | Usage | Example |
|:------------:|:------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------:|
| `repeat` | Repeat `STRING` `N` times | `repeat STRING N` | `{{ repeat "test" 3 }}` |
| `replace` | Perform replacement on `STRING` with `PAIRS` | `replace STRING PAIRS...` | `{{ replace "Test" "t" "T" "e" "E" }}` |
| `upper` | Convert `STRING` to uppercase | `upper STRING` | `{{ upper "Test" }}` |
| `lower` | Convert `STRING` to lowercase | `lower STRING` | `{{ lower "Test" }}` |
| `snakecase` | Convert `STRING` to snake_case | `snakecase STRING` | `{{ snakecase "Test" }}` |
| `camelcase` | Convert `STRING` to camelCase | `camelcase STRING` | `{{ camelcase "Test" }}` |
| `kebabcase` | Convert `STRING` to kebab-case | `kebabcase STRING` | `{{ kebabcase "Test" }}` |
| `rand` | Generate random number in range `MIN` to `MAX` | `rand MIN MAX` | `{{ rand 1 10 }}` |
| `now` | Get current timestamp | `now` | `{{ now }}` |
| `formatDate` | Format `TIMESTAMP` with [format](https://golang.cafe/blog/golang-time-format-example.html)<br/>Default: `20060102150405` | `formatDate TIMESTAMP` <br/> `formatDate TIMESTAMP "format"` | `{{ formatDate 1600000000 }}`<br/> `{{ formatDate 1600000000 "2006-01-02-15-04-05"}}` |
### Examples:
@ -45,6 +45,8 @@ Template syntax is based on [Go's text/template](https://golang.org/pkg/text/tem
{{ .FileName }}_{{ formatDate .DownloadDate }}_{{ .FileSize }}
{{ .FileName }}_{{ formatDate .DownloadDate "2006-01-02-15-04-05"}}_{{ .FileSize }}
{{ lower (replace .FileName ` ` `_`) }}
{{ formatDate (now) }}

View File

@ -25,18 +25,18 @@ bookToC: false
### 函数 (Beta)
| 函数 | 描述 | 用法 | 示例 |
|:------------:|:-------------------------------------:|:-------------------------:|:--------------------------------------:|
| `repeat` | 重复 `STRING` `N` 次 | `repeat STRING N` | `{{ repeat "test" 3 }}` |
| `replace` | 对 `STRING` 执行 `PAIRS` 替换 | `replace STRING PAIRS...` | `{{ replace "Test" "t" "T" "e" "E" }}` |
| `upper` | 将 `STRING` 转换为大写 | `upper STRING` | `{{ upper "Test" }}` |
| `lower` | 将 `STRING` 转换为小写 | `lower STRING` | `{{ lower "Test" }}` |
| `snakecase` | 将 `STRING` 转换为 snake_case | `snakecase STRING` | `{{ snakecase "Test" }}` |
| `camelcase` | 将 `STRING` 转换为 camelCase | `camelcase STRING` | `{{ camelcase "Test" }}` |
| `kebabcase` | 将 `STRING` 转换为 kebab-case | `kebabcase STRING` | `{{ kebabcase "Test" }}` |
| `rand` | 在范围 `MIN``MAX` 生成随机数 | `rand MIN MAX` | `{{ rand 1 10 }}` |
| `now` | 获取当前时间戳 | `now` | `{{ now }}` |
| `formatDate` | 使用 `20060102150405` 格式格式化 `TIMESTAMP` | `formatDate TIMESTAMP` | `{{ formatDate 1600000000 }}` |
| 函数 | 描述 | 用法 | 示例 |
|:------------:|:------------------------------------------------------------------------------------------:|:------------------------------------------------------------:|:-------------------------------------------------------------------------------------:|
| `repeat` | 重复 `STRING` `N` | `repeat STRING N` | `{{ repeat "test" 3 }}` |
| `replace` | `STRING` 执行 `PAIRS` 替换 | `replace STRING PAIRS...` | `{{ replace "Test" "t" "T" "e" "E" }}` |
| `upper` | `STRING` 转换为大写 | `upper STRING` | `{{ upper "Test" }}` |
| `lower` | `STRING` 转换为小写 | `lower STRING` | `{{ lower "Test" }}` |
| `snakecase` | `STRING` 转换为 snake_case | `snakecase STRING` | `{{ snakecase "Test" }}` |
| `camelcase` | `STRING` 转换为 camelCase | `camelcase STRING` | `{{ camelcase "Test" }}` |
| `kebabcase` | `STRING` 转换为 kebab-case | `kebabcase STRING` | `{{ kebabcase "Test" }}` |
| `rand` | 在范围 `MIN``MAX` 生成随机数 | `rand MIN MAX` | `{{ rand 1 10 }}` |
| `now` | 获取当前时间戳 | `now` | `{{ now }}` |
| `formatDate` | [格式化](https://zhuanlan.zhihu.com/p/145009400) `TIMESTAMP` 时间戳<br/>(默认格式: `20060102150405`) | `formatDate TIMESTAMP` <br/> `formatDate TIMESTAMP "format"` | `{{ formatDate 1600000000 }}`<br/> `{{ formatDate 1600000000 "2006-01-02-15-04-05"}}` |
### 示例:
@ -45,6 +45,8 @@ bookToC: false
{{ .FileName }}_{{ formatDate .DownloadDate }}_{{ .FileSize }}
{{ .FileName }}_{{ formatDate .DownloadDate "2006-01-02-15-04-05"}}_{{ .FileSize }}
{{ lower (replace .FileName ` ` `_`) }}
{{ formatDate (now) }}