diff --git a/.gitignore b/.gitignore index 6f9fe6b..44aff8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .DS_Store .nyc_output +.vscode \ No newline at end of file diff --git a/README.md b/README.md index b1e1c94..f5007ee 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ > a JavaScript static site generator with support for WordPress ## Usage + ### CLI + ```shell $ tobiko $ tobiko -h @@ -20,6 +22,7 @@ Options: ``` ### API + ```js const tobiko = require('tobiko'); const conf = require('./tobiko.js'); @@ -27,39 +30,44 @@ tobiko(conf); ``` ### Config file + By default, the CLI `tobiko` will look for `tobiko.json`. If dynamic options are needed, they can be declared in a JavaScript file: ```js // tobiko.js module.exports = { - contentsDir: 'contents', - outDir: 'dist', - handlebars: { - templatesDir: 'templates', - partialsDir: 'templates/partials', - helpersDir: 'templates/helpers' - }, - plugins: { - wordpress: { - apiRoot: 'https://mywordpress.com/wp-json/wp/v2', - contents: [{ - postType: 'posts', - folder: 'articles', - template: 'article.hbs' - }] - }, - archive: { - articles: { - postsPerPage: 4, - title: 'Articles', - template: 'articles.hbs' - } - }, - transform: function (contentTree) { - // do something with the content object - return Promise.resolve(contentTree) - } - } + outDir: 'dist', + handlebars: { + templatesDir: 'templates', + partialsDir: 'templates/partials', + helpersDir: 'templates/helpers' + }, + plugins: { + files: { + contentsDir: 'contents' + }, + wordpress: { + apiRoot: 'https://mywordpress.com/wp-json/wp/v2', + contents: [ + { + postType: 'posts', + folder: 'articles', + template: 'article.hbs' + } + ] + }, + archive: { + articles: { + postsPerPage: 4, + title: 'Articles', + template: 'articles.hbs' + } + }, + transform: function(contentTree) { + // do something with the content object + return Promise.resolve(contentTree); + } + } }; ``` @@ -68,24 +76,24 @@ $ tobiko -f tobiko.js ``` ## What's supported -- Content: JSON / Markdown (optionally with YAML frontmatter) / WordPress (through WP REST API) -- Template: Handlebars -- Styles: SCSS -- JavaScript: browserify (but it can really be anything) + +* Content: JSON / Markdown (optionally with YAML frontmatter) / WordPress (through WP REST API) +* Template: Handlebars +* Styles: SCSS +* JavaScript: browserify (but it can really be anything) ## Documentation ### Options -- `contentsDir`: where the site's contents are located. Defaults to `contents`. -- `outDir`: where to generate the static files to. Defaults to `dist`. -- `handlebars`: Handlebars configuration options. - - `templatesDir`: location of the templates directory. Defaults to `templates`. - - `partialsDir`: location of template partials. Defaults to `templates/partials`. - - `helpersDir`: location of template helpers. Defaults to `templates/helpers`. -- `plugins`: configuration for plugins. See [plugins](#plugins) for more info. +* `contentsDir`: where the site's contents are located. Defaults to `contents`. +* `outDir`: where to generate the static files to. Defaults to `dist`. +* `handlebars`: Handlebars configuration options. + * `templatesDir`: location of the templates directory. Defaults to `templates`. - `partialsDir`: location of template partials. Defaults to `templates/partials`. - `helpersDir`: location of template helpers. Defaults to `templates/helpers`. +* `plugins`: configuration for plugins. See [plugins](#plugins) for more info. ### Contents + By default, the site content will be in the `contents` folder. This option could be changed in `tobiko.json`, under `contentDir` property. Content can be written in `json` and `markdown` with `yaml` [frontmatter](https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter). @@ -93,32 +101,37 @@ Content can be written in `json` and `markdown` with `yaml` [frontmatter](https: The structure of the `contents` directory will be reflected in the final static HTML output. #### config.json + High level, site-wide configurations can be specified in `config.json` in the root folder. Environment-specific configurations are also supported. For example: `config.json` + ```json { - "site-name": "Tobiko Example", - "site-url": "http://tobiko.io", - "author": "Sushi Connoisseur" + "site-name": "Tobiko Example", + "site-url": "http://tobiko.io", + "author": "Sushi Connoisseur" } ``` `config.dev.json` + ```json { - "site-url": "http://localhost:4000", + "site-url": "http://localhost:4000" } ``` Environment-specific settings cascade over the original config. This allows you to declare only the different parameters. #### Nesting + In any directory, a file's sibling files and directories are available for the template to access. This is a convenient and structural way to store and organize data, instead of dumping everything into a single JSON file. For example, for this file structure + ``` contents ├── index.json @@ -133,10 +146,13 @@ contents ``` If you're writing the template for `index.json`, its own content is available through the `content` variable. + ```html

{{content.title}}

``` + And `cars` are also available as + ```html