Hello World/GitHub Page/Pelican!
好了拖了很久还是准备开始写自己的博客了,主要是有这么些原因:
- 记录一下自己做的东西,有时候好不容易查到资料会做了的东西,回头放了一段时间又忘了,或者资料找不到了,记录一下会比较好找。
- 也算show一下自己做的东西,虽然感觉没人会看,但万一找工作什么的有用呢,谁知道。
因为主要是自己写给自己看的,所以可能会比较乱,我考虑着可能会写的中英文夹杂。可能技术内容尽量是英文的,备注或者发发牢骚大概就用中文了。
之前一直用的自己的域名zhujiaqi.me,不过那个是挂在UFL的服务器上了,懒得更新,主要就当是网络版的简历了。Blog的话因为要经常更新,所以还是选择用GitHub Page,更新维护方便,而且也不用操心域名啊host啊这些。使用Pelican是因为懒得自己写HTML,写markdown会容易很多,而且Pelican有plugins可以直接把jupyter notebook转换成blog文章,因为很多要写的东西可能都是python做的数据方面的一些东西,所以长篇大论的文章可能会直接用notebook写。
Create a Pelican Blog
Installation
First make sure to install all the packages that are required.
Create a file called requirements.txt in blog folder, with the following content:
Markdown==2.6.6
pelican==3.6.3
jupyter>=1.0
ipython>=4.0
nbconvert>=4.0
beautifulsoup4
ghp-import==0.4.1
matplotlib==1.5.1
Run pip install -r requirements.txt in blog folder to install all of the packages in requirements.txt
QuickStart
Just run pelican-quickstart in blog folder and answer all the question by prompt, it will ask if you want to use GitHub Pages.
We should have these files in the folder now:
blog
│ output
│ content
│ .gitignore
│ develop_server.sh
│ fabfile.py
│ Makefile
│ requirements.txt
│ pelicanconf.py
│ publishconf.py
Install Plugins for Jupyter Notebook
To support writting content in notebook, we need to add a plugin.
- First run
git init to initialize current folder as git repo.
- Then run
mkdir plugins
git submodule add git://github.com/danielfrg/pelican-ipynb.git plugins/ipynb to add in the plugin. You can also copy code from that repo to plugins folder, it should also work.
Then use text editor to modify pelicanconf.py, and add these lines to the bottom:
MARKUP = ('md', 'ipynb')
PLUGIN_PATH = ['./plugins']
PLUGINS = ['ipynb.markup']
Write Post
- Put a Jupyter Notebook in
content
- Create a file with same name, with extension
.ipynb-meta
Add following content to meta file:
Title: First Post
Slug: first-post
Date: 2016-06-08 20:00
Category: posts
Tags: python firsts
author: Jiaqi Zhu
Summary: My first post, read it to find out.
Generate HTML Files
- Switch to the root folder.
- Run
pelican content to generate the HTML.
- Switch to the
output directory.
- Run
python -m pelican.server.
- Visit
localhost:8000 in your browser to preview the blog.
Create GitHub Page
- Sign up for Github if you haven’t already.
- Create a repository called username.github.io, where username is your Github username.
- Switch to the root folder.
- Add the repository as a remote for your local git repository by running
git remote add origin git@github.com:username/username.github.io.git – replace both references to username with your Github username.
Then, we’ll need to modify Pelican so that URLs point to the right spot:
- Edit
SITEURL in publishconf.py, so that it is set to http://username.github.io, where username is your Github username.
- Run
pelican content -s publishconf.py. When you want to preview your blog locally, run pelican content. Before you deploy, run pelican content -s publishconf.py. This uses the correct settings file for deployment.
Deploy to Github
We’ll need to add the content of the blog to the master branch for Github Pages to work properly. Currently, the HTML content is inside the folder output, but we need it to be at the root of the repository, not in a subfolder. We can use the ghp-import tool for this:
- Run
ghp-import output -b master to import everything in the output folder to the master branch.
- Use
git push origin master to push your content to Github.
- Try visiting
username.github.io – you should see your page!
Whenever you make a change to your blog, just re-run:
pelican content -s publishconf.py
ghp-import output -b master
git push origin master
When you want to check your site locally:
pelican content
python -m pelican.server
Some Useful Links
http://blog.csdn.net/simple_the_best/article/details/52821132
https://www.dataquest.io/blog/how-to-setup-a-data-science-blog/
http://docs.getpelican.com/en/stable/index.html
https://github.com/danielfrg/pelican-ipynb
https://github.com/MacDownApp/macdown