Octopress 3.0

Basic usage of Octopress.

Install

rbenv

1
sudo apt install rbenv
1
2
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
CFLAGS="-Wno-error=implicit-function-declaration -Wcompound-token-split-by-macro" rbenv install 2.7.1

Then, append the following configs into your ~/.zshrc:

1
2
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
1
2
3
rbenv versions
rbenv local 2.7.1
rbenv local --unset

Gemfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
source "https://gems.ruby-china.com"

gem "jekyll", "~> 3.8.4"
gem 'octopress', '~> 3.0.0'
gem "minima", "~> 2.0"

group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
end

gem 'rdiscount', '~> 2.0'
gem 'sinatra', '~> 1.4.2'
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "wdm", "~> 0.1.0" if Gem.win_platform?

Bundler

https://bundler.io/guides/getting_started.html

1
2
3
4
bundle install
bundle clean --force

bundle update --bundler

Usage

new post

1
bundle exec octopress new post hello -D Ruby

build

Here we set JEKYLL_ENV=production to enable google_analytics and disqus.

1
2
export JEKYLL_ENV=production
bundle exec jekyll serve

deploy

1
2
3
bundle exec jekyll build
bundle exec octopress deploy

_config.yml(default) 中配置了 jekyll build 时将静态文件生成到哪里:

1
2
source              : .
destination : ./_site

_deploy.yml 中配置了 octopress deploy 时将存放在哪里的静态文件发布到哪里:

1
2
3
4
5
6
7
site_dir: _site                           # Location of your static site files.

# Note on git_branch:
# If using GitHub project pages, set the branch to 'gh-pages'.
# For GitHub user/organization pages or Heroku, set the branch to 'master'.
#
git_branch: master # Git branch where static site files are commited

GitHub Pages Settings 里配置了 GitHub 用于网页渲染的静态文件来源:

1
Your GitHub Pages site is currently being built from the master branch. Learn more.

source

源码和网站是在同一个 repo 的不同 branch 底下的。

1
2
3
git add .
git commit -m "$(date)"
git push origin source

Theme

https://jekyllrb.com/docs/themes/

https://github.com/jekyll/minima

layouts

1
2
ls $(bundle show minima)/_layouts
ls $(bundle show minima)/_includes
1
vi $(bundle show minima)/_includes/header.html
1
vi $(bundle show minima)/_includes/footer.html

Extension

disqus

1
2
disqus:
shortname: my_disqus_shortname

google_analytics

1
google_analytics: UA-NNNNNNNN-N

Config

_config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
title:  Secret Base
author: Zhengyang Song
email: songzy.thu@gmail.com
description: >- # this means to ignore newlines until "baseurl:"
All those little bugs I have ever met.
baseurl: "" # the subpath of your site, e.g. /blog
url: "http://songzy12.github.io" # the base hostname & protocol for your site, e.g. http://example.com
github_username: songzy12

# Default extension for new posts and pages
post_ext: md
page_ext: html

# Default templates for posts and pages
# Found in _templates/
post_layout: post
page_layout: page

# Format titles with titlecase?
titlecase: true

# Change default template file (in _templates/)
post_template: post
page_template: page
draft_template: draft

# Build settings
markdown: rdiscount
rdiscount:
extensions:
- autolink
- footnotes
- smart
theme: minima
plugins:
- jekyll-feed

header_pages:
- about.md

show_excerpts: true

google_analytics: UA-147981013-1

disqus:
shortname: songzy12-github-io