用Pelican和Github Pages在Linux上搭建个人博客

来源:互联网 发布:网络机顶盒电视猫 编辑:程序博客网 时间:2024/05/16 07:50

转自我的Github博客 CommonQ's Blog

搭建环境

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

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

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页面就已经生成了一个页面。访问该网址即可看到。

配置本地环境

安装Pelican和Markdown:

在这里我没有用Jekyll因为它是Ruby写的对它没什么兴趣。所以我采用Python编写的Pelican

介绍

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

安装

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

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

另一种就是从github上克隆Pelican

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

写第一篇博客

搭建目录

mkdir blogcd blogpelican-quickstart

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

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

写一篇文章

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

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

然后执行

make html

生成了html。然后执行

./develop_server.sh start

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

创建一个About页面

这里以创建 About页面为例

content目录创建pages目录

mkdir content/pages

然后创建About.md并填入下面内容

Title: About MeDate: 2013-04-18About 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.gitcd pelican-themespelican-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 initgit add .git commit -m 'first commit' git remote add origin git@github.com:yourname/yourname.github.io.gitgit push -u origin master

这样就大功告成了!

0 0
原创粉丝点击