python 使用 Sphinx 编写个人网站和博客
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1576340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Sphinx to write personal websites and blogs
提问by Sridhar Ratnakumar
Sphinxis a Python library to generate nice documentation from a set of ReSTformatted text files.
Sphinx是一个 Python 库,用于从一组ReST格式的文本文件生成漂亮的文档。
I wonder if any one has written Sphinx plugins to make it generate personal websites and blogs.
我想知道是否有人编写了 Sphinx 插件来生成个人网站和博客。
Especially for blogs, there needs to be a way to automatically list posts chronologically and generate a RSS feed. One needs to write a Sphinx plugin to do such special page/xml generation.
特别是对于博客,需要有一种方法可以自动按时间顺序列出帖子并生成 RSS 提要。需要编写一个 Sphinx 插件来生成这种特殊的页面/xml。
Has anyone tried this before?
有没有人试过这个?
采纳答案by Reinout van Rees
I've done it at http://reinout.vanrees.org/weblog. The key trick is to add a preprocessor step. I've got my blog entries in a weblog/yyyy/mm/dd/
folder structure.
我已经在http://reinout.vanrees.org/weblog 上完成了。关键技巧是添加一个预处理器步骤。我在weblog/yyyy/mm/dd/
文件夹结构中有我的博客条目。
A script iterates through that folder structure, creating index.txt
files in every directory, listing the sub-items. The normal Sphinx process then renders those index.txt
files.
脚本遍历该文件夹结构,index.txt
在每个目录中创建文件,列出子项。然后正常的 Sphinx 进程渲染这些index.txt
文件。
I added a custom Sphinx processor for tags. So ".. tags:: python, buildout" somewhere at the top of my weblog entry generates the tags. And the preprocessor again collects those entries and writes out a weblog/tags/TAGNAME.txt
file which Sphinx again renders normally.
我为标签添加了一个自定义的 Sphinx 处理器。所以“.. tags:: python, buildout”在我的博客条目顶部的某处生成了标签。预处理器再次收集这些条目并写出一个weblog/tags/TAGNAME.txt
Sphinx 再次正常渲染的文件。
The preprocessor also creates the root weblog/index.txt
with the latest 10 entries. And an weblog/atom.xml
in (hardcoded) the output directory for the rss feed.
预处理器还weblog/index.txt
使用最新的 10 个条目创建根。以及weblog/atom.xml
(硬编码)RSS 提要的输出目录。
So: you need some custom stuff, but it is pretty much plain text, so for me it was a nice exercise. And you get to write some helper scripts to make life easy, for instance one that copies a textfile from somewhere to today's weblog directory (including creation of missing directories and an "svn add").
所以:你需要一些自定义的东西,但它几乎是纯文本,所以对我来说这是一个很好的练习。并且您可以编写一些帮助脚本来简化工作,例如将文本文件从某处复制到今天的 weblog 目录的脚本(包括创建丢失的目录和“svn add”)。
回答by Noe Nieto
As of now (February, 2012), there are different resources available to do what you want:
截至目前(2012 年 2 月),有不同的资源可用于执行您想要的操作:
A blog engine based on sphinx: http://tinkerer.me/
基于 sphinx 的博客引擎:http: //tinkerer.me/
Reinout Van Rees' blog: https://github.com/reinout/reinout.vanrees.org
Reinout Van Rees 的博客:https: //github.com/reinout/reinout.vanrees.org
The feed contrib extension: https://bitbucket.org/birkenfeld/sphinx-contrib/src/tip/feed/README
提要贡献扩展:https: //bitbucket.org/birkenfeld/sphinx-contrib/src/tip/feed/README
回答by monkut
Doug hellmann, author of the 'Python Module of the Week' does his site using Sphinx.
“本周 Python 模块”的作者 Doug hellmann 使用 Sphinx 创建他的网站。
http://www.doughellmann.com/PyMOTW/
http://www.doughellmann.com/PyMOTW/
He has several posts which cover sphinx topics that can probably help you on your way:
他有几篇涵盖狮身人面像主题的帖子,可能会对您有所帮助:
回答by Pierre-Jean Coudert
If you need to write in reStructuredText , you should try Pelican.
如果您需要在reStructuredText 中编写,您应该尝试Pelican。
Pelican is a static site generator, written in Python. You'll be able to write your blog entries directly in reStructuredText or Markdown.
Pelican 是一个静态站点生成器,用 Python 编写。您将能够直接在 reStructuredText 或 Markdown 中编写您的博客条目。
回答by ketanbhatt
Check out ABlog for Sphinx
I am in the process of starting a blog myself using it.
我正在使用它自己创建博客。
I stumbled across it while I was going through my feeds in feedly. I searched about it and found it interesting. It also has Disqus integration, and can generat Atom feeds (not very sure what that is at the moment, I am new to the web)
我在 Feedly 中浏览我的提要时偶然发现了它。我搜索了一下,发现它很有趣。它还具有 Disqus 集成,并且可以生成 Atom 提要(目前不太确定那是什么,我是网络新手)
I have not yet figured out how to deploy my test blog, will update when i find out something.
我还没有弄清楚如何部署我的测试博客,当我发现一些东西时会更新。
回答by dan mackinlay
It's worth knowing that there is an RSS extension for sphinx in the sphinx-contrib extensions, called sphinxcontrib.feed
It and many other fun Sphinx things live at http://bitbucket.org/birkenfeld/sphinx-contrib/
值得知道的是,在 sphinx-contrib 扩展中有一个 sphinx 的 RSS 扩展,称为sphinxcontrib.feed
It 和许多其他有趣的 Sphinx 东西,位于http://bitbucket.org/birkenfeld/sphinx-contrib/
(Disclaimer: I wrote the feed extension.)
(免责声明:我编写了提要扩展。)
回答by Lennart Regebro
Not Sphinx, but several of the sites at http://codespeak.net/are done with scripts that take ReST text, generates HTML and uploads them to the site. I didn't write those scripts though, but I've used them.
不是 Sphinx,而是http://codespeak.net/上的几个站点使用脚本完成,这些脚本采用 ReST 文本、生成 HTML 并将它们上传到站点。虽然我没有写这些脚本,但我已经使用过它们。
It's a reasonable way to generate sites if the sites need to contain a lot of ReST files anyway, like when generating documentation for python modules, which of course these sites are all about. It's also good if you need the site to be version controlled, because you can keep the source code in svn or hg, or something.
如果站点无论如何都需要包含大量 ReST 文件,那么这是一种生成站点的合理方法,例如在为 python 模块生成文档时,当然这些站点都是关于这些的。如果您需要对站点进行版本控制,这也很好,因为您可以将源代码保存在 svn 或 hg 中,或者其他格式。
But if you start writing a lot of automatic menues and other extensions, what you will end up with in the end is a content management system. And there is plenty of those around already, so you might want to look at them first.
但是,如果您开始编写大量自动菜单和其他扩展程序,您最终会得到一个内容管理系统。周围已经有很多这样的人,所以你可能想先看看他们。
Another example is the new packages.python.org. There you can generate your documentation in anyway you want it, and then through PyPI upload a zip-file with the docs. Distribute has done this with Sphinx: http://packages.python.org/distribute. But there no particular script is needed, that's just generating HTML from Sphinx documentation.
另一个例子是新的packages.python.org。在那里您可以随意生成文档,然后通过 PyPI 上传带有文档的 zip 文件。Distribute 已使用 Sphinx 完成此操作:http: //packages.python.org/distribute。但是不需要特定的脚本,只需从 Sphinx 文档生成 HTML。
However...
然而...
I must say that I find the idea of writing a blogging software as Sphinx extension a bit funny, especially since there is so much excellent blogging software out there already. And nothing is going to beat Wordpress anyway, and wordpress.com has been a great blogging experience for me. But as an exercise in how much you can abuse Sphinx, why not! :-)
我必须说,我发现将博客软件编写为 Sphinx 扩展的想法有点有趣,尤其是因为已经有很多优秀的博客软件。无论如何,没有什么能打败 Wordpress,而且 wordpress.com 对我来说是一次很棒的博客体验。但是作为练习您可以滥用 Sphinx 的程度,为什么不呢!:-)
回答by S.Lott
I redid my personal website (http://homepage.mac.com/s_lott/steve/) in Sphinx. It works nicely. Sadly, the SO markup mangles the _
in my URL.
我在 Sphinx 中重新制作了我的个人网站 ( http://homepage.mac.com/s_lott/steve/)。它工作得很好。 可悲的是,SO 标记破坏了_
我的 URL 中的 。
I also rewrote the entire Introduction to Programming for Non-Programmers(http://homepage.mac.com/s_lott/books/nonprog/html/index.html) book in Sphinx. I'm in the process of rewriting Introduction to Python in Sphinx.
我还在Sphinx 中重写了整个《非程序员编程简介》( http://homepage.mac.com/s_lott/books/nonprog/html/index.html) 一书。我正在用 Sphinx 重写 Python 简介。
I do not use Sphinx for blogs -- it's not perfectly convenient, but it would work. I use blogspotfor low-graphics/high-text and relatively high-velocity blogging. I use iWeb (http://web.me.com/s_lott/Travel/Welcome.html) for high graphic and relatively low-velocity blogging.
我不将 Sphinx 用于博客——它不是很方便,但它可以工作。我将blogspot用于低图形/高文本和相对高速的博客。我使用 iWeb ( http://web.me.com/s_lott/Travel/Welcome.html) 进行高图形和相对低速的博客。