Помощник для Хьюго, обеспечивающий предварительную обработку файлов.
Обеспечьте гибкий препроцессор для 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 — это объект массива, в котором каждый элемент массива определяется следующим образом:
path — определяет путь к репозиторию git (по умолчанию: «.»)processors — массив обработчиков журналов git.mode — значения head (только головная фиксация), each (каждая запись журнала проходит через процессор последовательно) или all (все записи проходят через процессор).file — файл для вывода; обрабатывается как шаблон.template — шаблон, с помощью которого записи журнала git будут обрабатываться, а затем записываться в file . Ключ exec представляет собой объект массива, в котором каждый элемент массива определяется следующим образом:
path — путь верхнего уровня, который будет пройден и просканирован на предмет совпадения имен файлов.pattern — шаблон, используемый для сопоставления имен файлов при рекурсивном обходе содержимого path .command — команда, запускаемая для соответствующих файлов; это значение обрабатывается как шаблон Go.Элементы массива будут выполняться последовательно в том порядке, в котором они определены.
Мы используем шаблоны Go для обработки ключей file и template в каждом обработчике git , а также command ключей в каждом объекте processors .
Помимо стандартных функций шаблона 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).