Pembantu Hugo untuk menyediakan pra-pemrosesan file.
Menyediakan pra-prosesor yang fleksibel untuk Hugo, karena sebagai komunitas kami tidak dapat memperoleh dukungan jenis file tertentu untuk penangan/prosesor eksternal dalam kode inti Hugo.
Ditujukan untuk membantu segala jenis pra-pemrosesan yang diinginkan untuk menerbitkan file, seperti:
File konfigurasi digunakan untuk mendefinisikan pemrosesan. Secara default, nama file konfigurasi adalah .hugo-preproc.yaml (atau .toml , atau .json ).
Anda dapat menentukan file konfigurasi pada baris perintah dengan opsi -c / --config .
Jalankan perintah dan pemrosesan terjadi berdasarkan konfigurasi.
File tersebut memiliki dua kunci utama: git dan processors , seperti contoh ini:
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 {{ . }} Kunci git adalah objek array, dengan setiap elemen array didefinisikan sebagai berikut:
path - Mendefinisikan jalur ke repo git (default: ".")processors - Array penangan git log.mode - Nilai head (hanya head yang dikomit), each (setiap entri log melewati prosesor, secara berurutan), atau all (semua entri melewati prosesor).file - File yang akan dikeluarkan; diproses sebagai templat.template - Templat yang digunakan untuk memproses entri/entri git log dan kemudian ditulis ke file . Kunci exec adalah objek array, dengan setiap elemen array didefinisikan sebagai berikut:
path - Jalur tingkat atas yang akan dilalui dan dipindai untuk menemukan nama file yang cocok.pattern - Pola yang digunakan untuk mencocokkan nama file sambil menelusuri konten path secara rekursif.command - Perintah untuk dijalankan pada file yang cocok; nilai ini diproses sebagai template Go.Entri array akan dieksekusi secara serial, sesuai urutan yang ditentukan.
Kami menggunakan Go Templates untuk memproses file dan kunci template di setiap penangan git , serta kunci command di setiap objek processors .
Selain fungsi standar Go Template, kami juga menambahkan:
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>}} Selain itu, kami sekarang telah memetakan perpustakaan lengkap fungsi template Masterminds/sprig. Untuk rilis 1.x dari hugo-preproc kami akan membiarkan fungsi template kustom kami tetap di tempatnya. Saat kami berpindah ke rilis 2.x , kami tidak lagi menggunakan fungsi khusus di atas dan mendukung sprig .
Kami memberikan masukan berikut untuk penangan yang dikonfigurasi.
penangan git
head dan 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.
}
} penangan exec
. string // String representing the matched filename,
// including its full path (handler top search path + sub-path to file).