用pelican写博客并发布到github-page

作为程序员写博客记笔记是一件很普遍和有用的事,而我们习惯了md写文档,下面介绍一款用md写博客的工具

功能特点

  • 多主题选择,可自定义主题
  • 保留md
  • 纯静态

市面上其实有hexo Jekyll,有相同的功能。为什么我选择pelican? 因为pelicam 基于 python 。其他的hexo 基于nodejs,Jekyll貌似是ruby.

安装使用

安装

 pip install pelican markdown
 sudo -H pip install pelican markdown ##mac 推荐

创建项目

mkdir -p ~/projects/yoursite  ##创建你的项目目录
cd ~/projects/yoursite

pelican-quickstart  ##快速开始命令  完成创建

写一篇文章

cd content
code hello-world.md  ## 用vs-code创建md并打开 我设置了cmd启动vscode

写入以下内容

Title: hello world
Date: 2010-12-03 10:20
Category: Review

hello,world

生成静态文件

pelican content

预览

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 安装 很适用于开发主题

我fork了官方的一个主题并进行修改地址如下git@github.com:visonforcoding/attila.git

配置

THEME = "attila"

COLOR_SCHEME_CSS = 'monokai.css'  ##设置代码高亮样式

DISQUS_SITENAME = "your-domain"  ##disqus 域名

发布到github page

首先你需要一个github page repository,具体参考官方文档https://pages.github.com/ 写的非常详细

这里主要介绍如何将生产的output 发布到你的github repository,其实官方有提供一个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个git commit 和push ,原因是我想把content 的md提交到github 保存。修改完之后执行fab命令即可将content push到md repository将content push到page repository

fab gh_pages

访问 youdomian.github.io 我的地址 https://visonforcoding.github.io/

4033700-307543c6b1150521.png
image.png
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值