Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme configurations using Hexo data files #328

iissnan opened this issue Aug 6, 2015 · 11 comments

Theme configurations using Hexo data files #328

iissnan opened this issue Aug 6, 2015 · 11 comments


Copy link

iissnan commented Aug 6, 2015

Currently, it is not smooth to update NexT theme from pulling or downloading new releases. It is quite often running into conflict status when updating NexT theme via git pull, or need to merge configurations manually when upgrading to new releases.

At present, NexT encourages users to store some options in site's _config.yml and other options in theme's _config.yml. This approach is applicable, but has some drawbacks:

  1. Configurations are splited into two pieces
  2. Users maybe confuse which place should be for options

In order to resolve this issue, NexT will take advantage of Hexo Data files. Because Data files is introduced in Hexo 3, so you need upgrade Hexo to 3.0 (or above) to use this feature.

If you prefer Hexo 2.x, you can still use the old approach for configurations. NexT is still compatible with Hexo 2.x.


With this feature, now you can put all your configurations into one place (source/_data/next.yml), you don't need to touch next/_config.yml. If there are any new options in new releases, you just need to copy those options from next/_config.yml, paste into _data/next.yml and set their values to whatever you want.

How to use this feature

  1. Please ensure you are using Hexo 3 (or above)
  2. Create an file named next.yml in site's source/_data directory (create _data directory if it did not exist)
  3. Copy NexT theme options both in site's _config.yml and theme's _config.yml into next.yml.

目前升级 NexT 主题的时候并不是非常的流畅。若使用 git pull 的方式,很多时候可能会产生冲突;而下载新版本覆盖安装的方式又需要手动合并主题的 _config.yml 文件。

在此修改之前, NexT 建议将配置分离,一部分在 站点的配置文件中,另外一部分在主题的配置文件中。将需要自定的选项放置在 站点配置文件中,从而脱离避免更新主题时可能遇到的麻烦。这种方式是可行,但是有一些缺点:

  1. 配置分离成了两个部分
  2. 用户可能会疑惑一些选项该放置在哪里比较合适

为了解决这个问题, NexT 将会使用 Hexo 的 Data Files 。然而由于 Data Files 是在 Hexo 3 版本时引进的,所以要使用这个特性,需要 Hexo 的版本不低于 3。

若你比较喜欢 Hexo 2.x 版本,可以继续使用原先的配置方式。 NexT 保持着向下兼容。


通过这个特性,你可以将所有的主题配置放置在站点的 source/_data/next.yml 文件中。原先放置在 站点配置文件 中的选项可以迁移到新的位置,同时,主题配置文件可以不用做任何修改。若后续版本有配置相关的改动时,你仅需在 next.yml 中做相应调整即可。


  1. 请先确保你所使用的 Hexo 版本在 3 以上
  2. 在站点的 source/_data 目录下新建 next.yml 文件(_data目录可能需要新建)
  3. 迁移站点配置文件和主题配置文件中的配置到 next.yml
@iissnan iissnan added this to the v0.4.5 milestone Aug 6, 2015
Copy link

HeminWon commented Aug 7, 2015

也就是说可以把自己的一些私人定制的配置直接剪切 到 source/_data/next.yml 中来么

Copy link
Owner Author

iissnan commented Aug 7, 2015

是的,所有主题相关的配置都可以写到 next.yml 文件中。 主题目录下的 _config.yml 可以不用做任何修改。

  1. 若你是新安装的,可以将主题的 _config.yml 里面的内容整个拷贝过去,然后修改即可
  2. 若是之前有将配置写在站点的 _config.yml 里,把这个文件里主题相关的配置剪切到 next.yml 里去;同时将主题下 _config.yml 里面的配置也拷贝过去,相当于是全部合并到 next.yml 中去了。

Copy link

imcoddy commented Aug 7, 2015


Copy link

eurusd commented Sep 11, 2015


Copy link
Owner Author

iissnan commented Oct 17, 2015

有一个缺点:每次修改 _next.yml 需要重启 hexo server 才能生效。

Copy link

vinnyxiong commented Mar 7, 2016


Copy link
Owner Author

iissnan commented Mar 7, 2016

嗯,这种方式还是可以适用很大范围的用户。如果自定义部分比较复杂,就需要 fork 一份

Copy link

atjason commented Apr 22, 2017

@iissnan 这个方案有缺陷:在主题的 _config.yml 里面打开的选项,无法在 source/_data/next.yml 中关闭。

比如,主题的 _config.yml 中默认开启 tags menu;这样,即使在 source/_data/next.yml 中关闭 tags menu,最终结果依然有,因为只有当后者也开启某项时,其值才能覆盖前者。

如何能让 hexo 放弃主题的中 _config.yml 呢?我试了,即使指定配置文件:hexo s --config source/_data/next.yml,依然会读取主题的中 _config.yml

Copy link

lengmo714 commented Jun 9, 2017


Copy link

MeetXinZhang commented Dec 6, 2017


Copy link

xiaobai050 commented Nov 11, 2018


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

9 participants