构建 Hexo 主题很容易 - 你只需创建一个新文件夹。要开始使用你的主题,请修改你站点的 _config.yml
中的 theme
设置。主题应具有以下结构:
¥It’s easy to build a Hexo theme - you just have to create a new folder. To start using your theme, modify the theme
setting in your site’s _config.yml
. A theme should have the following structure:
. |
_config.yml
主题配置文件。与站点的主要配置文件不同,修改它不需要重新启动服务器。
¥Theme configuration file. Unlike the site’s primary configuration file, modifying this doesn’t require a server restart.
languages
语言文件夹。更多信息请参见 国际化 (i18n)。
¥Language folder. See internationalization (i18n) for more info.
layout
布局文件夹。此文件夹包含主题的模板文件,这些文件定义了你网站的外观。Hexo 默认提供 Nunjucks 模板引擎,但你可以轻松安装其他插件来支持替代引擎,例如 EJS 或 Pug。Hexo 根据模板的文件扩展名选择模板引擎(就像帖子一样)。例如:
¥Layout folder. This folder contains the theme’s template files, which define the appearance of your website. Hexo provides the Nunjucks template engine by default, but you can easily install additional plugins to support alternative engines such as EJS or Pug. Hexo chooses the template engine based on the file extension of the template (just like the posts). For example:
layout.ejs - uses EJS |
更多信息请参见 templates。
¥See templates for more info.
scripts
脚本文件夹。Hexo 会在初始化时自动加载此文件夹中的所有 JavaScript 文件。有关更多信息,请参阅 plugins。
¥Script folder. Hexo will automatically load all JavaScript files in this folder during initialization. For more info, see plugins.
source
源文件夹。将你的资源(例如 CSS 和 JavaScript 文件)放在这里。Hexo 会忽略隐藏文件和以 _
(下划线)为前缀的文件或文件夹。
¥Source folder. Place your assets (e.g. CSS and JavaScript files) here. Hexo ignores hidden files and files or folders prefixed with _
(underscore).
Hexo 会处理并保存所有可渲染文件到 public
文件夹。不可渲染的文件将直接复制到 public
文件夹。
¥Hexo will process and save all renderable files to the public
folder. Non-renderable files will be copied to the public
folder directly.
发布
¥Publishing
当你完成主题构建后,你可以将其发布到 主题列表。在这样做之前,你应该运行 主题单元测试 以确保一切正常。发布主题的步骤与 更新文档 非常相似。
¥When you have finished building your theme, you can publish it to the theme list. Before doing so, you should run the theme unit test to ensure that everything works. The steps for publishing a theme are very similar to those for updating documentation.
Fork hexojs/site
将存储库克隆到你的计算机并安装依赖。
¥Clone the repository to your computer and install dependencies.
git clone https://github.com/<username>/site.git
cd site
npm install在
source/_data/themes/
中创建一个新的 yaml 文件,使用你的主题名称作为文件名¥Create a new yaml file in
source/_data/themes/
, use your theme name as the file name编辑
source/_data/themes/<your-theme-name>.yml
并添加你的主题。例如:¥Edit
source/_data/themes/<your-theme-name>.yml
and add your theme. For example:description: A brand new default theme for Hexo.
link: https://github.com/hexojs/hexo-theme-landscape
preview: http://hexo.nodejs.cn/hexo-theme-landscape
tags:
- official
- responsive
- widget
- two_column
- one_column将屏幕截图(与主题同名)添加到
source/themes/screenshots
。它必须是 800*500px 的 PNG。¥Add a screenshot (with the same name as the theme) to
source/themes/screenshots
. It must be a 800*500px PNG.推送分支。
¥Push the branch.
创建一个拉取请求并描述更改。
¥Create a pull request and describe the change.