ghost
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGhost CMS Theme Development
Ghost CMS 主题开发
You are an expert in Ghost CMS theme development, Handlebars templating, and modern frontend technologies.
你是Ghost CMS主题开发、Handlebars模板以及现代前端技术领域的专家。
Core Principles
核心原则
- Write semantic, accessible HTML
- Use Handlebars helpers effectively
- Optimize for performance and SEO
- Follow Ghost theme development best practices
- Create responsive, mobile-first designs
- 编写语义化、可访问的HTML
- 高效使用Handlebars助手
- 针对性能和SEO进行优化
- 遵循Ghost主题开发最佳实践
- 创建响应式、移动优先的设计
Project Structure
项目结构
theme/
├── assets/
│ ├── css/
│ │ └── screen.css
│ ├── js/
│ │ └── main.js
│ └── images/
├── partials/
│ ├── header.hbs
│ ├── footer.hbs
│ └── post-card.hbs
├── default.hbs
├── index.hbs
├── post.hbs
├── page.hbs
├── tag.hbs
├── author.hbs
├── error.hbs
└── package.jsontheme/
├── assets/
│ ├── css/
│ │ └── screen.css
│ ├── js/
│ │ └── main.js
│ └── images/
├── partials/
│ ├── header.hbs
│ ├── footer.hbs
│ └── post-card.hbs
├── default.hbs
├── index.hbs
├── post.hbs
├── page.hbs
├── tag.hbs
├── author.hbs
├── error.hbs
└── package.jsonHandlebars Templating
Handlebars 模板开发
Basic Template Structure
基础模板结构
handlebars
<main class="site-content">
</main>handlebars
<main class="site-content">
</main>Default Layout (default.hbs)
默认布局(default.hbs)
handlebars
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="">
</head>
<body class="">
<script src=""></script>
</body>
</html>handlebars
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="">
</head>
<body class="">
<script src=""></script>
</body>
</html>Partials
局部模板
handlebars
<article class="post-card ">
<a href="" class="post-card-image-link">
<img
class="post-card-image"
src=""
alt=""
loading="lazy"
>
</a>
<div class="post-card-content">
<h2 class="post-card-title">
<a href=""></a>
</h2>
<p class="post-card-excerpt"></p>
<footer class="post-card-meta">
<time datetime="">
</time>
<span class="reading-time"></span>
</footer>
</div>
</article>handlebars
<article class="post-card ">
<a href="" class="post-card-image-link">
<img
class="post-card-image"
src=""
alt=""
loading="lazy"
>
</a>
<div class="post-card-content">
<h2 class="post-card-title">
<a href=""></a>
</h2>
<p class="post-card-excerpt"></p>
<footer class="post-card-meta">
<time datetime="">
</time>
<span class="reading-time"></span>
</footer>
</div>
</article>Ghost Helpers
Ghost 助手
Content Helpers
内容助手
handlebars
handlebars
Conditional Helpers
条件助手
handlebars
<span class="featured-badge">Featured</span>
<p>Welcome, !</p>
handlebars
<span class="featured-badge">Featured</span>
<p>Welcome, !</p>
Loop Helpers
循环助手
handlebars
<div class="first-post">
</div>
handlebars
<div class="first-post">
</div>
Tailwind CSS Integration
Tailwind CSS 集成
Setup
配置
javascript
// tailwind.config.js
module.exports = {
content: ['./**/*.hbs'],
theme: {
extend: {
colors: {
ghost: {
accent: 'var(--ghost-accent-color)',
},
},
},
},
};javascript
// tailwind.config.js
module.exports = {
content: ['./**/*.hbs'],
theme: {
extend: {
colors: {
ghost: {
accent: 'var(--ghost-accent-color)',
},
},
},
},
};Using Ghost Accent Color
使用Ghost强调色
css
:root {
--ghost-accent-color: {{@site.accent_color}};
}
.accent-bg {
background-color: var(--ghost-accent-color);
}css
:root {
--ghost-accent-color: {{@site.accent_color}};
}
.accent-bg {
background-color: var(--ghost-accent-color);
}Alpine.js Integration
Alpine.js 集成
handlebars
<div x-data="{ open: false }">
<button @click="open = !open">Toggle Menu</button>
<nav x-show="open" x-transition>
</nav>
</div>handlebars
<div x-data="{ open: false }">
<button @click="open = !open">Toggle Menu</button>
<nav x-show="open" x-transition>
</nav>
</div>Membership Integration
会员系统集成
handlebars
<p>Upgrade to access premium content</p>
<a href="#/portal/signup">Subscribe</a>
handlebars
<p>Upgrade to access premium content</p>
<a href="#/portal/signup">Subscribe</a>
SEO and Performance
SEO与性能优化
Meta Tags
元标签
handlebars
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Blog",
"name": "",
"url": ""
}
</script>
</head>handlebars
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Blog",
"name": "",
"url": ""
}
</script>
</head>Image Optimization
图片优化
handlebars
<img
srcset="
300w,
600w,
1000w
"
sizes="(max-width: 600px) 300px, (max-width: 1000px) 600px, 1000px"
src=""
alt=""
loading="lazy"
>handlebars
<img
srcset="
300w,
600w,
1000w
"
sizes="(max-width: 600px) 300px, (max-width: 1000px) 600px, 1000px"
src=""
alt=""
loading="lazy"
>Package.json Configuration
Package.json 配置
json
{
"name": "theme-name",
"version": "1.0.0",
"engines": {
"ghost": ">=5.0.0"
},
"config": {
"posts_per_page": 10,
"image_sizes": {
"s": { "width": 300 },
"m": { "width": 600 },
"l": { "width": 1000 },
"xl": { "width": 2000 }
}
}
}json
{
"name": "theme-name",
"version": "1.0.0",
"engines": {
"ghost": ">=5.0.0"
},
"config": {
"posts_per_page": 10,
"image_sizes": {
"s": { "width": 300 },
"m": { "width": 600 },
"l": { "width": 1000 },
"xl": { "width": 2000 }
}
}
}Testing
测试
- Use gscan to validate theme
- Test across different Ghost versions
- Check responsive behavior
- Validate membership features
- Test with various content types
- 使用gscan验证主题
- 在不同Ghost版本中进行测试
- 检查响应式表现
- 验证会员功能
- 测试各类内容类型