准备工作
- 在 jekyll 用户下运行
- gem jekyll 安装好
- 安装好 rouge
gem install kramdown rouge
$ gem -v
3.0.8
$ jekyll -v
jekyll 4.2.0
创建站点 myblog
执行命令 jekyll new myblog
,新建站点 myblog
$ jekyll new myblog
Running bundle install in /usr/home/jekyll/myblog...
Bundler: Fetching gem metadata from https://rubygems.org/..........
Bundler: Resolving dependencies...
Bundler: Using public_suffix 4.0.6
Bundler: Fetching addressable 2.8.0Bundler::PermissionError: There was an error while trying to write to
Bundler: `/usr/local/lib/ruby/gems/2.7/cache/addressable-2.8.0.gem`. It is likely that
Bundler: you need to grant write permissions for that path.
Bundler: An error occurred while installing addressable (2.8.0), and Bundler cannot
Bundler: continue.
Bundler: Make sure that `gem install addressable -v '2.8.0' --source
Bundler: 'https://rubygems.org/'` succeeds before bundling.
Bundler:
Bundler: In Gemfile:
Bundler: minima was resolved to 2.5.1, which depends on
Bundler: jekyll-feed was resolved to 0.15.1, which depends on
Bundler: jekyll was resolved to 4.2.0, which depends on
Bundler: addressable
查看myblog文件
$ ls myblog/
404.html Gemfile _config.yml _posts about.markdown index.markdown
安装主题 themes
配置Gemfile,追加如下内容:
# Gem install themes
gem "minimal-mistakes-jekyll"
gem "just-the-docs"
gem "jekyll-theme-simplex"
这样,我们就有4个主题:minima
(default)、minimal-mistakes-jekyll
、just-the-docs
、jekyll-theme-simplex
以root用户执行命令bundle
,获取/升级 gems
root@VM-0-8-freebsd:/usr/home/jekyll/myblog # bundle
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
... 省略 ...
Bundle complete! 9 Gemfile dependencies, 52 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
通过gem list --local
可以查看到刚才安装主题的gem包。
通过bundle info --path $theme_name
查看安装的主题,可以看到都安装在/usr/local/lib/ruby/gems/2.7/gems/
目录下,与CentOS不同。如下:
$ bundle info --path minima
/usr/local/lib/ruby/gems/2.7/gems/minima-2.5.1
$ bundle info --path minimal-mistakes-jekyll
/usr/local/lib/ruby/gems/2.7/gems/minimal-mistakes-jekyll-4.24.0
$ bundle info --path just-the-docs
/usr/local/lib/ruby/gems/2.7/gems/just-the-docs-0.3.3
$ bundle info --path jekyll-theme-simplex
/usr/local/lib/ruby/gems/2.7/gems/jekyll-theme-simplex-0.9.8.15
配置使用主题
配置 _config.yml
# Build settings
#theme: minima
theme: minimal-mistakes-jekyll
#theme: just-the-docs
#theme: jekyll-theme-simplex
更新主题
以 jekyll
用户执行 bundle update
$ bundle update
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
... 省略 ...
Using jekyll-theme-simplex 0.9.8.15
Using just-the-docs 0.3.3
Using minima 2.5.1
Using minimal-mistakes-jekyll 4.24.0
Bundle updated!
配置监听端口
配置 _config.yml
,增加如下:
# Serving
host: 0.0.0.0
配置markdown
安装 rouge
gem install kramdown rouge
配置_config.yml
markdown: kramdown
highlighter: rouge
kramdown:
input: GFM
syntax_highlighter: rouge
rouge创建css文件,在当前站点目录下
mkdir -p assets/css/
rougify style thankful_eyes > assets/css/syntax.css
修改index.markdown,指定引用layout;创建被指定引用的layout,指定引用includes/markdown.html;创建_includes/markdonw.html , 引用rouge创建的css文件
mkdir _layouts
mkdir _includes
启动jekyll
-
jekyll build
编译,并将静态文件输出到 _site 目录
$ jekyll build
Configuration file: /usr/home/jekyll/myblog/_config.yml
Source: /usr/home/jekyll/myblog
Destination: /usr/home/jekyll/myblog/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
Build Warning: Layout 'post' requested in _posts/2021-09-10-welcome-to-jekyll.markdown does not exist.
Build Warning: Layout 'page' requested in about.markdown does not exist.
done in 1.123 seconds.
Auto-regeneration: disabled. Use --watch to enable.
- 在myblog目录,执行启动命令
nohup bundle exec jekyll serve --livereload &
,如下:
$ nohup bundle exec jekyll serve --livereload &
$ appending output to nohup.out
$ ls
404.html Gemfile Gemfile.lock _config.yml _posts _site about.markdown index.markdown nohup.out
- 检查端口,运行于本地的4000,35729端口
$ netstat -4an
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 *.35729 *.* LISTEN
tcp4 0 0 *.4000 *.* LISTEN
tcp4 0 52 172.17.0.8.1984 183.195.89.93.12194 ESTABLISHED
tcp4 0 0 172.17.0.8.1984 183.195.89.93.12056 ESTABLISHED
tcp4 0 0 *.1984 *.* LISTEN
tcp4 0 0 *.80 *.* LISTEN
tcp4 0 0 127.0.0.1.25 *.* LISTEN
udp4 0 0 *.514 *.*