Loading...

Loading...

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.

box.process().then(function () {
  // ...
});

box.watch().then(function () {
  // You can call box.unwatch() later to stop watching.
});

Path Matching

Box provides many ways for path matching. You can use a regular expression, a function or an Express-style pattern string. For example:

posts/:id => posts/89
posts/*path => posts/2015/title

See util.Pattern for more info.

Processors

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.

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:

AttributeDescription
sourceFull path of the file
pathRelative path to the box of the file
typeFile type. The value can be create, update, skip, delete.
paramsThe information from path matching.

Box also provides some methods so you don’t have to do file IO by yourself.

MethodDescription
readRead a file
readSyncRead a file synchronously
statRead the status of a file
statSyncRead the status of a file synchronously
renderRender a file
renderSyncRender a file synchronously
Comments
Data Loading...