Total Pageviews

Saturday, 23 November 2013

在linux vps上搭建基于python的静态博客程序-obraz

as3:~# pip install obraz
as3:~# mkdir obraz-site
 as3:~# cd obraz-site
as3:~/obraz-site# 
(目录结构为:
|-- _layouts
|   |-- default.html
|   `-- post.html
|-- _posts
|   |-- 2012-05-24-hello-world.md
|   `-- 2012-05-25-second-blog-post.md
`-- index.html 
这个目录结构和下面的文件具有普遍适用性 
  as3:~/obraz-site# mkdir _layouts  _posts
  as3:~/obraz-site# nano index.html
(index.html的内容为:
---
layout: default
---

<div>
  <h1>My Blog</h1>
  <p>Welcome to my blog!</p>
  <ul>
  {% for post in site.posts %}
    <li class="entry">
      <span class="date">{{ post.date }}</span>
      <a href="{{ post.url }}">{{ post.title }}</a>
    </li>
  {% endfor %}
  </ul>
</div> ) 
as3:~/obraz-site# cd  _layouts
as3:~/obraz-site/_layouts# nano default.html
( default.html的内容为:
---
---

<!DOCTYPE html>
<html>
  <head>
    <title>My Blog - {{ page.title }}</title>
  </head>
  <body>
    {{ content }}
  </body>
</html>  )
 as3:~/obraz-site/_layouts# nano post.html
(post.html的内容为:
---
layout: default
---

<div class="entry">
  <h1>{{ page.title }}</h1>
  <p>Created at {{ page.date }}.</p>
  {{ content }}
</div>  )
as3:~/obraz-site/_layouts# cd ../_posts
as3:~/obraz-site/_posts# nano 2012-05-24-hello-world.md
( 2012-05-24-hello-world.md的内容为:
---
layout: post
title: Hello, World!
---

This is my _first_ blog post!
It uses:
* YAML for metadata
* Markdown for formatting
* Obraz for static generation )
as3:~/obraz-site/_posts# nano 2012-05-25-second-blog-post.md
2012-05-25-second-blog-post.md的内容为:
---
layout: post
title: Second Blog Post
---

Just another blog post.  )
as3:~/obraz-site/_posts# cd ~ 
as3:~# obraz ~/obraz-site/ 
(所产生的静态站点将出现在 ~/obraz-site/_site/,obraz ~/obraz-site/ 就是生成/更新静态网站的命令
as3:~# cd ~/obraz-site/_site/
as3:~/obraz-site/_site# 
as3:~/obraz-site/_site# ls
2012  index.html  (可见 ~/obraz-site/_site/就是静态网站的根目录)
as3:~/obraz-site/_site# python -m SimpleHTTPServer 56742 & 
python -m SimpleHTTPServer some_port  就是著名的基于python的运行静态网站的命令
 
This is the list of several sites that are generated using Obraz:
The source code is available on the Bitbucket:
$ hg clone https://bitbucket.org/vlasovskikh/obraz 

演示站点: http://as3.brite.biz:56742/,http://or.brite.biz/
使用指南:http://obraz.pirx.ru/