mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge pull request #17961 from wxy/20190523-Run-your-blog-on-GitHub-Pages-with-Python
PRF&PUB:20190523 Run your blog on GitHub Pages with Python
This commit is contained in:
commit
065cd30665
@ -1,21 +1,22 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12064-1.html)
|
||||
[#]: subject: (Run your blog on GitHub Pages with Python)
|
||||
[#]: via: (https://opensource.com/article/19/5/run-your-blog-github-pages-python)
|
||||
[#]: author: (Erik O'Shaughnessy https://opensource.com/users/jnyjny/users/jasperzanjani/users/jasperzanjani/users/jasperzanjani/users/jnyjny/users/jasperzanjani)
|
||||
|
||||
在 GitHub 上使用 Python 运行你的博客
|
||||
使用 Python 在 GitHub 上运行你的博客
|
||||
======
|
||||
使用 Pelican(一个基于 Python 的平台)在 GitHub 上创建博客,看起来很不错。
|
||||
|
||||
![Raspberry Pi and Python][1]
|
||||
> 使用 Pelican 创建博客,这是一个基于 Python 的平台,与 GitHub 配合的不错。
|
||||
|
||||

|
||||
|
||||
[GitHub][2] 是一个非常流行的用于源代码控制的 Web 服务,它使用 [Git][3] 同步本地文件和 GitHub 服务器上保留的副本,这样你就可以轻松地共享和备份你的工作。
|
||||
|
||||
除了为代码仓库提供用户界面之外,GitHub 还运允许用户直接从仓库[发布网页][4]。GitHub 推荐的网站生成软件包是 [Jekll][5],使用 Ruby 编写。因为我是 [Python][6] 的忠实粉丝,所以我更喜欢 [Pelican][7],这是一个基于 Python 的博客平台,可与 GitHub 很好地协同工作。
|
||||
除了为代码仓库提供用户界面之外,GitHub 还运允许用户直接从仓库[发布网页][4]。GitHub 推荐的网站生成软件包是 [Jekll][5],是使用 Ruby 编写的。因为我是 [Python][6] 的忠实粉丝,所以我更喜欢 [Pelican][7],这是一个基于 Python 的博客平台,可与 GitHub 很好地协同工作。
|
||||
|
||||
Pelican 和 Jekll 都可以将 [Markdown][8] 或 [reStructuredText][9] 中编写的内容转换为 HTML 以生成静态网站,并且两个生成器都支持定制的主题。
|
||||
|
||||
@ -23,21 +24,21 @@ Pelican 和 Jekll 都可以将 [Markdown][8] 或 [reStructuredText][9] 中编写
|
||||
|
||||
### 安装 Pelican 并创建仓库
|
||||
|
||||
首先,你必须在本地计算机上安装 Pelican 和 **ghp-import**。使用 Python 软件包安装工具 [pip][12](你有,对吧?),这非常容易:
|
||||
首先,你必须在本地计算机上安装 Pelican 和 `ghp-import`。使用 Python 软件包安装工具 [pip][12](你有,对吧?),这非常容易:
|
||||
|
||||
```
|
||||
$ pip install pelican ghp-import Markdown
|
||||
```
|
||||
|
||||
然后,打开浏览器并在 GitHub 上为你的新博客创建一个新的仓库,命名如下(在此处以及整个教程中,用 GitHub 用户名替换 <username>):
|
||||
然后,打开浏览器并在 GitHub 上为你新鲜出炉的博客创建一个新仓库,命名如下(在此处以及整个教程中,用 GitHub 用户名替换 `username`):
|
||||
|
||||
```
|
||||
https://GitHub.com/username/username.github.io
|
||||
```
|
||||
|
||||
让它保持空白,稍后我们用引人注目的博客内容来填充它。
|
||||
让它保持为空,稍后我们用引人注目的博客内容来填充它。
|
||||
|
||||
使用命令行(确保正确),将空的 Git 仓库克隆到本地计算机:
|
||||
使用命令行(确保正确),将这个空 Git 仓库克隆到本地计算机:
|
||||
|
||||
```
|
||||
$ git clone <https://GitHub.com/username/username.github.io> blog
|
||||
@ -46,9 +47,9 @@ $ cd blog
|
||||
|
||||
### 奇怪的把戏...
|
||||
|
||||
在 GitHub 上发布 Web 内容有一个不太明显的技巧,对于用户页面(托管在名为 _username.github.io_ 的仓库的页面上),其内容来自 **master** 分支。
|
||||
在 GitHub 上发布 Web 内容有一个不太引入注意的技巧,对于托管在名为 `username.github.io` 的仓库的用户页面,其内容由 `master` 分支提供服务。
|
||||
|
||||
我强烈建议不要将所有 Pelican 配置文件和原始 Markdown 文件都保留在 **master** 中,**master** 中只保留 Web 内容中。因此,我将 Pelican 配置和原始内容保留在一个我喜欢称为 **content** 的单独分支中。(你可以随意创建一个分支,但以下内容沿用 **content**。)我喜欢这种结构,因为我可以放弃掉 **master** 中的所有文件,然后用 **content** 分支重新填充它。
|
||||
我强烈建议所有的 Pelican 配置文件和原始的 Markdown 文件都不要保留在 `master` 中,`master` 中只保留 Web 内容。因此,我将 Pelican 配置和原始内容保留在一个我喜欢称为 `content` 的单独分支中。(你可以随意创建一个分支,但以下内容沿用 `content`。)我喜欢这种结构,因为我可以放弃掉 `master` 中的所有文件,然后用 `content` 分支重新填充它。
|
||||
|
||||
```
|
||||
$ git checkout -b content
|
||||
@ -57,7 +58,7 @@ Switched to a new branch 'content'
|
||||
|
||||
### 配置 Pelican
|
||||
|
||||
现在该进行内容配置了。Pelican 提供了一个很棒的初始化工具 **pelican-quickstart**,它会询问你有关博客的一系列问题。
|
||||
现在该进行内容配置了。Pelican 提供了一个很棒的初始化工具 `pelican-quickstart`,它会询问你有关博客的一系列问题。
|
||||
|
||||
```
|
||||
$ pelican-quickstart
|
||||
@ -68,11 +69,11 @@ This script will help you create a new Pelican-based website.
|
||||
Please answer the following questions so this script can generate the files
|
||||
needed by Pelican.
|
||||
|
||||
> Where do you want to create your new web site? [.]
|
||||
> Where do you want to create your new web site? [.]
|
||||
> What will be the title of this web site? Super blog
|
||||
> Who will be the author of this web site? username
|
||||
> What will be the default language of this web site? [en]
|
||||
> Do you want to specify a URL prefix? e.g., <http://example.com> (Y/n) n
|
||||
> Do you want to specify a URL prefix? e.g., http://example.com (Y/n) n
|
||||
> Do you want to enable article pagination? (Y/n)
|
||||
> How many articles per page do you want? [10]
|
||||
> What is your time zone? [Europe/Paris] US/Central
|
||||
@ -90,13 +91,12 @@ Done. Your new project is available at /Users/username/blog
|
||||
|
||||
你可以对每个问题都采用默认值,但除了以下这些问题:
|
||||
|
||||
* 网站标题,应该唯一且特殊
|
||||
* 网站作者,可以是个人用户名或你的全名
|
||||
* 时区,可能你不在巴黎
|
||||
* 上传到 GitHub 页面,我们选择 "y"
|
||||
* 网站标题,应该唯一且特殊
|
||||
* 网站作者,可以是个人用户名或你的全名
|
||||
* 时区,可能你不在巴黎
|
||||
* 上传到 GitHub 页面,我们选择 `y`
|
||||
|
||||
|
||||
回答完所有问题后,Pelican 会在当前目录中保留以下内容:
|
||||
回答完所有问题后,Pelican 会在当前目录中留下以下内容:
|
||||
|
||||
```
|
||||
$ ls
|
||||
@ -105,11 +105,11 @@ fabfile.py output/ pelicanconf.py
|
||||
publishconf.py
|
||||
```
|
||||
|
||||
你可以查看 [Pelican 文档][13]来了解如何使用这些文件,但 _现在_ 我们要做的是完成手头的工作。说实话,我也没有阅读文档。
|
||||
你可以查看 [Pelican 文档][13]来了解如何使用这些文件,但**现在**我们要做的是完成手头的工作。说实话,我也没有阅读文档。
|
||||
|
||||
### 继续
|
||||
|
||||
将所有 Pelican 生成的文件添加到本地 Git 仓库的 **content** 分支,提交更改,然后将本地更改推送到 Github 上托管的远程仓库:
|
||||
将所有 Pelican 生成的文件添加到本地 Git 仓库的 `content` 分支,提交更改,然后将本地更改推送到 Github 上托管的远程仓库:
|
||||
|
||||
```
|
||||
$ git add .
|
||||
@ -117,11 +117,11 @@ $ git commit -m 'initial pelican commit to content'
|
||||
$ git push origin content
|
||||
```
|
||||
|
||||
这件事情并不是特别令人兴奋,但是如果我们需要将内容恢复到这些文件的时候,这将非常方便。
|
||||
这件事情并不是特别令人兴奋,但是如果我们需要撤销这些文件之一的修改时,这将非常方便。
|
||||
|
||||
### 终于
|
||||
|
||||
终于,现在你得到一个博客了!你所有的博客文章、照片、图像、PDF 等都将位于 **content** 目录中,它最初是空的。要开始创建第一篇博客和关于页面,输入:
|
||||
终于,现在你得到一个博客了!你所有的博客文章、照片、图像、PDF 等都将位于 `content` 目录中,它最初是空的。要开始创建第一篇博客和关于页面,输入:
|
||||
|
||||
```
|
||||
$ cd content
|
||||
@ -131,7 +131,7 @@ $ touch first-post.md
|
||||
$ touch pages/about.md
|
||||
```
|
||||
|
||||
接下来,在你喜欢的文本编辑器中打开 **first-post.md**,并添加以下内容:
|
||||
接下来,在你喜欢的文本编辑器中打开 `first-post.md`,并添加以下内容:
|
||||
|
||||
```
|
||||
title: First Post on My Sweet New Blog
|
||||
@ -147,7 +147,7 @@ the reader!
|
||||
|
||||
前三行是 Pelican 用于组织内容的元数据。有很多不同的元数据可供你选择。再说一次,文档是你了解更多选项的最佳选择。
|
||||
|
||||
现在,打开空白文件 **pages/about.md** 并添加以下文本:
|
||||
现在,打开空白文件 `pages/about.md` 并添加以下文本:
|
||||
|
||||
```
|
||||
title: About
|
||||
@ -164,7 +164,7 @@ and I would probably have been burned at the stake.
|
||||
[my_sweet_photo]: {static}/images/HotPhotoOfMe.jpg
|
||||
```
|
||||
|
||||
现在,content 目录中将包含三个新的 Web 内容,在 content 分支中还有很多内容。
|
||||
现在,`content` 目录中将包含三个新的 Web 内容,在 `content` 分支中还有很多内容。
|
||||
|
||||
### 发布
|
||||
|
||||
@ -172,27 +172,28 @@ and I would probably have been burned at the stake.
|
||||
|
||||
剩下要做的就是:
|
||||
|
||||
* 运行 Pelican 以在 **output** 中生成静态 HTML 文件:
|
||||
```
|
||||
`$ pelican content -o output -s publishconf.py`
|
||||
```
|
||||
* 运行 Pelican 以在 `output` 中生成静态 HTML 文件:
|
||||
|
||||
* 使用 **ghp-import** 将 **output** 目录的内容添加到 **master** 分支中:
|
||||
```
|
||||
$ ghp-import -m "Generate Pelican site" --no-jekyll -b master output`
|
||||
```
|
||||
```
|
||||
$ pelican content -o output -s publishconf.py
|
||||
```
|
||||
* 使用 `ghp-import` 将 `output` 目录的内容添加到 `master` 分支中:
|
||||
|
||||
* 将本地 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
|
||||
```
|
||||
```
|
||||
$ 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,我成功了
|
||||
|
||||
@ -211,7 +212,7 @@ via: https://opensource.com/article/19/5/run-your-blog-github-pages-python
|
||||
作者:[Erik O'Shaughnessy][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
Loading…
Reference in New Issue
Block a user