作為程序員寫博客記筆記是一件很普遍和有用的事癌蓖,而我們習(xí)慣了md寫文檔瞬哼,下面介紹一款用md寫博客的工具
功能特點(diǎn)
- 多主題選擇,可自定義主題
- 保留md
- 純靜態(tài)
市面上其實(shí)有hexo Jekyll,有相同的功能租副。為什么我選擇pelican? 因?yàn)閜elicam 基于 python 坐慰。其他的hexo 基于nodejs,Jekyll貌似是ruby.
安裝使用
安裝
pip install pelican markdown
sudo -H pip install pelican markdown ##mac 推薦
創(chuàng)建項(xiàng)目
mkdir -p ~/projects/yoursite ##創(chuàng)建你的項(xiàng)目目錄
cd ~/projects/yoursite
pelican-quickstart ##快速開始命令 完成創(chuàng)建
寫一篇文章
cd content
code hello-world.md ## 用vs-code創(chuàng)建md并打開 我設(shè)置了cmd啟動(dòng)vscode
寫入以下內(nèi)容
Title: hello world
Date: 2010-12-03 10:20
Category: Review
hello,world
生成靜態(tài)文件
pelican content
預(yù)覽
cd output
python -m pelican.server
在瀏覽器上查看 http://localhost:8000/
安裝主題
可以從https://github.com/getpelican/pelican-themes 選擇你喜歡的主題
pelican-themes -l #查看已安裝的主題
pelican-themes --install ~/Dev/Python/pelican-themes/notmyidea-cms --verbos ##從該路徑安裝主題
pelican-themes --remove two-column ##刪除主題
pelican-themes --symlink ~/Dev/Python/pelican-themes/two-column ##symlink 安裝 很適用于開發(fā)主題
我fork了官方的一個(gè)主題并進(jìn)行修改地址如下git@github.com:visonforcoding/attila.git
配置
THEME = "attila"
COLOR_SCHEME_CSS = 'monokai.css' ##設(shè)置代碼高亮樣式
DISQUS_SITENAME = "your-domain" ##disqus 域名
發(fā)布到github page
首先你需要一個(gè)github page repository,具體參考官方文檔https://pages.github.com/ 寫的非常詳細(xì)
這里主要介紹如何將生產(chǎn)的output 發(fā)布到你的github repository,其實(shí)官方有提供一個(gè)ghp-import,但我覺得與自己想要的并不太一樣用僧,因此還是按照自己的方式來结胀。原理就是利用fabric 將output push 到github.修改fabfile.py我的配置如下:
def gh_pages():
"""Publish to GitHub Pages"""
# rebuild()
# local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))
local("pelican content")
local("cd content && git add . && git commit -m 'update md' && git push origin master && cd ../")
local("cd output && git add . && git commit -m 'update blog' && git push origin master && cd ../")
修改 gh_pages 方法,我這里有2個(gè)git commit 和push ,原因是我想把content 的md提交到github 保存责循。修改完之后執(zhí)行fab命令即可將content push到md repository將content push到page repository
fab gh_pages
訪問 youdomian.github.io 我的地址 https://visonforcoding.github.io/