مساعد Hugo لتوفير المعالجة المسبقة للملفات.
توفير معالج مسبق مرن لـ 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 repo (الافتراضي: ".")processors - مجموعة من معالجات سجل git.mode - قيم head (التزام الرأس فقط)، each (كل إدخال سجل يتم تمريره عبر المعالج، على التوالي)، أو all (جميع الإدخالات يتم تمريرها عبر المعالج).file - الملف المطلوب إخراجه؛ معالجتها كقالب.template - القالب الذي ستتم من خلاله معالجة إدخال/إدخالات سجل git ثم كتابتها في file . المفتاح exec هو كائن مصفوفة، مع تعريف كل عنصر مصفوفة على النحو التالي:
path - مسار المستوى الأعلى الذي سيتم السير فيه وفحصه بحثًا عن أسماء الملفات المطابقة.pattern - النمط المستخدم لمطابقة أسماء الملفات أثناء السير على محتويات path بشكل متكرر.command - الأمر الذي سيتم تشغيله على الملفات المطابقة؛ تتم معالجة هذه القيمة كقالب Go.سيتم تنفيذ إدخالات المصفوفة بشكل تسلسلي، بالترتيب الذي تم تعريفها به.
نحن نستخدم Go Templates لمعالجة مفاتيح file template في كل معالج git ، بالإضافة إلى مفتاح command في كل كائن processors .
بخلاف وظائف Go Template القياسية، نضيف أيضًا:
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>}} بالإضافة إلى ذلك، قمنا الآن بتعيين المكتبة الكاملة لوظائف قوالب العقول المدبرة/sprig. بالنسبة لإصدارات 1.x من hugo-preproc سنترك وظائف القالب المخصص لدينا في مكانها. عندما ننتقل إلى إصدارات 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).