前两天无意间看到一个部署 Octopress 的教程, 今天终于抽出时间折腾了一下.
因为对 Git、Rudy 和 HTML 没啥了解,遇到很多问题,所以先把今后可能用到的语法总结一下。
Octopress文档链接

代码高亮的 Syntax

1
2
[language] [title] [url] [link text]
code snippet
1
2
3
4
struct Range<T> {
var startIndex:T
var endIndex:T
}

有些占位符在实际使用过程中可以被省略,比如目前不太常用的 url,可以帮助指向示例代码的详细内容链接,并且可以定位超链接的名字。

如果希望在文章中插入某个 swift 文件,用以呈现代码块,可使用:

1
{% include_code [title] [lang:language] path/to/file %}

这里的系统默认会读取source/downloads/code路径下的代码文件(此路径可通过配置_config.yml文件进行修改),同时,这里的 title 不是用来自定义的,而是需要输入文件的名字,并包含其扩展名.

1
{% include_code FilterHelper.swift %}

实现方法.

##新建文章

1
$ sudo rake new_post["title"]

new_post 会自动创建一个自定义 title 的 markdown 文件, 并且将中文字符转成拼音用已生成文章的 HTML链接.

文章自动生成一些关键内容:

1
2
3
4
5
6
layout: post
title: "Zombie Ninjas Attack: A survivor's retrospective"
date: 2011-07-03 5:59
comments: true
external-url:
categories:

如果希望这篇文章暂时以草稿的形式存在,可添加 published: false 阻止其公开.

1
2
3
4
5
6
7
8
9
10
11
// One category
categories: Sass
// Multiple categories example 1
categories: [CSS3, Sass, Media Queries]
// Multiple categories example 2
categories:
- CSS3
- Sass
- Media Queries

categories 的配置我理解类似文章的 tag, 可以利用一些关键字方便归类.

##为文章增加新页面

1
2
3
4
rake new_page[super-awesome]
//creates /source/super-awesome/index.markdown
rake new_page[super-awesome/page.html]
creates /source/super-awesome/page.html

感觉自己最近用不到,链接指向官方文档,需要的时候再实验具体内容.

##文章内容

在文章内插入<!-- more -->可以实现”点击此处”展开文章内容.

##生成文章

1
2
3
rake generate // Generates posts and pages into the public directory
rake watch // Watches source/ and sass/ for changes and regenerates
rake preview // Watches, and mounts a webserver at http://localhost:4000

如果希望文章不被公开,在文章头信息中添加published: false,并利用rake preview进行本地浏览.
文章编辑结束,利用rake generate将文章从 source 移到 public,并使用 git 指令 commit 到远程 Hub.

1
sudo git push heroku master

##终端使用 Tips

1
$ls 展示目录详情