diff --git a/package.json b/package.json
index c4bbd5cd96..9310cb4e97 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"scripts": {
"build": "hexo generate",
"eslint": "eslint .",
+ "format:md": "prettier --write */**/docs/*.md */**/api/*.md",
"prepare": "husky"
},
"dependencies": {
@@ -32,13 +33,15 @@
"eslint-config-hexo": "^5.0.0",
"husky": "^9.0.6",
"imagemin-lint-staged": "^0.5.1",
- "lint-staged": "^15.2.0"
+ "lint-staged": "^15.2.0",
+ "prettier": "3.2.5"
},
"lint-staged": {
"*.{png,jpeg,jpg,gif,svg}": [
"imagemin-lint-staged"
],
- "*.js": "eslint --fix"
+ "*.js": "eslint --fix",
+ "*.md": "prettier --write"
},
"engines": {
"node": ">=14"
diff --git a/source/api/box.md b/source/api/box.md
index 3cf4ebe3d9..17f9b22d6a 100644
--- a/source/api/box.md
+++ b/source/api/box.md
@@ -1,18 +1,19 @@
---
title: Box
---
+
Box is a container used for processing files in a specified folder. Hexo uses two different boxes: `hexo.source` and `hexo.theme`. The former is used to process the `source` folder and the latter to process the `theme` folder.
## Load Files
Box provides two methods for loading files: `process` and `watch`. `process` loads all files in the folder. `watch` does the same, but also starts watching for file changes.
-``` js
-box.process().then(function(){
+```js
+box.process().then(function () {
// ...
});
-box.watch().then(function(){
+box.watch().then(function () {
// You can call box.unwatch() later to stop watching.
});
```
@@ -21,7 +22,7 @@ box.watch().then(function(){
Box provides many ways for path matching. You can use a regular expression, a function or an Express-style pattern string. For example:
-``` plain
+```plain
posts/:id => posts/89
posts/*path => posts/2015/title
```
@@ -32,30 +33,30 @@ See [util.Pattern] for more info.
A processor is an essential element of Box and is used to process files. You can use path matching as described above to restrict what exactly the processor should process. Register a new processor with the `addProcessor` method.
-``` js
-box.addProcessor('posts/:id', function(file){
+```js
+box.addProcessor("posts/:id", function (file) {
//
});
```
Box passes the content of matched files to processors. This information can then be read straight from the `file` argument in the callback:
-Attribute | Description
---- | ---
-`source` | Full path of the file
-`path` | Relative path to the box of the file
-`type` | File type. The value can be `create`, `update`, `skip`, `delete`.
-`params` | The information from path matching.
+| Attribute | Description |
+| --------- | ----------------------------------------------------------------- |
+| `source` | Full path of the file |
+| `path` | Relative path to the box of the file |
+| `type` | File type. The value can be `create`, `update`, `skip`, `delete`. |
+| `params` | The information from path matching. |
Box also provides some methods so you don't have to do file IO by yourself.
-Method | Description
---- | ---
-`read` | Read a file
-`readSync` | Read a file synchronously
-`stat` | Read the status of a file
-`statSync` | Read the status of a file synchronously
-`render` | Render a file
-`renderSync` | Render a file synchronously
+| Method | Description |
+| ------------ | --------------------------------------- |
+| `read` | Read a file |
+| `readSync` | Read a file synchronously |
+| `stat` | Read the status of a file |
+| `statSync` | Read the status of a file synchronously |
+| `render` | Render a file |
+| `renderSync` | Render a file synchronously |
[util.Pattern]: https://github.com/hexojs/hexo-util#patternrule
diff --git a/source/api/console.md b/source/api/console.md
index 09b05879f1..f03bea2a85 100644
--- a/source/api/console.md
+++ b/source/api/console.md
@@ -1,21 +1,22 @@
---
title: Console
---
+
The console forms the bridge between Hexo and its users. It registers and describes the available console commands.
## Synopsis
-``` js
-hexo.extend.console.register(name, desc, options, function(args){
+```js
+hexo.extend.console.register(name, desc, options, function (args) {
// ...
});
```
-Argument | Description
---- | ---
-`name` | Name
-`desc` | Description
-`options`| Options
+| Argument | Description |
+| --------- | ----------- |
+| `name` | Name |
+| `desc` | Description |
+| `options` | Options |
An argument `args` will be passed into the function. This is the argument that users type into the terminal. It's parsed by [Minimist].
@@ -25,8 +26,10 @@ An argument `args` will be passed into the function. This is the argument that u
The usage of a console command. For example:
-``` js
-{usage: '[layout]
'}
+```js
+{
+ usage: "[layout] ";
+}
// hexo new [layout]
```
@@ -34,12 +37,12 @@ The usage of a console command. For example:
The description of each argument of a console command. For example:
-``` js
+```js
{
arguments: [
- {name: 'layout', desc: 'Post layout'},
- {name: 'title', desc: 'Post title'}
- ]
+ { name: "layout", desc: "Post layout" },
+ { name: "title", desc: "Post title" },
+ ];
}
```
@@ -47,11 +50,9 @@ The description of each argument of a console command. For example:
The description of each option of a console command. For example:
-``` js
+```js
{
- options: [
- {name: '-r, --replace', desc: 'Replace existing files'}
- ]
+ options: [{ name: "-r, --replace", desc: "Replace existing files" }];
}
```
@@ -61,10 +62,14 @@ More detailed information about a console command.
## Example
-``` js
-hexo.extend.console.register('config', 'Display configuration', function(args){
- console.log(hexo.config);
-});
+```js
+hexo.extend.console.register(
+ "config",
+ "Display configuration",
+ function (args) {
+ console.log(hexo.config);
+ },
+);
```
[Minimist]: https://github.com/minimistjs/minimist
diff --git a/source/api/deployer.md b/source/api/deployer.md
index 0ba8868f69..c26df36fdd 100644
--- a/source/api/deployer.md
+++ b/source/api/deployer.md
@@ -1,12 +1,13 @@
---
title: Deployer
---
+
A deployer helps users quickly deploy their site to a remote server without complicated commands.
## Synopsis
-``` js
-hexo.extend.deployer.register(name, function(args){
+```js
+hexo.extend.deployer.register(name, function (args) {
// ...
});
```
diff --git a/source/api/events.md b/source/api/events.md
index 21dc185355..4a72f43dbc 100644
--- a/source/api/events.md
+++ b/source/api/events.md
@@ -1,6 +1,7 @@
---
title: Events
---
+
Hexo inherits from [EventEmitter]. Use the `on` method to listen for events emitted by Hexo, and use the `emit` method to emit events. For more information, refer to the Node.js API documentation.
### deployBefore
@@ -27,16 +28,16 @@ Emitted after generation finishes.
Emitted after a new post has been created. This event returns the post data:
-``` js
-hexo.on('new', function(post){
+```js
+hexo.on("new", function (post) {
//
});
```
-Data | Description
---- | ---
-`post.path` | Full path of the post file
-`post.content` | Content of the post file
+| Data | Description |
+| -------------- | -------------------------- |
+| `post.path` | Full path of the post file |
+| `post.content` | Content of the post file |
### processBefore
diff --git a/source/api/filter.md b/source/api/filter.md
index 8f948d3b60..acd44c6a1c 100644
--- a/source/api/filter.md
+++ b/source/api/filter.md
@@ -1,11 +1,12 @@
---
title: Filter
---
+
A filter is used to modify some specified data. Hexo passes data to filters in sequence and the filters then modify the data one after the other. This concept was borrowed from [WordPress](http://codex.wordpress.org/Plugin_API#Filters).
## Synopsis
-``` js
+```js
hexo.extend.filter.register(type, function() {
// User configuration
const { config } = this;
@@ -22,69 +23,69 @@ You can define the `priority`. Lower `priority` means that it will be executed f
## Execute Filters
-``` js
+```js
hexo.extend.filter.exec(type, data, options);
hexo.extend.filter.execSync(type, data, options);
```
-Option | Description
---- | ---
-`context` | Context
-`args` | Arguments. This must be an array.
+| Option | Description |
+| --------- | --------------------------------- |
+| `context` | Context |
+| `args` | Arguments. This must be an array. |
The first argument passed into each filter is `data`. The `data` passed into the next filter can be modified by returning a new value. If nothing is returned, the data remains unmodified. You can even use `args` to specify other arguments in filters. For example:
-``` js
-hexo.extend.filter.register('test', function(data, arg1, arg2){
+```js
+hexo.extend.filter.register("test", function (data, arg1, arg2) {
// data === 'some data'
// arg1 === 'foo'
// arg2 === 'bar'
- return 'something';
+ return "something";
});
-hexo.extend.filter.register('test', function(data, arg1, arg2){
+hexo.extend.filter.register("test", function (data, arg1, arg2) {
// data === 'something'
});
-hexo.extend.filter.exec('test', 'some data', {
- args: ['foo', 'bar']
+hexo.extend.filter.exec("test", "some data", {
+ args: ["foo", "bar"],
});
```
You can also use the following methods to execute filters:
-``` js
+```js
hexo.execFilter(type, data, options);
hexo.execFilterSync(type, data, options);
```
## Unregister Filters
-``` js
+```js
hexo.extend.filter.unregister(type, filter);
```
**Example**
-``` js
+```js
// Unregister a filter which is registered with named function
const filterFn = (data) => {
- data = 'something';
+ data = "something";
return data;
};
-hexo.extend.filter.register('example', filterFn);
+hexo.extend.filter.register("example", filterFn);
-hexo.extend.filter.unregister('example', filterFn);
+hexo.extend.filter.unregister("example", filterFn);
```
-``` js
+```js
// Unregister a filter which is registered with commonjs module
-hexo.extend.filter.register('example', require('path/to/filter'));
+hexo.extend.filter.register("example", require("path/to/filter"));
-hexo.extend.filter.unregister('example', require('path/to/filter'));
+hexo.extend.filter.unregister("example", require("path/to/filter"));
```
## Filter List
@@ -97,8 +98,8 @@ Executed before a post is rendered. Refer to [post rendering](posts.html#Render)
For example, to transform the title to lower case:
-``` js
-hexo.extend.filter.register('before_post_render', function(data){
+```js
+hexo.extend.filter.register("before_post_render", function (data) {
data.title = data.title.toLowerCase();
return data;
});
@@ -110,9 +111,12 @@ Executed after a post is rendered. Refer to [post rendering](posts.html#Render)
For example, to replace `@username` with a link to a Twitter profile:
-``` js
-hexo.extend.filter.register('after_post_render', function(data){
- data.content = data.content.replace(/@(\d+)/, '#$1');
+```js
+hexo.extend.filter.register("after_post_render", function (data) {
+ data.content = data.content.replace(
+ /@(\d+)/,
+ '#$1',
+ );
return data;
});
```
@@ -121,8 +125,8 @@ hexo.extend.filter.register('after_post_render', function(data){
Executed before Hexo is about to exit -- this will run right after `hexo.exit` is called.
-``` js
-hexo.extend.filter.register('before_exit', function(){
+```js
+hexo.extend.filter.register("before_exit", function () {
// ...
});
```
@@ -131,8 +135,8 @@ hexo.extend.filter.register('before_exit', function(){
Executed before generation begins.
-``` js
-hexo.extend.filter.register('before_generate', function(){
+```js
+hexo.extend.filter.register("before_generate", function () {
// ...
});
```
@@ -141,8 +145,8 @@ hexo.extend.filter.register('before_generate', function(){
Executed after generation finishes.
-``` js
-hexo.extend.filter.register('after_generate', function(){
+```js
+hexo.extend.filter.register("after_generate", function () {
// ...
});
```
@@ -153,8 +157,8 @@ Modify [local variables](../docs/variables.html) in templates.
For example, to add the current time to the local variables of templates:
-``` js
-hexo.extend.filter.register('template_locals', function(locals){
+```js
+hexo.extend.filter.register("template_locals", function (locals) {
locals.now = Date.now();
return locals;
});
@@ -164,8 +168,8 @@ hexo.extend.filter.register('template_locals', function(locals){
Executed after Hexo is initialized -- this will run right after `hexo.init` completes.
-``` js
-hexo.extend.filter.register('after_init', function(){
+```js
+hexo.extend.filter.register("after_init", function () {
// ...
});
```
@@ -174,8 +178,8 @@ hexo.extend.filter.register('after_init', function(){
Executed when creating a post to determine the path of new posts.
-``` js
-hexo.extend.filter.register('new_post_path', function(data, replace){
+```js
+hexo.extend.filter.register("new_post_path", function (data, replace) {
// ...
});
```
@@ -184,8 +188,8 @@ hexo.extend.filter.register('new_post_path', function(data, replace){
Used to determine the permalink of posts.
-``` js
-hexo.extend.filter.register('post_permalink', function(data){
+```js
+hexo.extend.filter.register("post_permalink", function (data) {
// ...
});
```
@@ -198,8 +202,8 @@ Executed after rendering finishes. You can see [rendering](rendering.html#after_
Executed after generated files and cache are removed with `hexo clean` command.
-``` js
-hexo.extend.filter.register('after_clean', function(){
+```js
+hexo.extend.filter.register("after_clean", function () {
// remove some other temporary files
});
```
@@ -210,10 +214,10 @@ Add middleware to the server. `app` is a [Connect] instance.
For example, to add `X-Powered-By: Hexo` to the response header:
-``` js
-hexo.extend.filter.register('server_middleware', function(app){
- app.use(function(req, res, next){
- res.setHeader('X-Powered-By', 'Hexo');
+```js
+hexo.extend.filter.register("server_middleware", function (app) {
+ app.use(function (req, res, next) {
+ res.setHeader("X-Powered-By", "Hexo");
next();
});
});
diff --git a/source/api/generator.md b/source/api/generator.md
index 97c067f252..c7062f0986 100644
--- a/source/api/generator.md
+++ b/source/api/generator.md
@@ -1,12 +1,13 @@
---
title: Generator
---
+
A generator builds routes based on processed files.
## Synopsis
-``` js
-hexo.extend.generator.register(name, function(locals){
+```js
+hexo.extend.generator.register(name, function (locals) {
// ...
});
```
@@ -15,27 +16,27 @@ A `locals` argument will get passed into the function, containing the [site vari
## Update Routes
-``` js
-hexo.extend.generator.register('test', function(locals){
+```js
+hexo.extend.generator.register("test", function (locals) {
// Object
return {
- path: 'foo',
- data: 'foo'
+ path: "foo",
+ data: "foo",
};
// Array
return [
- {path: 'foo', data: 'foo'},
- {path: 'bar', data: 'bar'}
+ { path: "foo", data: "foo" },
+ { path: "bar", data: "bar" },
];
});
```
-Attribute | Description
---- | ---
-`path` | Path not including the prefixing `/`.
-`data` | Data
-`layout` | Layout. Specify the layouts for rendering. The value can be a string or an array. If it's ignored then the route will return `data` directly.
+| Attribute | Description |
+| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
+| `path` | Path not including the prefixing `/`. |
+| `data` | Data |
+| `layout` | Layout. Specify the layouts for rendering. The value can be a string or an array. If it's ignored then the route will return `data` directly. |
When the source files are updated, Hexo will execute all generators and rebuild the routes. **Please return the data and do not access the router directly.**
@@ -47,13 +48,13 @@ Create an archive page at `archives/index.html`. We pass all posts as data to th
Next, set the `layout` attribute to render with the theme templates. We're setting two layouts in this example: if the `archive` layout doesn't exist, the `index` layout will be used instead.
-``` js
-hexo.extend.generator.register('archive', function(locals){
+```js
+hexo.extend.generator.register("archive", function (locals) {
return {
- path: 'archives/index.html',
+ path: "archives/index.html",
data: locals,
- layout: ['archive', 'index']
- }
+ layout: ["archive", "index"],
+ };
});
```
@@ -61,15 +62,15 @@ hexo.extend.generator.register('archive', function(locals){
You can use the convenient official tool [hexo-pagination] to easily build archive pages with pagination.
-``` js
-var pagination = require('hexo-pagination');
+```js
+var pagination = require("hexo-pagination");
-hexo.extend.generator.register('archive', function(locals){
+hexo.extend.generator.register("archive", function (locals) {
// hexo-pagination makes an index.html for the /archives route
- return pagination('archives', locals.posts, {
+ return pagination("archives", locals.posts, {
perPage: 10,
- layout: ['archive', 'index'],
- data: {}
+ layout: ["archive", "index"],
+ data: {},
});
});
```
@@ -78,13 +79,13 @@ hexo.extend.generator.register('archive', function(locals){
Iterate over all posts in `locals.posts` and create routes for all the posts.
-``` js
-hexo.extend.generator.register('post', function(locals){
- return locals.posts.map(function(post){
+```js
+hexo.extend.generator.register("post", function (locals) {
+ return locals.posts.map(function (post) {
return {
path: post.path,
data: post,
- layout: 'post'
+ layout: "post",
};
});
});
@@ -94,15 +95,15 @@ hexo.extend.generator.register('post', function(locals){
This time we don't return the data explicitly but instead set `data` to a function so the route will build `fs.ReadStream` only when needed.
-``` js
-var fs = require('hexo-fs');
+```js
+var fs = require("hexo-fs");
-hexo.extend.generator.register('asset', function(locals){
+hexo.extend.generator.register("asset", function (locals) {
return {
- path: 'file.txt',
- data: function(){
- return fs.createReadStream('path/to/file.txt')
- }
+ path: "file.txt",
+ data: function () {
+ return fs.createReadStream("path/to/file.txt");
+ },
};
});
```
diff --git a/source/api/helper.md b/source/api/helper.md
index 104762b9cd..76a72e8bcd 100644
--- a/source/api/helper.md
+++ b/source/api/helper.md
@@ -1,27 +1,28 @@
---
title: Helper
---
+
A helper makes it easy to quickly add snippets to your templates. We recommend using helpers instead of templates when you're dealing with more complicated code.
Helpers can not be accessed from `source` files.
## Synopsis
-``` js
-hexo.extend.helper.register(name, function(){
+```js
+hexo.extend.helper.register(name, function () {
// ...
});
```
## Example
-``` js
-hexo.extend.helper.register('js', function(path){
+```js
+hexo.extend.helper.register("js", function (path) {
return '';
});
```
-``` js
+```js
<%- js('script.js') %>
//
```
@@ -36,8 +37,8 @@ Place it under `scripts/` or `themes//scripts/` folder.
All helpers are executed in the same context. For example, to use [`url_for()`](/docs/helpers#url-for) inside a custom helper:
-``` js
-hexo.extend.helper.register('lorem', function(path) {
+```js
+hexo.extend.helper.register("lorem", function (path) {
return '';
});
```
@@ -46,6 +47,6 @@ hexo.extend.helper.register('lorem', function(path) {
`hexo.extend.helper.get` will return the helper function, but it needs to have hexo as its context, so:
-``` js
-const url_for = hexo.extend.helper.get('url_for').bind(hexo);
+```js
+const url_for = hexo.extend.helper.get("url_for").bind(hexo);
```
diff --git a/source/api/index.md b/source/api/index.md
index 0b4b67f4ac..e6f3445454 100644
--- a/source/api/index.md
+++ b/source/api/index.md
@@ -1,6 +1,7 @@
---
title: API
---
+
This documentation provides more detailed information about the API and will be particularly helpful for people who want to modify the Hexo source code or write new plugins. If you are interested in more basic usage of Hexo, please refer to the [docs](../docs) instead.
Please note that this documentation is only valid for Hexo 3 and above.
@@ -9,22 +10,22 @@ Please note that this documentation is only valid for Hexo 3 and above.
First, we have to create a Hexo instance. A new instance takes two arguments: the root directory of the website, `base_dir`, and an object containing the initialization options. Next, we initialize this instance by calling the `init` method on it, which will then cause Hexo to load its configuration and plugins.
-``` js
-var Hexo = require('hexo');
+```js
+var Hexo = require("hexo");
var hexo = new Hexo(process.cwd(), {});
-hexo.init().then(function(){
+hexo.init().then(function () {
// ...
});
```
-Option | Description | Default
---- | --- | ---
-`debug` | Enable debug mode. Display debug messages in the terminal and save `debug.log` in the root directory. | `false`
-`safe` | Enable safe mode. Don't load any plugins. | `false`
-`silent` | Enable silent mode. Don't display any messages in the terminal. | `false`
-`config` | Specify the path of the configuration file. | `_config.yml`
-`draft` / `drafts`| Enable to add drafts to the posts list. example: when you use `hexo.locals.get('posts')` | `render_drafts` of _config.yml
+| Option | Description | Default |
+| ------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------- |
+| `debug` | Enable debug mode. Display debug messages in the terminal and save `debug.log` in the root directory. | `false` |
+| `safe` | Enable safe mode. Don't load any plugins. | `false` |
+| `silent` | Enable silent mode. Don't display any messages in the terminal. | `false` |
+| `config` | Specify the path of the configuration file. | `_config.yml` |
+| `draft` / `drafts` | Enable to add drafts to the posts list. example: when you use `hexo.locals.get('posts')` | `render_drafts` of \_config.yml |
## Load Files
@@ -32,12 +33,12 @@ Hexo provides two methods for loading files: `load` and `watch`. `load` is used
Both methods will load the list of files and pass them to the corresponding processors. After all files have been processed, they will call upon the generators to create the routes.
-``` js
-hexo.load().then(function(){
+```js
+hexo.load().then(function () {
// ...
});
-hexo.watch().then(function(){
+hexo.watch().then(function () {
// You can call hexo.unwatch() later to stop watching.
});
```
@@ -46,26 +47,29 @@ hexo.watch().then(function(){
Any console command can be called explicitly using the `call` method on the Hexo instance. Such a call takes two arguments: the name of the console command, and an options argument. Different options are available for the different console commands.
-``` js
-hexo.call('generate', {}).then(function(){
+```js
+hexo.call("generate", {}).then(function () {
// ...
});
```
-``` js
-hexo.call('list', { _: ['post'] }).then(function() {
+```js
+hexo.call("list", { _: ["post"] }).then(function () {
// ...
-})
+});
```
## Exit
You should call the `exit` method upon successful or unsuccessful completion of a console command. This allows Hexo to exit gracefully and finish up important things such as saving the database.
-``` js
-hexo.call('generate').then(function(){
- return hexo.exit();
-}).catch(function(err){
- return hexo.exit(err);
-});
+```js
+hexo
+ .call("generate")
+ .then(function () {
+ return hexo.exit();
+ })
+ .catch(function (err) {
+ return hexo.exit(err);
+ });
```
diff --git a/source/api/injector.md b/source/api/injector.md
index 80d43a2085..a1200bf9d7 100644
--- a/source/api/injector.md
+++ b/source/api/injector.md
@@ -7,7 +7,7 @@ An injector is used to add static code snippet to the `` or/and `` o
## Synopsis
```js
-hexo.extend.injector.register(entry, value, to)
+hexo.extend.injector.register(entry, value, to);
```
### entry ``
@@ -40,24 +40,34 @@ Which page will code snippets being injected.
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](/docs/writing#Layout).
-----
+---
There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.
## Example
```js
-const css = hexo.extend.helper.get('css').bind(hexo);
-const js = hexo.extend.helper.get('js').bind(hexo);
-
-hexo.extend.injector.register('head_end', () => {
- return css('https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css');
-}, 'music');
-
-hexo.extend.injector.register('body_end', '
@@ -178,19 +179,19 @@ Loads JavaScript files. `path` can be a string, an array, an object or an array
Inserts a link.
-``` js
+```js
<%- link_to(path, [text], [options]) %>
```
-Option | Description | Default
---- | --- | ---
-`external` | Opens the link in a new tab | false
-`class` | Class name |
-`id` | ID |
+| Option | Description | Default |
+| ---------- | --------------------------- | ------- |
+| `external` | Opens the link in a new tab | false |
+| `class` | Class name |
+| `id` | ID |
**Examples:**
-``` js
+```js
<%- link_to('http://www.google.com') %>
// http://www.google.com
@@ -205,22 +206,22 @@ Option | Description | Default
Inserts a mail link.
-``` js
+```js
<%- mail_to(path, [text], [options]) %>
```
-Option | Description
---- | ---
-`class` | Class name
-`id` | ID
-`subject` | Mail subject
-`cc` | CC
-`bcc` | BCC
-`body` | Mail content
+| Option | Description |
+| --------- | ------------ |
+| `class` | Class name |
+| `id` | ID |
+| `subject` | Mail subject |
+| `cc` | CC |
+| `bcc` | BCC |
+| `body` | Mail content |
**Examples:**
-``` js
+```js
<%- mail_to('a@abc.com') %>
// a@abc.com
@@ -232,23 +233,23 @@ Option | Description
Inserts an image.
-``` js
+```js
<%- image_tag(path, [options]) %>
```
-Option | Description
---- | ---
-`alt` | Alternative text of the image
-`class` | Class name
-`id` | ID
-`width` | Image width
-`height` | Image height
+| Option | Description |
+| -------- | ----------------------------- |
+| `alt` | Alternative text of the image |
+| `class` | Class name |
+| `id` | ID |
+| `width` | Image width |
+| `height` | Image height |
### favicon_tag
Inserts a favicon.
-``` js
+```js
<%- favicon_tag(path) %>
```
@@ -256,18 +257,18 @@ Inserts a favicon.
Inserts a feed link.
-``` js
+```js
<%- feed_tag(path, [options]) %>
```
-Option | Description | Default
---- | --- | ---
-`title` | Feed title | `config.title`
-`type` | Feed type |
+| Option | Description | Default |
+| ------- | ----------- | -------------- |
+| `title` | Feed title | `config.title` |
+| `type` | Feed type |
**Examples:**
-``` js
+```js
<%- feed_tag('atom.xml') %>
//
@@ -285,7 +286,7 @@ Option | Description | Default
Check whether `path` matches the URL of the current page. Use `strict` options to enable strict matching.
-``` js
+```js
<%- is_current(path, [strict]) %>
```
@@ -293,7 +294,7 @@ Check whether `path` matches the URL of the current page. Use `strict` options t
Check whether the current page is home page.
-``` js
+```js
<%- is_home() %>
```
@@ -301,7 +302,7 @@ Check whether the current page is home page.
Check whether the current page is the first of home page.
-``` js
+```js
<%- is_home_first_page() %>
```
@@ -309,7 +310,7 @@ Check whether the current page is the first of home page.
Check whether the current page is a post.
-``` js
+```js
<%- is_post() %>
```
@@ -317,7 +318,7 @@ Check whether the current page is a post.
Check whether the current page is a page.
-``` js
+```js
<%- is_page() %>
```
@@ -325,7 +326,7 @@ Check whether the current page is a page.
Check whether the current page is an archive page.
-``` js
+```js
<%- is_archive() %>
```
@@ -333,7 +334,7 @@ Check whether the current page is an archive page.
Check whether the current page is a yearly archive page.
-``` js
+```js
<%- is_year() %>
```
@@ -341,7 +342,7 @@ Check whether the current page is a yearly archive page.
Check whether the current page is a monthly archive page.
-``` js
+```js
<%- is_month() %>
```
@@ -350,7 +351,7 @@ Check whether the current page is a monthly archive page.
Check whether the current page is a category page.
If a string is given as parameter, check whether the current page match the given category.
-``` js
+```js
<%- is_category() %>
<%- is_category('hobby') %>
```
@@ -360,7 +361,7 @@ If a string is given as parameter, check whether the current page match the give
Check whether the current page is a tag page.
If a string is given as parameter, check whether the current page match the given tag.
-``` js
+```js
<%- is_tag() %>
<%- is_tag('hobby') %>
```
@@ -371,7 +372,7 @@ If a string is given as parameter, check whether the current page match the give
Removes prefixing and trailing spaces of a string.
-``` js
+```js
<%- trim(string) %>
```
@@ -379,13 +380,13 @@ Removes prefixing and trailing spaces of a string.
Sanitizes all HTML tags in a string.
-``` js
+```js
<%- strip_html(string) %>
```
**Examples:**
-``` js
+```js
<%- strip_html('It\'s not important anymore!') %>
// It's not important anymore!
```
@@ -394,13 +395,13 @@ Sanitizes all HTML tags in a string.
Transforms a string into proper title caps.
-``` js
+```js
<%- titlecase(string) %>
```
**Examples:**
-``` js
+```js
<%- titlecase('this is an apple') %>
# This is an Apple
```
@@ -409,13 +410,13 @@ Transforms a string into proper title caps.
Renders a string with Markdown.
-``` js
+```js
<%- markdown(str) %>
```
**Examples:**
-``` js
+```js
<%- markdown('make me **strong**') %>
// make me strong
```
@@ -424,13 +425,13 @@ Renders a string with Markdown.
Renders a string.
-``` js
+```js
<%- render(str, engine, [options]) %>
```
**Examples:**
-``` js
+```js
<%- render('p(class="example") Test', 'pug'); %>
//
Test
```
@@ -441,13 +442,13 @@ See [Rendering](https://hexo.io/api/rendering) for more details.
Wraps text into lines no longer than `length`. `length` is 80 by default.
-``` js
+```js
<%- word_wrap(str, [length]) %>
```
**Examples:**
-``` js
+```js
<%- word_wrap('Once upon a time', 8) %>
// Once upon\n a time
```
@@ -456,13 +457,13 @@ Wraps text into lines no longer than `length`. `length` is 80 by default.
Truncates text after certain `length`. Default is 30 characters.
-``` js
+```js
<%- truncate(text, [options]) %>
```
**Examples:**
-``` js
+```js
<%- truncate('Once upon a time in a world far far away', {length: 17}) %>
// Once upon a ti...
@@ -477,13 +478,13 @@ Truncates text after certain `length`. Default is 30 characters.
Escapes HTML entities in a string.
-``` js
+```js
<%- escape_html(str) %>
```
**Examples:**
-``` js
+```js
<%- escape_html('
Hello "world".
') %>
// <p>Hello "world".</p>
```
@@ -494,26 +495,26 @@ Escapes HTML entities in a string.
Loads other template files. You can define local variables in `locals`.
-``` js
+```js
<%- partial(layout, [locals], [options]) %>
```
-Option | Description | Default
---- | --- | ---
-`cache` | Cache contents (Use fragment cache) | `false`
-`only` | Strict local variables. Only use variables set in `locals` in templates. | `false`
+| Option | Description | Default |
+| ------- | ------------------------------------------------------------------------ | ------- |
+| `cache` | Cache contents (Use fragment cache) | `false` |
+| `only` | Strict local variables. Only use variables set in `locals` in templates. | `false` |
### fragment_cache
Caches the contents in a fragment. It saves the contents within a fragment and serves the cache when the next request comes in.
-``` js
+```js
<%- fragment_cache(id, fn);
```
**Examples:**
-``` js
+```js
<%- fragment_cache('header', function(){
return '';
}) %>
@@ -525,13 +526,13 @@ Caches the contents in a fragment. It saves the contents within a fragment and s
Inserts formatted date. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `date_format` setting by default.
-``` js
+```js
<%- date(date, [format]) %>
```
**Examples:**
-``` js
+```js
<%- date(Date.now()) %>
// 2013-01-01
@@ -543,13 +544,13 @@ Inserts formatted date. `date` can be unix time, ISO string, date object, or [Mo
Inserts date in XML format. `date` can be unix time, ISO string, date object, or [Moment.js] object.
-``` js
+```js
<%- date_xml(date) %>
```
**Examples:**
-``` js
+```js
<%- date_xml(Date.now()) %>
// 2013-01-01T00:00:00.000Z
```
@@ -558,13 +559,13 @@ Inserts date in XML format. `date` can be unix time, ISO string, date object, or
Inserts formatted time. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `time_format` setting by default.
-``` js
+```js
<%- time(date, [format]) %>
```
**Examples:**
-``` js
+```js
<%- time(Date.now()) %>
// 13:05:12
@@ -576,13 +577,13 @@ Inserts formatted time. `date` can be unix time, ISO string, date object, or [Mo
Inserts formatted date and time. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `date_format + time_format` setting by default.
-``` js
+```js
<%- full_date(date, [format]) %>
```
**Examples:**
-``` js
+```js
<%- full_date(new Date()) %>
// Jan 1, 2013 0:00:00
@@ -600,7 +601,7 @@ Inserts relative time from now. `date` can be unix time, ISO string, date object
**Examples:**
-``` js
+```js
<%- relative_date(new Date()) %>
// a few seconds ago
@@ -618,7 +619,7 @@ Inserts time tag. `date` can be unix time, ISO string, date object, or [Moment.j
**Examples:**
-``` js
+```js
<%- time_tag(new Date()) %>
//
@@ -636,25 +637,25 @@ Inserts time tag. `date` can be unix time, ISO string, date object, or [Moment.j
Inserts a list of all categories.
-``` js
+```js
<%- list_categories([options]) %>
```
-Option | Description | Default
---- | --- | ---
-`orderby` | Order of categories | name
-`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1
-`show_count` | Display the number of posts for each category | true
-`style` | Style to display the category list. `list` displays categories in an unordered list. Use `false` or any other value to disable it. | list
-`separator` | Separator between categories. (Only works if `style` is not `list`) | ,
-`depth` | Levels of categories to be displayed. `0` displays all categories and child categories; `-1` is similar to `0` but displayed in flat; `1` displays only top level categories. | 0
-`class` | Class name of category list. | category
-`transform` | The function that changes the display of category name. |
-`suffix` | Add a suffix to link. | None
+| Option | Description | Default |
+| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
+| `orderby` | Order of categories | name |
+| `order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 |
+| `show_count` | Display the number of posts for each category | true |
+| `style` | Style to display the category list. `list` displays categories in an unordered list. Use `false` or any other value to disable it. | list |
+| `separator` | Separator between categories. (Only works if `style` is not `list`) | , |
+| `depth` | Levels of categories to be displayed. `0` displays all categories and child categories; `-1` is similar to `0` but displayed in flat; `1` displays only top level categories. | 0 |
+| `class` | Class name of category list. | category |
+| `transform` | The function that changes the display of category name. |
+| `suffix` | Add a suffix to link. | None |
**Examples:**
-``` js
+```js
<%- list_categories(post.categories, {
class: 'post-category',
transform(str) {
@@ -674,31 +675,31 @@ Option | Description | Default
Inserts a list of all tags.
-``` js
+```js
<%- list_tags([options]) %>
```
-Option | Description | Default
---- | --- | ---
-`orderby` | Order of categories | name
-`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1
-`show_count` | Display the number of posts for each tag | true
-`style` | Style to display the tag list. `list` displays tags in an unordered list. Use `false` or any other value to disable it. | list
-`separator` | Separator between categories. (Only works if `style` is not `list`) | ,
-`class` | Class name of tag list (string) or customize each tag's class (object, see below). | tag
-`transform` | The function that changes the display of tag name. See examples in [list_categories](#list-categories). |
-`amount` | The number of tags to display (0 = unlimited) | 0
-`suffix` | Add a suffix to link. | None
+| Option | Description | Default |
+| ------------ | ----------------------------------------------------------------------------------------------------------------------- | ------- |
+| `orderby` | Order of categories | name |
+| `order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 |
+| `show_count` | Display the number of posts for each tag | true |
+| `style` | Style to display the tag list. `list` displays tags in an unordered list. Use `false` or any other value to disable it. | list |
+| `separator` | Separator between categories. (Only works if `style` is not `list`) | , |
+| `class` | Class name of tag list (string) or customize each tag's class (object, see below). | tag |
+| `transform` | The function that changes the display of tag name. See examples in [list_categories](#list-categories). |
+| `amount` | The number of tags to display (0 = unlimited) | 0 |
+| `suffix` | Add a suffix to link. | None |
Class advanced customization:
-Option | Description | Default
---- | --- | ---
-`class.ul` | `
` class name (only for style `list`) | `tag-list` (list style)
-`class.li` | `