使用 Python 在 GitHub 上运行你的博客( 二 )


继续将所有 Pelican 生成的文件添加到本地 Git 仓库的 content 分支,提交更改,然后将本地更改推送到 Github 上托管的远程仓库:
$ git add .$ git commit -m 'initial pelican commit to content'$ git push origin content这件事情并不是特别令人兴奋,但是如果我们需要撤销这些文件之一的修改时,这将非常方便 。
终于终于,现在你得到一个博客了!你所有的博客文章、照片、图像、PDF 等都将位于 content 目录中,它最初是空的 。要开始创建第一篇博客和关于页面,输入:
$ cd content$ mkdir pages images$ cp /Users/username/SecretStash/HotPhotoOfMe.jpg images$ touch first-post.md$ touch pages/about.md接下来,在你喜欢的文本编辑器中打开 first-post.md,并添加以下内容:
title: First Post on My Sweet New Blogdate: <today's date>author: Your Name Here# I am On My Way To Internet Fame and Fortune!This is my first post on my new blog. While not super informative itshould convey my sense of excitement and eagerness to engage with you,the reader!前三行是 Pelican 用于组织内容的元数据 。有很多不同的元数据可供你选择 。再说一次,文档是你了解更多选项的最佳选择 。
现在,打开空白文件 pages/about.md 并添加以下文本:
title: Aboutdate: <today's date>![So Schmexy][my_sweet_photo]Hi, I am <username> and I wrote this epic collection of Interwebwisdom. In days of yore, much of this would have been deemed sorceryand I would probably have been burned at the stake.现在,content 目录中将包含三个新的 Web 内容,在 content 分支中还有很多内容 。
发布不要急,马上要见到成果了!
剩下要做的就是:

  • 运行 Pelican 以在 output 中生成静态 HTML 文件:$ pelican content -o output -s publishconf.py
  • 使用 ghp-import 将 output 目录的内容添加到 master 分支中:$ ghp-import -m "Generate Pelican site" --no-jekyll -b master output
  • 将本地 master 分支推送到远程仓库:$ git push origin master
  • 提交新内容并将其推送到 content 分支$ git add content $ git commit -m 'added a first post, a photo and an about page' $ git push origin content
OMG,我成功了现在最激动的时候到了,当你想要看到你发布给大家的博客内容时,打开浏览器输入:
https://username.github.io恭喜你可以在 GitHub 上发布自己的博客了!当你想添加更多页面或文章时,都可以按照上面的步骤来 。希望你可以愉快地发布博客 。


推荐阅读