ファイルの前処理を提供する Hugo のヘルパー。
Hugo の柔軟なプリプロセッサを提供します。これは、コミュニティとして、コア Hugo コード内の外部ハンドラー/プロセッサーでサポートされている特定のファイルタイプを取得できないように見えるためです。
ファイルの公開に必要な、次のようなあらゆる種類の前処理を支援することを目的としています。
設定ファイルは処理を定義するために使用されます。デフォルトでは、構成ファイル名は.hugo-preproc.yaml (または.toml 、または.json ) です。
コマンドラインで-c / --configオプションを使用して構成ファイルを指定できます。
コマンドを実行すると、設定に基づいて処理が行われます。
このファイルには、次の例のように、 gitとprocessors 2 つの主キーがあります。
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キーは配列オブジェクトであり、各配列要素は次のように定義されています。
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 テンプレート関数の他に、次の機能も追加します。
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).