Aide à Hugo pour prévoir le prétraitement des fichiers.
Prévoyez un pré-processeur flexible pour Hugo, car nous ne pouvons pas en tant que communauté en mesure de pouvoir obtenir certains filetypes pris en charge pour les gestionnaires / processeurs externes dans le code Hugo de base.
Destiné à aider à toute sorte de prétraitement souhaité pour la publication de fichiers, tels que:
Un fichier de configuration est utilisé pour définir le traitement. Par défaut, le nom de fichier Config est .hugo-preproc.yaml (ou .toml , ou .json ).
Vous pouvez spécifier un fichier de configuration sur la ligne de commande avec l'option -c / --config .
Exécuter la commande et le traitement se produit en fonction de la configuration.
Le fichier a deux clés principales: git et processors , comme cet exemple:
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 {{ . }} La clé git est un objet de tableau, avec chaque élément de tableau défini comme suit:
path - Définit le chemin vers le repo git (par défaut: ".")processors - tableau de gestionnaires de journaux GIT.mode - Values of head (only the head commit), each (each log entry passed through the processor, consecutively), or all (all entries passed through the processor).file - le fichier à sortir; traité comme un modèle.template - The template through which the git log entry/entries will be processed and then written to file . La touche exec est un objet de tableau, avec chaque élément de tableau défini comme suit:
path - The top-level path that will be walked and scanned for matching filenames.pattern - The pattern used to match the filenames while walking the path contents recursively.command - La commande à exécuter sur des fichiers correspondants; Cette valeur est traitée comme un modèle GO.Les entrées du tableau seront exécutées en série, dans l'ordre dans lequel ils sont définis.
We are using Go Templates to process the file and template keys in each git handler, as well as the command key in each processors object.
Autre que les fonctions de modèle GO standard, nous ajoutons également:
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>}} De plus, nous avons maintenant cartographié la bibliothèque complète des fonctions Masterminds / Sprig Template. For 1.x releases of hugo-preproc we will leave our custom template functions in place. When we move to 2.x releases, we will deprecate the above custom functions in favor of sprig .
Nous fournissons l'entrée suivante pour les gestionnaires configurés.
git handlers
head and 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 handlers
. string // String representing the matched filename,
// including its full path (handler top search path + sub-path to file).