Total Pageviews

Sunday 26 November 2017

静态网站生成器-ingsoc


ingsoc is a static site generator written in Python with the purpose of generating raymii.org. It differs from other static site generators because it does not create a blog-like site, but it is focused on pages and structure. It also does not use a template engine. It generates categories, pages, tags, an XML sitemap and a RSS feed. It takes markdown files with a yaml config header as input, and outputs html.

Usage

ingsoc requires three directories and content to work. The directory structure can be as below:
$ tree
.
|-- ci.sh
|-- config.yml
|-- minify.py
|-- newspeak.py
|-- inc
|   |-- css
|   |   |-- example.css
|   |-- img
|   |   |-- example.png
|   |-- js
|   |   |-- example.js
|-- src
|   |-- software
|   |   |-- ingsoc.md
|   |   |-- Awesome_Example_Application.md
|   `-- tutorials
|       |-- Awesome_Tutorial_1.md
|       |-- Tutorial_2.md
|-- out
|   |-- everything.html
|   |-- feed.xml
|   |-- inc
|   |   |-- css
|   |   |   |-- example.css
|   |   |-- img
|   |   |   |-- example.png
|   |   |-- js
|   |   |   |-- example.js
|   |-- index.html
|   |-- sitemap.xml
|   |-- software
|   |   |-- ingsoc.html
|   |   |-- Awesome_Example_Application.html
|   |-- tags
|   |   |-- tag1.html
|   |   |-- tag2.html
|   |   |-- tag3.html
|   `-- tutorials
|       |-- Awesome_Tutorial_1.html
|       |-- Tutorial_2.html
`-- tests
    |-- broken-link-check.py
    |-- dead-link-checker.py
    |-- spell-check.py
    |-- w3-validate.sh
    `-- words-to-ignore.txt
I have a src directory with my content, which is written in markdown. The inc directory gets copied over to the output folder, it has the css, js, images and other static content. The out folder is the folder where ingsoc puts its generated html.

Content

A content item is a markdown file, with a yaml header. The header looks like this:
title: "Example Title"
author: "John Doe"
category: "software"
date: "29-06-2015"
minify: false
summary: "This is a great article about some stuff related to Lorum Ipsum. The summary of this article is even more awesome."
tags: 
  - example
  - lorum
  - ipsum
  - tag
---
Then below the three dashes (---) the actual markdown content is placed. The category item is what also end up in the menu. The date and summary are used in the RSS. The summary is the only field which is not required.
There is a post generation step in which the css and generated html are minified. The minify: False optional option (default is True) allows a page to be excluded from the minification.

Configuration

There is also a config.yml file. It looks like this:
title: "Awesome Website"
subtitle: "Awesome Slogan!"
rootdir: "./src"
outdir: "out"
incfolder: "./inc"
breadcrumbs: "yes"
tags: "yes"
rsstitle: "Awesome Website RSS Feed"
rssdescr: "The Awesome Website RSS feed, all about awesome stuff"
rssurl: "https://raymii.org/s/"

homepagetext: >
    <h3>Welcome!</h3>
    This is the <strong>most awesome site</strong> on the entire internet.
The homepagetext item is the raw html code which is put on the index.html code. the tags and breadcrumbs are used to define if tags and breadcrumbs should be generated and placed or not.

Tests

I have a Jenkins CI running which after every push starts a test suite. The test suite tests the following things:
  • Valid HTML code - I run a copy of the w3 HTML validator locally
  • Spellig errors
  • Dead links

Requirements

The minification also requires the cssmin and htmlmin.minify modules. It is fully threaded, minifying at least 4 pages at once.
To install them in a standard ubuntu/debian:
sudo apt-get install python-pip
and then:
sudo pip install misaka pyyaml dateutils

sudo apt-get install python-pip
and then:
sudo pip install misaka pyyaml dateutils 
 
from https://raymii.org/s/software/ingsoc.html 

No comments:

Post a Comment