【Github学习】如何创建Github blog

我看到Jake VanderPlas写的Github文章《Understanding Data Types in Python》,如此优美,且有comment栏。

我尝试github.io,得到https://pages.github.com。按照指示可以申请自己的github.io的博客。这个博客的特点是:书写markdown文档,上传,可发布为blog(Github会将其翻译成html网页)。

 

那么,想想看,如果建设一个基础repo,让其成为一个capacity,那日后只要写markdown文档就好。我喜欢Paul Le先生的Lagrange模板,修改其个人化数据,就以它作为基础repo。

那么核心任务是将其所有文件连同文件夹结构复制到我的Github repo。

1)新建一个repository,名字叫username.github.io。我的是dersu-git.github.io。

2)点击repository setting,选择一个theme。这样在浏览器输入username.github.io,可以得到博客网页。

3)替换整个repo。

在Terminal中pull 整个repository。

cd my_local_repo_archive

git config --global user.name myusername
git config --global user.email myemailaddress

  以上三条命令用于登录Github。后来的操作时,可能会被问用户名和密码(密码是token)。

git remote set-url origin https://github.com/Dersu-git/dersu-git.github.io
git pull origin master

可以在本地得到dersu-git.github.io文件夹,这是本地repo,清空文件夹
下载Lagrange模板所有文件,拷贝到本地repo。这样我们就仿造了一个基础repo。可能的话,先做第四步也是好的,看看里面到底是什么数据,要如何改成我的数据。

将所有文件“数据同步”至远程repoGit command系列命令为:

git add .
git commit -m "Copy a demo repo."
git push origin master

稍等(Github有约半分钟的滞后),可以看到blog如同demo site。

 

4)个人化。

  • _post中的md文档删除,替换成自己的blog md文档。
  • 修改menu中的文档。
  • 修改_config.yml。
  • 修改_data中的setting.yml。需要申请disqus账号,获得short name。disqus用来实现comment功能。
  • 修改favicon.ico。需要申请favicon。

每个文件都看一看,确保改好,数据同步。

 

从Git command的角度看,整个过程如图1示。

 图1:创建Github blog的流程

 

日后写新的博客,是写.md文档,依葫芦画瓢起文件名,例如,2020-06-10-how-to-build-a-Github-blog.md(这个名字结构和网站代码读取文件有关),拷贝至_posts文件夹,图片存于assets/img,登录Github数据同步。我平时用网易云笔记写markdown文档,但无法保存,需要拷贝到TextEdit或Sublime保存为.md (我爱Sublime,我爱它的风格)。

若在Github markdown文档尽量手写,不要使用复杂标记语言(如list、引用脚注),Github会不理睬的。如果插入图片,我使用HTML标记语言:

<div style="text-align:left;"><img src="https://dersu-git.github.io/assets/img/gitcommand.jpg" style="margin-bottom:0px; max-width:80%;" alt=""><p style="font-size:12px">Fig: Git work flow</p></div>

 

感谢毛毛虫_wendy,《如何利用github page快速搭建个人博客》这个博文给我很多启发。

 

相关:

 

posted @ 2020-06-10 07:39  Dersu  阅读(670)  评论(0编辑  收藏  举报