Auxiliar do Hugo para pré-processamento de arquivos.
Forneça um pré-processador flexível para Hugo, uma vez que não podemos, como comunidade, parecer capazes de obter suporte para certos tipos de arquivos para manipuladores/processadores externos no código principal do Hugo.
Destinado a auxiliar em qualquer tipo de pré-processamento desejado para publicação de arquivos, como:
Um arquivo de configuração é usado para definir o processamento. Por padrão, o nome do arquivo de configuração é .hugo-preproc.yaml
(ou .toml
ou .json
).
Você pode especificar um arquivo de configuração na linha de comando com a opção -c
/ --config
.
Execute o comando e o processamento ocorrerá com base na configuração.
O arquivo possui duas chaves primárias: git
e processors
, como neste exemplo:
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 {{ . }}
A chave git
é um objeto array, com cada elemento do array definido da seguinte forma:
path
- Define o caminho para o repositório git (padrão: ".")processors
- Matriz de manipuladores de log git.mode
- Valores de head
(apenas o commit head), each
(cada entrada de log passada pelo processador, consecutivamente) ou all
(todas as entradas passadas pelo processador).file
- O arquivo a ser gerado; processado como um modelo.template
- O modelo através do qual as entradas/entradas do log do git serão processadas e então gravadas no file
. A chave exec
é um objeto array, com cada elemento do array definido da seguinte forma:
path
- O caminho de nível superior que será percorrido e verificado em busca de nomes de arquivos correspondentes.pattern
- O padrão usado para corresponder aos nomes dos arquivos enquanto percorre o conteúdo path
recursivamente.command
- O comando a ser executado em arquivos correspondentes; esse valor é processado como um modelo Go.As entradas do array serão executadas serialmente, na ordem em que são definidas.
Estamos usando Go Templates para processar as chaves file
e template
em cada manipulador git
, bem como a chave command
em cada objeto processors
.
Além das funções padrão do Go Template, também adicionamos:
fields
- structs.Names
replace
- strings.Replace
{{replace <input> <search> <replace> <n>}}
example.drawio
command
: draw.io --export --output {{replace . ".md" ".svg" -1}} --format svg {{.}}
exec
: draw.io --export --output example.svg --format svg example.drawio
split
- strings.Split
{{split <input> <separator>}}
trimsuffix
- strings.TrimSuffix
{{trimsuffix <input> <trim_string>}}
Além disso, agora mapeamos a biblioteca completa de funções do modelo Masterminds/sprig. Para versões 1.x
do hugo-preproc
deixaremos nossas funções de modelo personalizado em vigor. Quando passarmos para as versões 2.x
, descontinuaremos as funções personalizadas acima em favor de sprig
.
Fornecemos a seguinte entrada para os manipuladores configurados.
manipuladores git
head
e 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.
}
}
manipuladores exec
. string // String representing the matched filename,
// including its full path (handler top search path + sub-path to file).