swg-一个静态网站生成器
swg的Python项目详细描述
Simone Margaritelli版权所有evilsocket@gmail.com>;
什么是SWG?
swg是新一代的静态网站生成器,以mako(http://www.makotemplates.org/)模板系统为特色,源于 既有性能又有“web 2.0”的内容和能力。
给定一组文件,每个页面/文章一个,每个作者一个,类别hyerarchy一个,swg将读取配置文件 您从命令行指定并生成一个完整的静态网站,带有标签和类别索引。
安装
要获取最新版本:
pip install swg
创建新网站
要创建新网站,请键入:
swg --create website-folder-name
将在“网站文件夹名称”目录内创建具有基本结构的示例网站。 然后您可以键入:
cd website-folder-name swg --serve
在本地测试网站。 第一篇文章是关于定制和基本配置的,所以请仔细阅读。
生成您的网站
一旦您进入包含网站定义的目录(其中包含swg.cfg文件),只需运行:
swg --generate
要开始生成网站,可以使用其他选项,请使用
swg --help
以显示完整的列表。
从其他平台导入
现在,可以使用swg wordpress脚本将wordpress xml备份文件转换为 swg格式,要使用它,请考虑以下内容:
swg-wordpress --help - SWG Wordpress Backup Importer - Usage: swg-wordpress -i wordpress-backup.xml -u 'http://www.your-site-url.com' <options> Options: -h, --help show this help message and exit -i WPBACKUP, --input=WPBACKUP The Wordpress XML backup file. -u SITEURL, --url=SITEURL URL of the destination website. -o OUTDIR, --output=OUTDIR Output directory, default is the current working directory. -e FILEEXT, --extension=FILEEXT Output file extension, default is txt. -I IMGDIR, --images=IMGDIR If specified, it's the path where the importer will try to download images referenced by articles.
例如,假设您有wp.xml文件,希望将其导出到'example site.com'目录,下载 文章引用到“example site.com/images”目录中的图像(导入将正确替换图像url),您可以 将使用命令行:
swg-wordpress -i wp.xml -u http://www.example-site.com -o 'example-site.com' -I 'example-site.com/images'
一切都结束了! 现在您只需创建模板,修复文件'example site.com/db/categories.txt'中的类别hyerarchy,自定义 您自己在“example site.com/db/your nickname.txt”中的描述,并按照下面的示例创建配置文件。
配置文件示例
# DB files extension dbitem_ext = txt # URL of the site you are going to generate siteurl = http://www.example-site.com # Site name / description sitename = An example site generated by SWG # Site charset charset = utf-8 # Site language language = it # Comma separated site keywords keywords = some, html, keywords, here # Site destination basepath basepath = # Site page files output extension page_ext = html # Generated site output path outputpath = out # Items (dirs or files) to copy from datapath to outputpath (eg. static files, css, etc) copypaths = css, images, .htaccess # Command to execute once the generation is finished, for instance an rsync :) transfer = rsync -ravz out/* -e ssh user@example-site.com:/var/www/example-site.com/htdocs/ # Enable or disable the pager on categories, index, tags and author pages pager = true # If pager is enabled, this is the maximum number of items per page items_per_page = 10 # Compress pages (ie. index.html.gz) and create (or update) .htaccess file to serve them as html files gzip = true # Compression level, 0 to 9 compression = 9 # Clean output html with TIDY tidyfy = true
很不言而喻,不是吗?:)
在本地测试您的网站
从版本1.2.4,swg提供了在本地测试您的网站的可能性,一旦您在包含您的网站定义的目录中 (包含swg.cfg文件),运行以下命令:
swg --serve
这将在http://localhost:8080/上启动网站生成和测试web服务器。