Front-matter

Front-matter is a block of YAML or JSON at the beginning of the file that is used to configure settings for your writings. Front-matter is terminated by three dashes when written in YAML or three semicolons when written in JSON.

The nova theme defined following front-matter beyond the official’s

  • toc
  • title2
  • description
  • type
  • gh

toc

Show table of contents or not, if not set, the default value is:

  • post layout: false
  • project layout: true
  • page layout: true

Sample (source of current page):

Copy Code

---
title: Hexo your blog
date: 2016-03-04 12:48:31
category: [软件技术, Web]
tags: [Hexo, Node.js]
toc: true
---

# Overview

This article...

title2

The internationalization title key, will be translated with __(title2)

Example
download.md content:

Copy Code

---
title: Downloads
title2: project.download
---

languages/en.yml content:

Copy Code

project:
    download: Downloads

The page title will be the output of __('project.download'), the result is: Downloads

description

The extra description of html page, will append to the content of <html><head><meta name="description"...

type

type front-matter only used in page layout.

Sample (Source of source/categories/index.md):

Copy Code

---
title: categories
date: 2016-03-30 16:14:59
type: categories
title2: menu.category
---

gh

Nova project page are generated by hexo-generator-github partially, a gh front-matter is used for project layout.

  • gh.user: the github user, default is the user in theme _config.yml
  • gh.repo: the github repo, default is fetched from url
  • gh.type
    • get_repos: The gh_repos() helper will invoked to get repositories from github.
    • get_contents: The gh_repo_contents() helper will be invoked to get markdown file under repository.
      gh.path to indicate the concrete file on github, default is README.md
      gh.ref to indicate the branch on github, default is master
    • get_releases: The gh_repo_releases() helper will be invoked to get releases under repository.

Sample (Source of p/Android-ORM/index.md):

Copy Code

---
title: Android-ORM
date: 2016-01-30 17:43:26
layout: project
title2: project.overview
gh:
  type: get_contents
  path: README_zh.md
  user: Jamling
  repo: Android-ORM
---

What’s the page output? see the snippets of helpers.js in hexo-generator-github plugin.

Copy Code

function gh_contents(options){
  var o = options || {}
  var user = o.hasOwnProperty('user') ? o.user : this.config.github.user;
  var name = o.hasOwnProperty('repo') ? o.repo : null;
  var path = o.hasOwnProperty('path') ? o.path : 'README.md';
  var ref = o.hasOwnProperty('ref') ? o.ref : 'master';
  
  if (name === undefined) {
    return '';
  }
  
  var cache = (this.gh_read_cache(this.page));
  if (cache){
      return this.markdown(cache.toString());
  }
  
  gh.setToken(this.config.github.token);
  var url = util.format('repos/%s/%s/contents/%s', user, name, path);
  console.log("no cache, and try load from : " + url);
  var repo = gh.reqSync(url, {data:{'ref': ref}});
  if (repo && repo.content){
    var md = new Buffer(repo.content, repo.encoding).toString();
    var content = this.markdown(md);
    this.gh_write_cache(this.gh_cache_dir(this.page, md));
    return content;
  }
  return '';
}