hugo preproc
v1.2.3
Hugo 的助手提供文件的预处理。
为 Hugo 提供灵活的预处理器,因为作为一个社区,我们似乎无法在核心 Hugo 代码中获得外部处理程序/处理器支持的某些文件类型。
旨在协助发布文件所需的任何类型的预处理,例如:
配置文件用于定义处理。默认情况下,配置文件名为.hugo-preproc.yaml (或.toml或.json )。
您可以使用-c / --config选项在命令行上指定配置文件。
执行命令并根据配置进行处理。
该文件有两个主键: git和processors ,例如这个例子:
git :
- path : path/to/repo
processors :
- mode : head | each | all
file : path/to/output/{{ .Commit.Hash }}
template : Entry {{ .<field> }}
exec :
- path : path/to/top/directory
pattern : " *.md "
command : echo {{ . }} git key 是一个数组对象,每个数组元素定义如下:
path - 定义 git 存储库的路径(默认值:“.”)processors - git 日志处理程序数组。mode - head (仅头提交)、 each (连续通过处理器的每个日志条目)或all (通过处理器的所有条目)的值。file - 要输出的文件;作为模板处理。template - 通过该模板处理 git 日志条目,然后将其写入file 。 exec键是一个数组对象,每个数组元素定义如下:
path - 将遍历并扫描匹配文件名的顶级路径。pattern - 用于在递归遍历path内容时匹配文件名的模式。command - 在匹配文件上运行的命令;该值作为 Go 模板进行处理。数组条目将按照它们定义的顺序串行执行。
我们使用 Go 模板来处理每个git处理程序中的file和template键,以及每个processors对象中的command键。
除了标准的 Go Template 函数之外,我们还添加了:
fields - structs.Namesreplace - strings.Replace替换{{replace <input> <search> <replace> <n>}}example.drawiocommand : draw.io --export --output {{replace . ".md" ".svg" -1}} --format svg {{.}}exec的模板输出: draw.io --export --output example.svg --format svg example.drawiosplit - strings.Split{{split <input> <separator>}}trimsuffix - strings.TrimSuffix{{trimsuffix <input> <trim_string>}}此外,我们现在已经映射了 Masterminds/sprig 模板函数的完整库。对于hugo-preproc的1.x版本,我们将保留自定义模板函数。当我们转向2.x版本时,我们将弃用上述自定义函数,转而使用sprig 。
我们为配置的处理程序提供以下输入。
git处理程序
head和each
. {
Commit {
Hash string // Hash of the commit object.
Author { // Author is the original author of the commit.
Name string // Name of the Author.
Email string // Email address of the Author.
When time . Time // Date/time of the commit.
}
Committer { // Committer is the one performing the commit,
// might be different from Author.
Name string // Name of the Committer.
Email string // Email address of the Committer.
When time . Time // Date/time of the commit.
}
Message string // Message is the commit message, contains arbitrary text.
TreeHash string // TreeHash is the hash of the root tree of the commit.
ParentHashes [] string // ParentHashes are the hashes of the parent commits of the commit.
PGPSignature string // PGPSignature is the PGP signature of the commit.
}
Stats [] string // Array of strings for files changed and their stats.
} all
. {
// Array of Commits
Commits []{
Commit {
Hash string // Hash of the commit object.
Author string // Author is the original author of the commit.
Name string // Name of the Author.
Email string // Email address of the Author.
When time . Time // Date/time of the commit.
}
Committer { // Committer is the one performing the commit,
// might be different from Author.
Name string // Name of the Committer.
Email string // Email address of the Committer.
When time . Time // Date/time of the commit.
}
Message string // Message is the commit message, contains arbitrary text.
TreeHash string // TreeHash is the hash of the root tree of the commit.
ParentHashes [] string // ParentHashes are the hashes of the parent commits of the commit.
PGPSignature string // PGPSignature is the PGP signature of the commit.
}
Stats [] string // Array of strings for files changed and their stats.
}
// Head Commit
Head {
Commit {
Hash string // Hash of the commit object.
Author string // Author is the original author of the commit.
Name string // Name of the Author.
Email string // Email address of the Author.
When time. Time // Date/time of the commit.
}
Committer { // Committer is the one performing the commit,
// might be different from Author.
Name string // Name of the Committer.
Email string // Email address of the Committer.
When time. Time // Date/time of the commit.
}
Message string // Message is the commit message, contains arbitrary text.
TreeHash string // TreeHash is the hash of the root tree of the commit.
ParentHashes [] string // ParentHashes are the hashes of the parent commits of the commit.
PGPSignature string // PGPSignature is the PGP signature of the commit.
}
Stats [] string // Array of strings for files changed and their stats.
}
} exec处理程序
. string // String representing the matched filename,
// including its full path (handler top search path + sub-path to file).