Lektor简介—用于Python的静态文件内容管理系统

The longer I’m programming and creating software, the more I notice that I build a lot of stuff that requires maintenance even though it should not. In particular a topic that just keeps annoying me is how quickly technology moves forward and how much effort it is to maintain older code that still exists but now stands on ancient foundations.

我编程和创建软件的时间越长,我越会注意到我构建了很多需要维护的东西,即使它们不需要维护。 特别是让我一直烦恼的一个话题是技术的发展速度以及维护旧代码(现在仍然存在,但现在已经立足于古老的基础)付出了多大的努力。

This is not a new discovery mind you. This blog you’re reading started out as a Django application many, many years ago; made a transition to WordPress because I could not be bothered with updating Django; and then turned into two different static site generators because I did not want to bother with making database updates and rather wanted to track my content in a git repository.

这不是您的新发现。 许多年前,您正在阅读的博客最初是Django应用程序; 过渡到WordPress,因为我不必为更新Django所困扰; 然后变成了两个不同的静态站点生成器,因为我不想麻烦进行数据库更新,而是想在git存储库中跟踪我的内容。

I like static website generators quite a bit. As everything needs a website these days — it’s impossible to escape the work to create one. For programmers it’s possible to get away with building something with static website generators like Jekyll, Hexo, Hugo, Pelican, Hyde, Brunch, Middleman, Harp, Expose, …

我相当喜欢静态网站生成器。 如今,由于一切都需要一个网站-无法逃避创建网站的工作。 对于程序员而言,可以使用静态网站生成器(如Jekyll,Hexo,Hugo,Pelican,Hyde,Brunch,Middleman,Harp,Expose等)来构建东西。

As you can see the list of tools available is endless. Unfortunately though these tools are all aimed at programmers and it’s very hard to use them as someone without programming experience. Worse though: many of them are clones of each other just written in different programming languages with very similar designs. There is very little innovation in that space and that’s a bit unfortunate because I like the flexibility I get from frameworks like Flask at times.

如您所见,可用工具的列表是无止境的。 不幸的是,尽管这些工具都是针对程序员的,但是如果没有编程经验的人很难使用它们。 更糟糕的是:它们中的许多都是彼此克隆,只是用不同的编程语言编写的,它们的设计非常相似。 在那个领域几乎没有什么创新,这有点不幸,因为我有时喜欢从Flask这样的框架获得的灵活性。

所以我建立了自己的 (So I Built My Own)

This is by far not the first time I built a static website generator but I hope it will be the last time. This one however is different from any project I built before. The reason it exists is quite frankly that it’s impossible to escape family duties. For me that means helping out with the website of my parents. I knew that I did not want that to be WordPress or something that needs security updates so about two years ago I started to investigate that options there are.

到目前为止,这不是我第一次构建静态网站生成器,但我希望这将是最后一次。 但是,这与我之前构建的任何项目都不同。 坦率地说,存在它的原因是无法逃避家庭责任。 对我来说,这意味着帮助我父母的网站。 我知道我不希望它成为WordPress或需要安全性更新的东西,所以大约两年前,我开始调查其中的选项。

After a ton of toying around I ended up using Frozen-Flask for that project. It was neat because it allowed me to structure the website exactly like I wanted. However it also meant that whenever text started to change I needed to spend time on it. Thus I had to investigate CMS solutions again. Countless weekends were wasted trying to make WordPress work again and looking at Statamic. However I found them quite a bit more complex to customize than what I was used to with Frozen-Flask and they did not really fit the format at all. Especially WordPress feels much more like a blog engine than a CMS.

经过大量的玩弄之后,我最终为该项目使用了Frozen-Flask 。 整洁是因为它使我能够完全按照自己的意愿来构建网站。 但是,这也意味着,每当文本开始更改时,我都需要花时间在上面。 因此,我不得不再次研究CMS解决方案。 浪费了无数的周末,试图使WordPress重新工作并查看Statamic。 但是,我发现它们的自定义要比我以前使用Frozen-Flask复杂得多,并且它们根本不适合该格式。 特别是WordPress感觉更像是博客引擎,而不是CMS。

Finally I decided to sit down and build something completely different: a content management system that uses flat files as source files like most other systems, but it has a locally hosted admin panel that a non programmer can use. You install the application, double click on the project, a browser opens and you can edit the pages. It builds in the background into static HTML files and there is a publish button to ship it up to a server. For collaboration one can use Dropbox.

最终,我决定坐下来构建一个完全不同的东西:一个内容管理系统,它像大多数其他系统一样使用平面文件作为源文件,但是它具有本地托管的管理面板,非程序员可以使用。 安装应用程序,双击项目,浏览器打开,您可以编辑页面。 它在后台构建到静态HTML文件中,并且有一个发布按钮可将其发送到服务器。 对于协作,可以使用Dropbox。

输入Lektor (Enter Lektor)

I called this system Lektor and Open Sourced it initially a few months ago after not having cared about it in a year or so. However I had another run-in with a project which was the Sentry documentation. Sentry uses Sphinx for the documentation and customizing the docs for what we had in mind there turned out to be a complete waste of time and sanity. While Lektor is currently not in a position where it could replace Sphinx for Sentry it gave me enough motivation to hack on it again on weekends.

我在几个月左右没有关心它的几个月前,就将该系统称为Lektor,并在最初将其开源。 但是,我的另一个项目是Sentry文档。 Sentry使用Sphinx作为文档,并根据我们的想法自定义文档,结果发现这完全浪费了时间和理智。 虽然Lektor目前无法代替Sphinx换成Sentry,但它给了我足够的动力在周末再次破解它。

So I figured I might retry Open Sourcing it and made a website for it with documentation and cleaned up some bad stuff in it.

所以我想我可以重试Open Sourcing,并为其建立一个带有文档的网站,并清理其中的一些不良内容。

Here is what it looks like when you open up the admin panel:

这是您打开管理面板时的外观:

https://raw.githubusercontent.com/lektor/lektor-archive/master/screenshots/admin.png

Lektor是一个框架 (Lektor is a Framework)

But what makes Lektor so much fun to work with is that Lektor is (while very opinionated) very, very flexible. It takes a lot of inspiration from ORMs like Django’s. Instead of there being a “blog component” you can model your own blog posts and render them with the templates you want to use. There is not a single built-in template that you have to use. The only thing it gives you is a quickstart that sets up the folders and copies default minimalistic templates over.

但是让Lektor如此有趣的是,Lektor非常(非常固执)非常灵活。 它从Django之类的ORM中获得了很多启发。 您可以为自己的博客文章建模,并使用要使用的模板来呈现它们,而不是使用“博客组件”。 没有一个单一的内置模板,您必须使用。 它给您的唯一好处就是快速入门,它可以设置文件夹并复制默认的简约模板。

As an example, here is how a blog index template looks like:

例如,这是博客索引模板的外观:

{% {% extends extends "blog_layout.html" "blog_layout.html" %}
%}
{% {% from from "macros/pagination.html" "macros/pagination.html" import import render_pagination render_pagination %}
%}
{% {% block block title title %}My Blog%} My Blog {% {% endblock endblock %}
%}
{% {% block block body body %}
  %}
  <h1>My Blog<h1> My Blog </h1>

  </h1>

  <ul <ul class=class= "blog-index""blog-index" >
  >
  {% {% for for post post in in this.pagination.items this.pagination.items %}
    %}
    <li>
      <li>
      <a <a href=href= "" {{ {{ postpost || url url }}}} "" >> {{ {{ post.title post.title }}}} </a> —
      by </a> —
      by {{ {{ post.author post.author }}
      on }}
      on {{ {{ post.pub_datepost.pub_date || dateformat dateformat }}
  }}
  {% {% endfor endfor %}
  %}
  </ul>

  </ul>

  {% {% if if this.pagination.pages this.pagination.pages > > 1 1 %}
    %}
    {{ {{ render_paginationrender_pagination (( this.paginationthis.pagination ) ) }}
  }}
  {% {% endif endif %}
%}
{% {% endblock endblock %}
%}

The system understands what the blog is, that it has child record, that those records are paginated, it can provide pagination etc. However there is nothing in there that makes it a blog in itself. It just has a very flexible ORM inspired component that gives access to the structured files on the file system. Programming for Lektor feels very much like programming something with Flask or Django.

系统了解博客是什么,它有子记录,这些记录是分页的,可以提供分页等。但是,其中没有任何内容使它本身成为博客。 它只是具有一个非常灵活的ORM启发性组件,可以访问文件系统上的结构化文件。 为Lektor编程非常类似于使用Flask或Django进行编程。

学到更多 (Learn More)

If you want to learn more about it, there are quite a few resources at this point:

如果您想进一步了解它,那么此时有很多资源:

最后的话 (Final Words)

I hope people find it useful. I know that I enjoy using it a ton and I hope it makes others enjoy it similarly. Because I run so many Open Source projects and maintenance of all of them turns out to be tricky I figured I do this better this time around. Lektor belongs to a separate org and the project does not use any resources only I have access to (other than the domain name and the server travis-CI deploys to). So in case people want to help out, there is no single point of failure!

我希望人们觉得它有用。 我知道我喜欢大量使用它,希望它能使其他人也同样喜欢它。 因为我运行了很多开源项目,并且所有项目的维护都非常棘手,所以我认为这次可以做得更好。 Lektor属于一个单独的组织,该项目仅使用我有权访问的任何资源(域名和travis-CI部署的服务器除外)。 因此,如果人们想提供帮助,就不会有单点故障!

I hope I can spend some time over Christmas to do the same to my other projects and alter the bus factor of them.

我希望我可以在圣诞节期间花一些时间对我的其他项目做同样的事情,并改变它们的公交系数。

There is far too much in Lektor to be able to cover it in a single blog post so I will probably write a bit more about some of the really cool things about in in the next few weeks. Enjoy!

Lektor的内容太多了,无法在一个博客文章中进行介绍,因此我可能会在接下来的几周内写一些关于一些非常酷的事情。 请享用!

翻译自: https://www.pybloggers.com/2015/12/introducing-lektor-a-static-file-content-management-system-for-python/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值