Sphinx 是一个 Python 库,用于从一组 ReST 格式的文本文件。
不知道有没有人写过Sphinx插件,让它生成个人网站和博客。
特别是对于博客来说,需要有一种方法可以自动按时间顺序列出帖子并生成 RSS 提要。需要编写一个 Sphinx 插件来生成这种特殊的页面/xml。
以前有人尝试过这个吗?
Sphinx is a Python library to generate nice documentation from a set of ReST formatted text files.
I wonder if any one has written Sphinx plugins to make it generate personal websites and blogs.
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.
Has anyone tried this before?
发布评论
评论(8)
我已经在 http://reinout.vanrees.org/weblog 上完成了。关键技巧是添加预处理器步骤。我的博客条目位于
weblog/yyyy/mm/dd/
文件夹结构中。脚本会遍历该文件夹结构,在每个目录中创建
index.txt
文件,并列出子项。然后,正常的 Sphinx 进程会渲染这些index.txt
文件。我为标签添加了一个自定义 Sphinx 处理器。因此,我的博客条目顶部的“..tags::python,buildout”生成了标签。预处理器再次收集这些条目并写出一个
weblog/tags/TAGNAME.txt
文件,Sphinx 再次正常渲染该文件。预处理器还会创建包含最新 10 个条目的根
weblog/index.txt
。以及 rss feed 的(硬编码)输出目录中的weblog/atom.xml
。所以:你需要一些自定义的东西,但它几乎是纯文本,所以对我来说这是一个很好的练习。您可以编写一些帮助程序脚本来使生活变得轻松,例如将文本文件从某处复制到今天的博客目录的脚本(包括创建丢失的目录和“svn add”)。
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.A script iterates through that folder structure, creating
index.txt
files in every directory, listing the sub-items. The normal Sphinx process then renders thoseindex.txt
files.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.The preprocessor also creates the root
weblog/index.txt
with the latest 10 entries. And anweblog/atom.xml
in (hardcoded) the output directory for the rss feed.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").
如果您需要使用 reStructuredText 编写,您应该尝试
Pelican 是一个静态站点生成器,用 Python 编写。您将能够直接在 reStructuredText 或 Markdown 中编写博客条目。
If you need to write in reStructuredText , you should try Pelican.
Pelican is a static site generator, written in Python. You'll be able to write your blog entries directly in reStructuredText or Markdown.
截至目前(2012 年 2 月),有不同的资源可以满足您的需求:
基于 sphinx 的博客引擎:http://tinkerer.me/
Reinout Van Rees 的博客:https://github.com/reinout/reinout.vanrees.org
Feed contrib 扩展:https://bitbucket.org/birkenfeld/sphinx-contrib/src/提示/提要/自述文件
As of now (February, 2012), there are different resources available to do what you want:
A blog engine based on sphinx: http://tinkerer.me/
Reinout Van Rees' blog: https://github.com/reinout/reinout.vanrees.org
The feed contrib extension: https://bitbucket.org/birkenfeld/sphinx-contrib/src/tip/feed/README
Doug hellmann 是“本周 Python 模块”的作者,他使用 Sphinx 来创建他的网站。
http://www.doughellmann.com/PyMOTW/
他有几篇涉及 sphinx 主题的帖子也许可以帮助您:
http://blog.doughellmann.com
Doug hellmann, author of the 'Python Module of the Week' does his site using Sphinx.
http://www.doughellmann.com/PyMOTW/
He has several posts which cover sphinx topics that can probably help you on your way:
http://blog.doughellmann.com
查看 ABlog for Sphinx
我正在使用它自己创建一个博客。
我在 feedly 中查看 feed 时偶然发现了它。我搜索了一下,发现很有趣。它还具有 Disqus 集成,并且可以生成 Atom 提要(目前不太确定那是什么,我是网络新手)
我还没有弄清楚如何部署我的测试博客,当我发现一些东西时会更新。
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)
I have not yet figured out how to deploy my test blog, will update when i find out something.
值得一提的是,sphinx-contrib 扩展中有一个 sphinx 的 RSS 扩展,名为
sphinxcontrib.feed
它和许多其他有趣的 Sphinx 东西都位于 http://bitbucket.org/birkenfeld/sphinx-contrib/< /a>
(免责声明:我编写了提要扩展。)
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/
(Disclaimer: I wrote the feed extension.)
不是 Sphinx,但 http://codespeak.net/ 上的几个站点都是使用采用 ReST 文本的脚本完成的,生成 HTML 并将其上传到网站。虽然这些脚本不是我写的,但我使用过它们。
如果站点需要包含大量 ReST 文件,那么这是生成站点的合理方法,例如为 python 模块生成文档时,当然这些站点都是关于这些的。如果您需要对站点进行版本控制,这也很好,因为您可以将源代码保存在 svn 或 hg 等中。
但是,如果您开始编写大量自动菜单和其他扩展,那么最终您将得到一个内容管理系统。周围已经有很多这样的东西了,所以你可能想先看看它们。
另一个例子是新的packages.python.org。在那里,您可以按照您想要的任何方式生成文档,然后通过 PyPI 上传包含文档的 zip 文件。 Distribute 已经通过 Sphinx 做到了这一点: http://packages.python.org/distribute 。但不需要特定的脚本,只需从 Sphinx 文档生成 HTML 即可。
然而...
我必须说,我发现编写一个博客软件作为 Sphinx 扩展的想法有点有趣,特别是因为已经有很多优秀的博客软件了。无论如何,没有什么能打败 Wordpress,而且 wordpress.com 对我来说是一次很棒的博客体验。但作为一个练习,看看你可以在多大程度上滥用 Sphinx,为什么不呢! :-)
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.
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.
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.
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! :-)
我重新设计了我的个人网站 (http://homepage.mac.com/s_lott/steve/) 在狮身人面像中。效果很好。 遗憾的是,SO 标记破坏了我 URL 中的
_
。我还重写了整个非程序员编程简介(http://homepage.mac.com/s_lott/books/nonprog/html/index。 html)在 Sphinx 中书籍。我正在用 Sphinx 重写 Python 简介。
我不使用 Sphinx 来写博客——它不是很方便,但它可以工作。我使用 blogspot 来进行低图形/高文本和相对高速的博客。我使用 iWeb (http://web.me.com/s_lott/Travel/Welcome. html)用于高图形和相对低速的博客。
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.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.
I do not use Sphinx for blogs -- it's not perfectly convenient, but it would work. I use blogspot for 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.