Halo 主題開發

👤 Ryan Wang👍 📦 v1.0.0 ⭐ 4.6 ⬇️ 230 下載
💻 開發程式設計 免費

📖 技能介紹


name: halo-theme-dev description: > Use when creating or modifying a Halo CMS theme, writing Thymeleaf templates, configuring theme.yaml or settings.yaml, calling Finder APIs, using vite-plugin-halo-theme, defining theme settings forms, referencing static assets, implementing halo:comment or halo:footer extension points, defining model annotation fields (AnnotationSetting), adding i18n support, or handling error pages. Always use this skill when the user mentions themes, templates, Thymeleaf, theme configuration, or wants to customize the frontend appearance of a Halo site — even if they do not explicitly say "theme."


Halo Theme Development

Halo is built on Spring Boot + Spring WebFlux + Thymeleaf. Themes use Thymeleaf templates for frontend page rendering.

Important: Halo's APIs, VO field names, and template variables evolve across versions. Do not rely on training data for specific field names, method signatures, or type structures. When writing code that accesses template variables or calls Finder API methods, always fetch the relevant online doc from the References section below first.

Thymeleaf Quick Reference

Full docs: https://raw.githubusercontent.com/thymeleaf/thymeleaf-docs/refs/heads/master/docs/tutorials/3.1/usingthymeleaf.md

Core syntax cheatsheet:

<!-- Output text -->
<h1 th:text="${site.title}"></h1>

<!-- Output unescaped HTML -->
<div th:utext="${post.content.content}"></div>

<!-- Links -->
<a th:href="@{${post.status.permalink}}">Post link</a>
<link rel="stylesheet" th:href="@{/assets/dist/style.css}" />

<!-- Loop -->
<li th:each="post : ${posts.items}" th:text="${post.spec.title}"></li>

<!-- Conditionals -->
<div th:if="${posts.hasNext()}">Next page</div>
<div th:unless="${posts.hasNext()}">Last page</div>

<!-- Local variable -->
<div th:with="menu = ${menuFinder.getPrimary()}">...</div>

<!-- Fragment include -->
<div th:replace="~{fragments/header :: header}"></div>

<!-- Layout reuse: pages pass fragments into a parameterized layout -->
<html th:replace="~{layout :: html(head = null, content = ~{::content})}">
  <th:block th:fragment="content"><!-- page body --></th:block>
</html>

<!-- Inline JavaScript -->
<script th:inline="javascript">
  var url = '[(${#theme.assets("/dist/main.iife.js")})]';
</script>

Development Workflow

  1. Create a theme folder under themes/ in the Halo working directory (must match metadata.name in theme.yaml)
  2. Write theme.yaml (required) and settings.yaml (optional)
  3. Create template files under templates/
  4. Install and activate the theme in Console → Theme Management

    7w4.net收錄了海量優質技能外掛。

  5. Visit the frontend to verify

Disable Thymeleaf caching during development: set env var SPRING_THYMELEAF_CACHE=false (Docker), or spring.thymeleaf.cache: false in config (source mode).

Starter Templates

The assets/ directory provides two ready-to-use theme templates:

  • assets/theme-minimal/ — Zero-build-tool minimal theme with all 8 template files; ideal for quick prototyping or simple themes
  • assets/theme-vite/ — Vite project template with vite-plugin-halo-theme (recommended for new themes); includes partial layout reuse and CSS toolchain

Usage: copy the directory into themes/ in your Halo working directory, ensure the folder name matches metadata.name in theme.yaml, then install and activate in Console.

References Index

File Content When to read
references/structure-and-config.md Directory structure, theme.yaml fields, settings.yaml form definition Creating a theme, configuring theme.yaml/settings.yaml
references/vite-plugin.md vite-plugin-halo-theme integration guide, include/slot template syntax, TailwindCSS integration Setting up a Vite-based theme (recommended)
references/templates.md Template route mapping, available variables per template Writing template files
references/global-variables.md Global variables (site, theme, theme.config) and type definitions Accessing site info or theme setting values
references/finder-apis.md All Finder APIs (postFinder, categoryFinder, tagFinder, menuFinder, singlePageFinder, etc.) Querying data from any template
references/static-resources.md Static asset reference methods (@{}, #theme.assets()) Referencing CSS/JS/images in plain HTML themes
references/template-tags.md Custom tags (halo:comment extension point, halo:footer injection) Integrating comment plugins, injecting footer code
references/i18n.md Internationalization via .properties files, #messages, #locale, frontend i18n injection Adding multi-language support to a theme
references/official-plugins.md Official plugin integration: pluginFinder.available(), search widget, dark mode color scheme adaptation Adding search, adapting dark mode for plugin UI
references/annotations.md AnnotationSetting for model custom fields, #annotations utility for reading metadata in templates Adding custom fields to menu items/posts/categories and using them in templates
references/packaging.md Packaging a theme as a ZIP using @halo-dev/theme-package-cli Preparing a theme for release or upload
references/thymeleaf-tips.md Halo-specific Thymeleaf best practices: literal substitutions, safe navigation, meta tag rules, permalink syntax Writing any template file

🤖 AI 評測

這個 Skill 質量不錯,內容全面且結構清晰,涵蓋主題開發的主要知識點,提供實用的模板示例和線上文件連結。對於想開發 Halo 主題的人來說很有幫助,入門指引清晰。不足之處是缺少一些實戰案例和常見問題解答,對進階使用者的需求覆蓋不夠。

📊 多維度評分

適應性4.2
規範性4.7
有效性4.7
可靠性4.7
可信度4.8

📁 包含檔案 (59 個)

📄 SKILL.md 7.1 KB
📄 assets/theme-minimal/settings.yaml 322 B
📄 assets/theme-minimal/templates/archives.html 953 B
📄 assets/theme-minimal/templates/assets/css/style.css 496 B
📄 assets/theme-minimal/templates/author.html 1003 B
📄 assets/theme-minimal/templates/categories.html 429 B
📄 assets/theme-minimal/templates/category.html 799 B
📄 assets/theme-minimal/templates/index.html 734 B
📄 assets/theme-minimal/templates/layout.html 1 KB
📄 assets/theme-minimal/templates/page.html 644 B
📄 assets/theme-minimal/templates/post.html 1.3 KB
📄 assets/theme-minimal/templates/tag.html 789 B
📄 assets/theme-minimal/templates/tags.html 367 B
📄 assets/theme-minimal/theme.yaml 422 B
📄 assets/theme-vite/package.json 331 B
📄 assets/theme-vite/pnpm-lock.yaml 46.2 KB
📄 assets/theme-vite/settings.yaml 319 B
📄 assets/theme-vite/src/archives.html 1.2 KB
📄 assets/theme-vite/src/author.html 458 B
📄 assets/theme-vite/src/categories.html 763 B
📄 assets/theme-vite/src/category.html 445 B
📄 assets/theme-vite/src/css/main.css 2.1 KB
📄 assets/theme-vite/src/index.html 306 B
📄 assets/theme-vite/src/js/index.ts 35 B
📄 assets/theme-vite/src/js/main.ts 26 B
📄 assets/theme-vite/src/js/post.ts 40 B
📄 assets/theme-vite/src/page.html 568 B
📄 assets/theme-vite/src/partials/layout.html 1.2 KB
📄 assets/theme-vite/src/partials/pagination.html 296 B
📄 assets/theme-vite/src/partials/post-card.html 622 B
📄 assets/theme-vite/src/post.html 1.7 KB
📄 assets/theme-vite/src/tag.html 339 B
📄 assets/theme-vite/src/tags.html 629 B
📄 assets/theme-vite/templates/archives.html 2.3 KB
📄 assets/theme-vite/templates/assets/index-DGxCc5t4.js 61 B
📄 assets/theme-vite/templates/assets/main-BX4hMbrq.css 1.6 KB
📄 assets/theme-vite/templates/assets/main-C4l0csbI.js 698 B
📄 assets/theme-vite/templates/assets/post-uGJ7G9O0.js 66 B
📄 assets/theme-vite/templates/categories.html 1.9 KB
📄 assets/theme-vite/templates/category.html 2.4 KB
📄 assets/theme-vite/templates/index.html 2.3 KB
📄 assets/theme-vite/templates/page.html 1.7 KB
📄 assets/theme-vite/templates/post.html 2.9 KB
📄 assets/theme-vite/templates/tag.html 2.3 KB
📄 assets/theme-vite/templates/tags.html 1.8 KB
📄 assets/theme-vite/theme.yaml 428 B
📄 assets/theme-vite/vite.config.ts 172 B
📄 references/annotations.md 3.4 KB
📄 references/finder-apis.md 4.1 KB
📄 references/global-variables.md 3.5 KB
📄 references/i18n.md 2.7 KB
📄 references/official-plugins.md 2.3 KB
📄 references/packaging.md 1.2 KB
📄 references/static-resources.md 1.9 KB
📄 references/structure-and-config.md 10.8 KB
📄 references/template-tags.md 2.1 KB
📄 references/templates.md 4.6 KB
📄 references/thymeleaf-tips.md 2.3 KB
📄 references/vite-plugin.md 8 KB