2015-12-07 16:03:02 +00:00
# ![Cobalt](https://raw.githubusercontent.com/cobalt-org/logos/master/cobald.logo.02.resize.png)
2016-07-25 10:30:23 +00:00
[![ ](https://img.shields.io/crates/v/cobalt-bin.svg?maxAge=25920 )](https://crates.io/crates/cobalt-bin)
[![ ](https://travis-ci.org/cobalt-org/cobalt.rs.svg?branch=master )](https://travis-ci.org/cobalt-org/cobalt.rs) [![ ](https://ci.appveyor.com/api/projects/status/gp2mmvk8dpe8wsmi/branch/master?svg=true )](https://ci.appveyor.com/project/johannhof/cobalt-rs/branch/master)
2015-12-07 16:03:02 +00:00
[![ ](https://coveralls.io/repos/cobalt-org/cobalt.rs/badge.svg?branch=master&service=github )](https://coveralls.io/github/cobalt-org/cobalt.rs?branch=master)
2016-07-25 10:30:23 +00:00
[![ ](https://badges.gitter.im/Join%20Chat.svg )](https://gitter.im/cobalt-org/cobalt.rs?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge)
2014-10-24 10:41:07 +00:00
2015-04-13 05:57:21 +00:00
A static site generator written in [Rust ](http://www.rust-lang.org/ ).
2014-10-25 22:14:35 +00:00
2016-05-15 17:51:13 +00:00
## Content
- [Installation ](#installation )
- [Examples ](#examples )
- [Usage ](#usage )
- [Layouts ](#layouts )
- [Posts ](#posts )
- [Other Files ](#other-files )
- [Attributes ](#attributes )
- [RSS ](#rss )
- [Import ](#import )
- [Deployment ](#deployment )
2016-10-08 05:47:50 +00:00
- [Travis CI ](#with-travis-ci )
2016-10-08 05:47:04 +00:00
- [GitLab CI ](#with-gitlab-ci )
2016-05-15 17:51:13 +00:00
2015-04-22 22:23:10 +00:00
## Installation
2015-10-02 07:49:19 +00:00
```
2016-07-06 12:50:18 +00:00
$ cargo install cobalt-bin
2015-10-02 07:49:19 +00:00
```
2015-06-11 11:19:07 +00:00
2016-04-05 16:21:46 +00:00
## Examples
There are a few people already using `cobalt` . Here is a list of projects and their source code that use `cobalt` .
- [tak1n.github.io ](https://tak1n.github.io ) [Source ](https://github.com/tak1n/tak1n.github.io )
2016-05-15 17:51:13 +00:00
- [amethyst.rs ](https://amethyst.rs ) [Source ](https://github.com/amethyst/website )
2016-04-23 05:38:46 +00:00
- [johannh.me ](http://johannh.me ) [Source ](https://github.com/johannhof/johannhof.github.io )
2016-06-13 10:07:41 +00:00
- [kstep.me ](http://kstep.me ) [Source ](https://github.com/kstep/kstep.github.com )
2016-04-05 16:21:46 +00:00
2014-10-27 09:34:55 +00:00
## Usage
2014-10-24 10:41:07 +00:00
2015-11-06 20:47:03 +00:00
```
2016-05-15 18:09:32 +00:00
$ cobalt new myBlog
$ cobalt build -s myBlog -d path/to/your/destination
2015-11-06 20:47:03 +00:00
```
See more options with
```
$ cobalt -h
```
2015-04-13 05:57:21 +00:00
### Layouts
2014-10-24 10:41:07 +00:00
2015-04-13 05:57:21 +00:00
You can have custom layouts in the ```_layouts``` directory.
2014-10-24 10:41:07 +00:00
2015-04-13 05:57:21 +00:00
Layouts will be compiled as [liquid ](https://github.com/cobalt-org/liquid-rust ) templates.
2014-10-25 12:43:16 +00:00
2014-10-24 10:41:07 +00:00
### Posts
2016-07-03 17:33:08 +00:00
Posts live in `posts` by default, but you can use a different directory for posts with the `-p` flag or by setting the `posts` variable in your .cobalt.yml.
2014-10-24 11:14:03 +00:00
Example:
2016-05-21 17:34:55 +00:00
```yaml
2016-03-31 10:21:16 +00:00
extends: posts.liquid
2014-10-27 09:34:55 +00:00
2014-10-24 11:14:03 +00:00
title: My first Blogpost
2016-01-16 20:40:48 +00:00
date: 01 Jan 2016 21:00:00 +0100
2014-10-24 11:14:03 +00:00
---
Hey there this is my first blogpost and this is super awesome.
My Blog is lorem ipsum like, yes it is..
```
2016-02-17 20:39:44 +00:00
The content before ```---``` are meta attributes ("front matter") made accessible to the template via their key (see below).
2014-10-24 11:14:03 +00:00
2016-01-15 21:22:12 +00:00
The ```extends``` attribute specifies which layout will be used.
2014-10-27 09:34:55 +00:00
2016-01-16 20:40:48 +00:00
The ```date``` attribute will be used to sort blog posts (from last to first). ```date``` must have the format `%dd %Mon %YYYY %HH:%MM:%SS %zzzz` , so for example `27 May 2016 21:00:30 +0100` .
2016-08-09 21:04:24 +00:00
#### Drafts
Cobalt supports leaving posts in "draft" state. Drafts will not be rendered unless Cobalt is run with the `--drafts` flag.
To mark a post as draft you can either set `draft: true` in your front matter or add it to the drafts folder (`_drafts` by default). The draft folder location can be specified using the `draft` key in your .cobalt.yml.
2015-04-13 05:57:21 +00:00
### Other files
2014-10-24 11:14:03 +00:00
2016-03-31 10:21:16 +00:00
Any file with the .md or .liquid file extension is considered a liquid template and will be parsed for metadata and compiled using liquid, like a post.
2014-10-24 11:14:03 +00:00
2015-04-13 05:57:21 +00:00
Unlike posts, files outside the ``_posts`` directory will not be indexed as blog posts and not passed to the index file in the list of contents.
All other files and directories in the source folder will be recursively added to your destination folder.
2016-03-03 07:45:04 +00:00
You can specify different template extensions by setting the `template_extensions` field in your config file:
```yaml
template_extensions: ['txt', 'lqd']
```
2016-05-21 17:34:55 +00:00
#### Custom paths
Custom paths are much like permalinks in Jekyll, but with a bit more flexibility. You can specify a `path` attribute in the front matter of
any document to give it a custom path. The path is always relative to the document root, independent of where the file is located.
Example:
```yaml
extends: posts.liquid
title: My first Blogpost
path: /some/other/path/
```
would result in a file with the url `your-website.com/some/other/path/index.html` .
2016-07-03 17:33:08 +00:00
You can also set a global attribute `post_path` in your .cobalt.yml that will be used for all posts.
2016-05-21 17:34:55 +00:00
Any attribute in the front matter can be interpolated into the path. If you set a `date` attribute you have access to several other custom attributes. See the Jekyll documentation.
More examples:
```yaml
date: 01 Jan 2016 21:00:00 +0100
path: /:year/:month/:day/thing.html
```
-> `/2016/01/01/thing.html`
```yaml
date: 01 Jan 2016 21:00:00 +0100
author: johann
path: /:author/:year/:month/:day/title
```
-> `/johann/2016/01/01/title/index.html`
2015-04-13 05:57:21 +00:00
### Attributes
All template files have access to a set of attributes.
In example above _title_ is accessible via ```{{ title }}``` and _date_ via ```{{ date }}```, for the layout template as well as the post template.
2015-04-22 22:08:30 +00:00
### Special Attributes
#### content
`{{ content }}` is accessible only to layouts and contains the compiled text below the ```---``` block of the post.
#### posts
2016-01-16 20:40:48 +00:00
`{{ posts }}` is a list of the attributes of all templates in the `_posts` directory. Example usage on a page listing all blog posts:
```
{% for post in posts %}
2016-05-21 17:34:55 +00:00
< a href = "{{post.path}}" > {{ post.title }}< / a >
2016-01-16 20:40:48 +00:00
{% endfor %}
```
2016-02-17 20:39:44 +00:00
### RSS
To generate an RSS file from the metadata of your `_posts` , you need to provide the following data in your config.file:
```yaml
# path where the RSS file should be generated
rss: rss.xml
name: My blog!
description: Blog description
link: http://example.com
```
None of these fields are optional, as by the [RSS 2.0 spec]().
Make sure to also provide the fields `title` , `date` and `description` in the front matter of your posts.
2016-05-09 16:47:15 +00:00
### Import
To import your site to your `gh-pages` branch you can either pass a `build --import` flag when you build the site or after you have build the site with `build` you can run `import` . There are also some flags that can be found via `import --help` .
2016-05-15 17:51:13 +00:00
## Deployment
2016-10-08 05:47:50 +00:00
### With Travis CI
2016-05-15 17:51:13 +00:00
2016-10-07 11:12:09 +00:00
You can easily deploy a cobalt site to `gh-pages` ! To do this with travis is also very easy. You will need to have rust available on travis. In your `travis.yml` you will need to have something similar to this:
2016-05-15 17:51:13 +00:00
```yaml
sudo: false
language: rust
before_script:
2016-07-06 16:13:39 +00:00
- cargo install cobalt-bin
2016-05-15 17:51:13 +00:00
- export PATH="$PATH:/home/travis/.cargo/bin"
script:
- cobalt build
after_success: |
[ $TRAVIS_BRANCH = master ] & &
[ $TRAVIS_PULL_REQUEST = false ] & &
cobalt import & &
git config user.name "Cobalt Site Deployer" & &
git config user.email "name@example.com" & &
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
```
2016-05-15 18:04:33 +00:00
For the `GH_TOKEN` you will need to create a personal access token, which can be found [here ](https://github.com/settings/tokens ), then you will need to use the [travis cli ](https://github.com/travis-ci/travis.rb#the-travis-client- ) tool to encrypt your personal access token. You can do this like so `travis encrypt GH_TOKEN=... --add env.global`
2016-05-15 18:02:22 +00:00
2016-10-07 11:12:09 +00:00
### With GitLab CI
You can also deploy a cobalt site to [GitLab Pages ](http://pages.gitlab.io/ ) using GitLab CI. GitLab CI uses [Docker ](https://docs.docker.com/ ), you can use [nott/cobalt ](https://hub.docker.com/r/nott/cobalt/ ) or any other image with `cobalt` in `PATH` .
An example of `.gitlab-ci.yml` :
```yaml
image: nott/cobalt:latest
pages:
script:
- mkdir -p public
- cobalt build -d public
artifacts:
paths:
- public/
only:
- master
```