Content
Installation
$ cargo install cobalt-bin
Examples
cobalt
. Here is a list of projects and their source code that use cobalt
.Usage
$ cobalt new myBlog
$ cobalt build -s myBlog -d path/to/your/destination
$ cobalt -h
Layouts
_layouts
directory.Posts
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.extends: posts.liquid
title: My first Blogpost
date: 01 Jan 2016 21:00:00 +0100
---
Hey there this is my first blogpost and this is super awesome.
My Blog is lorem ipsum like, yes it is..
---
are meta attributes ("front matter") made accessible to the template via their key (see below).extends
attribute specifies which layout will be used.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
.Drafts
--drafts
flag.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.Other files
_posts
directory will not be indexed as blog posts and not passed to the index file in the list of contents.template_extensions
field in your config file:template_extensions: ['txt', 'lqd']
Custom paths
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.extends: posts.liquid
title: My first Blogpost
path: /some/other/path/
your-website.com/some/other/path/index.html
.post_path
in your .cobalt.yml that will be used for all posts.date
attribute you have access to several other custom attributes. See the Jekyll documentation.date: 01 Jan 2016 21:00:00 +0100
path: /:year/:month/:day/thing.html
/2016/01/01/thing.html
date: 01 Jan 2016 21:00:00 +0100
author: johann
path: /:author/:year/:month/:day/title
/johann/2016/01/01/title/index.html
Attributes
{{ title }}
and date via {{ date }}
, for the layout template as well as the post template.Special Attributes
content
{{ content }}
is accessible only to layouts and contains the compiled text below the ---
block of the post.posts
{{ 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 %}
<a href="{{post.path}}">{{ post.title }}</a>
{% endfor %}
RSS
_posts
, you need to provide the following data in your config.file:# path where the RSS file should be generated
rss: rss.xml
name: My blog!
description: Blog description
link: http://example.com
title
, date
and description
in the front matter of your posts.Import
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
.Deployment
With Travis CI
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:sudo: false
language: rust
before_script:
- cargo install cobalt-bin
- 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
GH_TOKEN
you will need to create a personal access token, which can be found here, then you will need to use the travis cli tool to encrypt your personal access token. You can do this like so travis encrypt GH_TOKEN=... --add env.global
With GitLab CI
cobalt
in PATH
..gitlab-ci.yml
:image: nott/cobalt:latest
pages:
script:
- mkdir -p public
- cobalt build -d public
artifacts:
paths:
- public/
only:
- master
from https://github.com/cobalt-org/cobalt.rs
----------------------
我的补充说明:
curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
cargo install cobalt-bin (此步耗时40分钟)
会显示:
...
Installing /root/.cargo/bin/cobalt
warning: be sure to add `/root/.cargo/bin` to your PATH to be able to run the installed binaries.
于是,编辑/etc/profile文件,在其最下面加上:
export PATH=$PATH:/root/.cargo/bin
然后source /etc/profile
至此,cobalt安装完毕。
cd /usr/local
cobalt new cobalt-site (此命令会在当前目录下,生成cobalt-site目录)
cd cobalt-site
root@AR:/usr/local/cobalt-site# ls
index.liquid _layouts posts
root@AR:/usr/local/cobalt-site# cobalt build -s . -d output
(此命令的意思是源目录为当前目录,输出目录为output目录。此命令会在当前目录下,生成output目录。此命令就是生成/更新静态网站的根目录的命令)
root@AR:/usr/local/cobalt-site# ls
index.liquid _layouts output posts
(生成了output 目录)
root@AR:/usr/local/cobalt-site# cd output
root@AR:/usr/local/cobalt-site/output# ls
index.html posts
root@AR:/usr/local/cobalt-site/output#
(可见/usr/local/cobalt-site/output就是静态网站的根目录)
新建源帖:
root@AR:/usr/local/cobalt-site/output# cd ../posts
root@AR:/usr/local/cobalt-site/posts# nano test-1.md
root@AR:/usr/local/cobalt-site/posts# cat test-1.md
extends: default.liquid
title: 测试1
date: 21 November 2016 21:25:30 -0500
---
这是测试1.
看看如何?
root@AR:/usr/local/cobalt-site/posts# cd ..
root@AR:/usr/local/cobalt-site# cobalt build -s . -d output
演示网站:http://cr.bright.biz.st (不过,这样建立的网站很简陋,连css文件都没有。而且显示的中文是乱码,须设置浏览器的编码为utf-8,才能正常浏览。)
下面克隆别人的第一个修改版:
root@AR:/usr/local/cobalt-site# cd ..
root@AR:/usr/local# git clone https://github.com/johannhof/johannhof.github.io
root@AR:/usr/local# cd johannhof.github.io
root@AR:/usr/local/johannhof.github.io# cobalt build -s . -d output
root@AR:/usr/local/johannhof.github.io# cd output
root@AR:/usr/local/johannhof.github.io/output#
(/usr/local/johannhof.github.io/output就是静态网站的根目录)
新建源帖:
root@AR:/usr/local/johannhof.github.io/output# cd ..
root@AR:/usr/local/johannhof.github.io# cd blog
root@AR:/usr/local/johannhof.github.io/blog# nano test-1.md
root@AR:/usr/local/johannhof.github.io/blog# cat test-1.md
extends: post.liquid
title: 测试1
date: 22 November 2016 13:17:00 +0100
route: blog
---
这是测试1.
看看如何?
root@AR:/usr/local/johannhof.github.io/blog#
root@AR:/usr/local/johannhof.github.io/blog# cd ..
root@AR:/usr/local/johannhof.github.io# cobalt build -s . -d output
演示网站:http://jh.bright.biz.st
项目地址:https://github.com/johannhof/johannhof.github.io
第二个修改版
cd /usr/local/
git clone https://github.com/amethyst/website amethyst-website
cd amethyst-website
root@AR:/usr/local/amethyst-website# ls
generate.sh LICENSE.md README.md src TWIA_TEMPLATE.md
root@AR:/usr/local/amethyst-website# cd src
root@AR:/usr/local/amethyst-website/src# ls
assets css doc index.liquid _layouts posts
root@AR:/usr/local/amethyst-website/src# cobalt build -s . -d output
root@AR:/usr/local/amethyst-website/src# ls
assets css doc index.liquid _layouts output posts
root@AR:/usr/local/amethyst-website/src# cd output
root@AR:/usr/local/amethyst-website/src/output#
(/usr/local/amethyst-website/src/output就是静态网站的根目录)
新建源帖:
root@AR:/usr/local/amethyst-website/src/output# cd ..
root@AR:/usr/local/amethyst-website/src# cd posts
root@AR:/usr/local/amethyst-website/src/posts# nano test-1.md
root@AR:/usr/local/amethyst-website/src/posts# cat test-1.md
extends: default.liquid
title: 测试1
date: 22 November 2016 15:18:00 -0600
---
这是测试1.
看看如何?
root@AR:/usr/local/amethyst-website/src/posts# cd ..
root@AR:/usr/local/amethyst-website/src# cobalt build -s . -d output
演示网站:http://amt.bright.biz.st
项目地址:https://github.com/amethyst/website
Installation
Download a release.
or
$ curl -LSfs https://raw.githubusercontent.com/crate-ci/gh-install/master/v1/install.sh | sh -s -- --git cobalt-org/cobalt.rs --crate cobalt
Usage
Start
Create a site with an example pages, posts, and layouts:
$ mkdir myBlog && cd myBlog
$ cobalt init
Preview
To serve your site locally, run:
$ cobalt serve
Building from `.` into `/tmp/.tmpgYpScM`
Watching . for changes
Serving /tmp/.tmpgYpScM through static file server
Server Listening on http://localhost:1024
Ctrl-c to stop the server
Add a Page
Add a new page or post to your site:
$ cobalt new "Cats Around the World"
A file cats-around-the-world.md
will be created in the current directory.
The type of file created is based on which directory you put it in.
Posts start out as "drafts". For them to show up on serve
, you'll need to
pass the --drafts
flag:
$ cobalt serve --drafts
Publish a Post
Once your post is ready, you can publish it:
$ cobalt publish posts/cats-around-the-world.md
The page will no longer be a "draft" and the published_date
will be set to today.
Build the site
Once the post is in published state, build the site:
$ cobalt build
The site is sitting in _site
and ready to be uploaded!
from https://cobalt-org.github.io/getting-started/