ข้ามไปยังเนื้อหา

การกำหนดค่า Astro

ที่เก็บเนื้อหาไม่มี astro.config.mjs เป็นของตัวเอง แต่จะนำเข้า configuration factory จาก npm package @f5-sales-demo/docs-theme ซึ่งคืนค่าการกำหนดค่า Astro ที่สมบูรณ์พร้อม Starlight, plugins ที่รวมมา 8 ตัว และค่าเริ่มต้นของธีมทั้งหมด

ไฟล์ astro.config.mjs ของที่เก็บเนื้อหา (จัดเตรียมโดย Docker builder) เป็นเพียง wrapper บางๆ:

import { createF5xcDocsConfig } from '@f5-sales-demo/docs-theme/config';
export default createF5xcDocsConfig();

การปรับแต่งทั้งหมดทำผ่าน options object หรือตัวแปรสภาพแวดล้อม — ไม่จำเป็นต้องแตะการเชื่อมต่อ plugin, การนำเข้า CSS, หรือการแทนที่ส่วนประกอบ

createF5xcDocsConfig รับ object ชนิด F5xcDocsConfigOptions โดยทุกฟิลด์เป็นแบบ optional; ตัวแปรสภาพแวดล้อมและค่าเริ่มต้นที่เหมาะสมจะเติมในส่วนที่ขาดหายไป

interface F5xcDocsConfigOptions {
site?: string;
base?: string;
title?: string;
description?: string;
githubRepository?: string;
llmsOptionalLinks?: Array<{ title: string; url: string }>;
additionalIntegrations?: AstroIntegration[];
additionalRemarkPlugins?: Array<unknown>;
megaMenuItems?: MegaMenuItem[];
head?: HeadEntry[];
logo?: { src: string } | { light: string; dark: string };
}
ตัวเลือกค่าเริ่มต้น / ค่าสำรองจาก Envวัตถุประสงค์
siteDOCS_SITE หรือ https://f5-sales-demo.github.ioURL ฐานแบบ canonical
baseDOCS_BASE หรือ /URL base path สำหรับ project sites
titleDOCS_TITLE หรือ Documentationชื่อไซต์ในส่วนหัวและแท็บของเบราว์เซอร์
descriptionDOCS_DESCRIPTION หรือ string ว่างคำอธิบายไซต์สำหรับ metadata และ llms.txt
githubRepositoryGITHUB_REPOSITORY หรือ string ว่างเปิดใช้งานลิงก์แก้ไขและไอคอน GitHub social
llmsOptionalLinksLLMS_OPTIONAL_LINKS (JSON) หรือ []ลิงก์เพิ่มเติมสำหรับ plugin llms.txt
additionalIntegrations[]Astro integrations เพิ่มเติมที่จะต่อท้าย
additionalRemarkPlugins[]remark plugins เพิ่มเติมที่เพิ่มหลัง remark-mermaid
megaMenuItemsเมนู Products/Solutions/Docs/Support ที่มีในตัวรายการ mega menu ระดับบนสุด
headแท็ก <script> ของ Mermaid CDNรายการ <head> แบบกำหนดเอง
logo@f5-sales-demo/docs-theme/assets/github-avatar.pngโลโก้ sidebar (src เดี่ยว หรือคู่ light/dark)

factory เชื่อมต่อ Starlight plugins 8 ตัวโดยอัตโนมัติ:

Pluginวัตถุประสงค์
starlight-mega-menumega menu การนำทางบนสุดพร้อมเลย์เอาต์แบบ grid/list
starlight-videosฝังวิดีโอในหน้าเอกสาร
starlight-image-zoomคลิกเพื่อซูมภาพ
@f5-sales-demo/docs-theme (self)การแทรก CSS, การแทนที่ส่วนประกอบ, route middleware
starlight-scroll-to-topปุ่มเลื่อนกลับขึ้นบนพร้อม progress ring
starlight-heading-badgesคำอธิบาย badge บนหัวข้อ
starlight-page-actionsปุ่ม action ของหน้า
starlight-plugin-iconsรองรับไอคอนใน Starlight
starlight-llms-txtสร้าง llms.txt และ llms-full.txt สำหรับการใช้งาน LLM

plugins เหล่านี้ถูกลงทะเบียนตามลำดับภายใน config.ts โดย theme plugin (@f5-sales-demo/docs-theme) เองก็เป็น Starlight plugin ที่ทำงานอยู่ในรายการนี้

theme plugin ถูกกำหนดใน index.ts และลงทะเบียนในกลุ่ม plugins ที่รวมมาข้างต้น โดย hook config:setup ทำสามสิ่ง:

  1. แทรก CSS — เพิ่ม fonts/font-face.css และ styles/custom.css ไว้ต้น array customCss ของ Starlight
  2. แทนที่ส่วนประกอบ — แทนที่ส่วนประกอบ Starlight 5 ตัว:
    • Banner — การนำทางแบบ breadcrumb พร้อมลิงก์แก้ไข
    • EditLink — ว่างเปล่าโดยเจตนา (ลิงก์แก้ไขอยู่ใน Banner)
    • Footer — ลิงก์ social media ที่ต่อท้ายด้านล่าง footer เริ่มต้น
    • SiteTitle — โลโก้พร้อมลิงก์หน้าแรก
    • MarkdownContent — wrapper ที่เปิดใช้งานวิดีโอและการซูมภาพ
  3. เพิ่ม route middleware — ลงทะเบียน route-middleware.ts ซึ่งกรองหน้า index ออกจาก sidebar และปิดการแสดงสารบัญบนหน้า index
// index.ts — Starlight plugin entry point
export default function f5xcDocsTheme(): StarlightPlugin {
return {
name: '@f5-sales-demo/docs-theme',
hooks: {
'config:setup'({ config, updateConfig, addRouteMiddleware }) {
addRouteMiddleware({
entrypoint: '@f5-sales-demo/docs-theme/route-middleware',
order: 'pre',
});
updateConfig({
customCss: [
...(config.customCss ?? []),
'@f5-sales-demo/docs-theme/fonts/font-face.css',
'@f5-sales-demo/docs-theme/styles/custom.css',
],
components: {
...config.components,
Banner: '@f5-sales-demo/docs-theme/components/Banner.astro',
EditLink: '@f5-sales-demo/docs-theme/components/EditLink.astro',
Footer: '@f5-sales-demo/docs-theme/components/Footer.astro',
SiteTitle: '@f5-sales-demo/docs-theme/components/SiteTitle.astro',
MarkdownContent: '@f5-sales-demo/docs-theme/components/MarkdownContent.astro',
},
});
},
},
};
}

เส้นทางทั้งหมดใช้ npm package specifiers (เช่น @f5-sales-demo/docs-theme/styles/custom.css) ซึ่ง resolve ผ่าน exports map ใน package.json

นอกจาก Starlight และ plugins ของมัน factory ยังลงทะเบียนสิ่งต่อไปนี้:

  • @astrojs/react — เปิดใช้งานการรองรับ React component ในหน้า MDX
  • remark-mermaid — remark plugin แบบกำหนดเองที่แปลง code block ```mermaid ให้เป็น diagram ที่เรนเดอร์แล้ว

integrations เพิ่มเติมและ remark plugins สามารถต่อท้ายได้ผ่านตัวเลือก additionalIntegrations และ additionalRemarkPlugins

ไม่มีการกำหนด sidebar แบบกำหนดเอง Starlight สร้าง sidebar โดยอัตโนมัติจากโครงสร้างไฟล์ใน docs/ โดยใช้ title frontmatter ของแต่ละหน้าเป็นข้อความลิงก์ และ sidebar.order สำหรับการเรียงลำดับ route middleware จะกรองหน้า index ออกจาก sidebar โดยอัตโนมัติ