用 Pelican 和 github 打造你的个人主页

用 Pelican 生成你的个人主页

无需申请站点, 也不要搭建服务器, 编写网页, 如果只是一个人站点, 发布点个人信息, 博客文章, 以及读书笔记, 用 pelican 和 github 就可以做一个免费的个人主页.

So easy.

1. 安装 brew

这里仅以 mac book 为例,在windows上差不多,先把python, pip装上,剩下的就好办了

安装 homebrew 先

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安装 python, pip and pelican

brew install python
sudo easy_install pip
sudo pip install pelican markdown

output: ::
Successfully installed blinker-1.3 docutils-0.12 feedgenerator-1.7 jinja2-2.7.3 markdown-2.6 markupsafe-0.23 pelican-3.5.0 pygments-2.0.2 unidecode-0.4.17

3. 执行 pelican-quickstart in yoursite folder

pelican-quickstart

常见问题

问题1: some errors showed up: ValueError: unknown locale: UTF-8

  • 解决方案:
    在 ~/.bash_profile增加如下两行

    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8

问题2: No module named html_parser

  • 解决方案: pip install six
  • if still encounter the error , upgrade python form 2.7.6 to 2.7.9
  • if still encounter the error::

    sudo vi /Library/Python/2.7/site-packages/pelican/readers.py

    from six.moves.html_parser import HTMLParser

    from HTMLParser import HTMLParser

4. 添加一个文件 test.md 在 content 目录中

Title: Journal
Date: 2015-02-27 10:20
Modified: 2015-02-27 19:30
Category: Journal
Tags: journal, blog
Authors: Walter Fan
Summary: Daily minute

# Task

5. 快速测试一下

步骤如下:

pelican content
pelican listen

6. 访问 http://localhost:8000


可见一个象模象样的博客网站已经生成了

配置文件示例 pelicanconf.py:

AUTHOR = 'Foo Bar'
SITEURL = 'http://yoursite.com'
SITENAME = 'Foo Bar\'s Blog'
SITETITLE = 'Foo Bar'
SITESUBTITLE = 'Web Developer'
SITEDESCRIPTION = 'Foo Bar\'s Thoughts and Writings'
SITELOGO = SITEURL + '/images/profile.png'
FAVICON = SITEURL + '/images/favicon.ico'

BROWSER_COLOR = '#333'
ROBOTS = 'index, follow'

CC_LICENSE = {
    'name': 'Creative Commons Attribution-ShareAlike',
    'version': '4.0',
    'slug': 'by-sa'
}

COPYRIGHT_YEAR = 2016

EXTRA_PATH_METADATA = {
    'extra/custom.css': {'path': 'static/custom.css'},
}
CUSTOM_CSS = 'static/custom.css'

MAIN_MENU = True

LINKS_IN_NEW_TAB = 'external'

ADD_THIS_ID = 'ra-77hh6723hhjd'
DISQUS_SITENAME = 'yoursite'
GOOGLE_ANALYTICS = 'UA-1234-5678'
GOOGLE_TAG_MANAGER = 'GTM-ABCDEF'
STATUSCAKE = { 'trackid': 'your-id', 'days': 7, 'design': 6, 'rumid': 1234 }

# Enable i18n plugin.
PLUGINS = ['i18n_subsites']
# Enable Jinja2 i18n extension used to parse translations.
JINJA_EXTENSIONS = ['jinja2.ext.i18n']

# Translate to German.
DEFAULT_LANG = 'de'
OG_LOCALE = 'de_DE'
LOCALE = 'de_DE'

# Default theme language.
I18N_TEMPLATES_LANG = 'en'

Tips

  • edit pelicanconf.py to set RELATIVE_URLS = True

用 github 来发布你的个人主页

1. publish blog to github site

步骤如下:

cd output
git init
git add *
git remote add origin https://github.com/walterfan/walterfan.github.io.git
git pull origin master
git commit -am 'add blog'
git push -u origin master

2. 定制你的博客站点样式

步骤如下:

    mkdir theme
    cd theme
    git submodule add https://github.com/DandyDev/pelican-bootstrap3.git
    git submodule init
    git submodule update

然后编辑 pelicanconf.py, 增加下面这行

THEME = '../theme/pelican-bootstrap3'

推荐我最喜欢的 Flex 样式

    cd theme
    git submodule add https://github.com/alexandrevicenzi/Flex.git
    git submodule init
    git submodule update

你可能感兴趣的:(用 Pelican 和 github 打造你的个人主页)