โครงสร้างเทมเพลต และการสร้าง Layout
เทมเพลตของ GenWebBlog อยู่ภายใต้โฟลเดอร์ source/ โดยมีโครงสร้างหลักดังนี้:
source/layouts/— containing base layout files (e.g.,layout.html,head.html) ซึ่งส่วนใหญ่จะเป็น layout หลักของเว็บไซต์source/pages/— page templates ที่ใช้ render เพจเฉพาะ เช่นindex.html,post.html,docs.htmlsource/components/— reusable partials/components (เช่น header, footer, card) ที่เรียกใช้จาก layouts และ pages
การลงทะเบียนเทมเพลต
ตัว generator จะ scan โฟลเดอร์ source/layouts, source/pages, และ source แล้วลงทะเบียนไฟล์ .html เป็น template name โดยจะใช้ path แบบ relative เป็น key ตัวอย่าง:
source/pages/docs.htmlจะลงทะเบียนเป็นdocsหรือpages/docsขึ้นกับการตั้งค่าและ path key
การสร้าง layout ใหม่
- สร้างไฟล์ใน
source/layouts/หรือsource/pages/ขึ้นอยู่กับว่าเป็น layout หรือหน้าเฉพาะ - ใช้ Handlebars syntax ในไฟล์ เช่น
{{ title }},{{{ contents }}}และ partials เช่น{{> components/header }} - ใน Markdown frontmatter ให้ตั้ง
layout: "your-template-name"เพื่อให้ generator ใช้ template นั้นเมื่อ render
ตัวอย่าง partial การเรียกใช้ header และ footer:
{{> components/header}}
{{{ contents }}}
{{> components/footer}}
ข้อควรระวัง
- หากเห็นข้อผิดพลาด
Template not found <name>ให้ตรวจสอบว่าชื่อไฟล์เทมเพลตตรงกับคีย์ที่ generator ลงทะเบียน (เช่น ชื่อไฟล์และตำแหน่ง) - หากต้องการใช้ component ใหม่ ให้สร้างไฟล์ใน
source/components/และเรียกใช้งานเป็น partial