用Pelican和Github Pages在Linux上搭建我的博客

搭建环境

Linux环境下搭建,采用ubuntu,使用其它发行版过程基本相同。html

Github Pages

  • 注册Github,注册和配置SSH密钥过程help page写得很清楚。
  • 不过如今github支持http传输良好,因此也能够不用配置SSH,经过用户名密码便可登陆。
  • 在Github建立一个名为username.github.io的版本库(将username替换成本身的Github帐户名)。
  • Setting -> Automatic page generator -> Continue to layout,选择一个模板,并发布。

十分钟后在username.github.io页面就已经生成了一个页面。访问该网址便可看到。python

配置本地环境

安装Pelican和Markdown:

在这里我没有用Jekyll由于它是Ruby写的对它没什么兴趣。因此我采用Python编写的Pelicangit

介绍

Pelican是一套开源的使用Python编写的博客静态生成, 能够添加文章和和建立页面, 可使用MarkDown reStructuredTextAsiiDoc 的格式来抒写, 同时使用 Disqus评论系统, 支持 RSSAtom输出, 插件, 主题, 代码高亮等功能, 采用Jajin2模板引擎, 能够很容易的更改模板github

安装

安装Pelican有不少种方法。一种使用python的包管理器pip进行安装。web

$sudo apt-get install python-pip
$sudo pip install pelican
$sudo pip install markdown

另外一种就是从github上克隆Pelicanbootstrap

git clone git://github.com/getpelican/pelican.git       
cd pelican
python setup.py install

写第一篇博客

搭建目录

mkdir blog
cd blog
pelican-quickstart

在回答一系列问题事后你的博客就建成的, 主要生成下列文件:
生成的目录结构:ubuntu

blog/
├── content
│   └── *.md             # markdown文件
├── output               # 默认的输出目录
├── develop_server.sh
├── Makefile
├── pelicanconf.py       # 主配置文件
└── publishconf.py

写一篇文章

content目录新建一个 test.md文件, 填入一下内容:浏览器

Title: 文章标题
Date: 2013-04-18
Category: 文章类别
Tag: 标签1, 标签2
这里是内容

而后执行服务器

make html

生成了html。而后执行markdown

./develop_server.sh start

开启一个测试服务器, 这会在本地 8000 端口创建一个测试web服务器, 可使用浏览器打开:http://localhost:8000来访问这个测试服务器, 而后就能够欣赏到你的博客了

建立一个About页面

这里以建立 About页面为例

content目录建立pages目录

mkdir content/pages

而后建立About.md并填入下面内容

Title: About Me
Date: 2013-04-18

About me content

执行 make html 生成html, 而后打开http://localhost:8000查看效果

使用Pelican支持评论

使用Disqus做为评论系统,注册账号后直接在pelicanconf.conf中添加:

DISQUS_SITENAME = your_shortname

而后执行

make html

使用浏览器打开:http://localhost:8000来查看效果

主题

安装主题:
Pelican自己提供不少主题可供选择,能够从githubclone下来

git clone https://github.com/getpelican/pelican-themes.git
cd pelican-themes
pelican-themes -i bootstrap2

其中bootstrap2是选择使用的主题,pelican主题的Github目录下几乎每一个都提供了预览.

而后,在配置文件pelicanconf.py中添加:

THEME = u"bootstrap2'

从新make,就生成了带有选定主题的页面。

使用插件

Pelican 一开始是将插件内置的, 可是新版本 Pelican将插件隔离了出来, 因此咱们要到github上 克隆一份新的插件, 在博客目录执行

git clone git://github.com/getpelican/pelican-plugins.git

如今咱们博客目录就新添了一个 pelican-plugins目录, 咱们已配置sitemap插件为例, sitemap插件能够生成 sitemap.xml 供搜索引擎使用

pelicanconf.py配置文件里加上以下项:

PLUGIN_PATH = u"pelican-plugins"

PLUGINS = ["sitemap"]

配置sitemap 插件

SITEMAP = {
    "format": "xml",
    "priorities": {
        "articles": 0.7,
        "indexes": 0.5,
        "pages": 0.3,
    },
    "changefreqs": {
        "articles": "monthly",
        "indexes": "daily",
        "pages": "monthly",
    }
}

而后再执行

make html

打开浏览器请求 http://localhost:8000/sitemap.xml便可看到生成的 Sitemap 了

添加Google Analytics

去Google Analytics申请帐号,记下跟踪ID。 在pelicanconf.py添加

GOOGLE_ANALYTICS = 跟踪ID

使用Google Webmasters

Google Webmasters上注册便可。
这个就是Google站长工具,使用它的目的是为了让博客被Google更好的收录,好比手动让Googlebot抓取、提交Robots、更新Sitemap等等,各方面完爆百度站长工具。

上传Github

最后在你的output文件夹内

git init
git add .
git commit -m 'first commit' 
git remote add origin git@github.com:yourname/yourname.github.io.git
git push -u origin master

这样就大功告成了!

相关文章
相关标签/搜索