Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Releasing 1.2.7, static pages support and bug fixes.

  • Loading branch information...
commit b82f5b8c79dd5ac65cc36e9a2bcc7d7d6c5d2ecd 1 parent 50a1afd
@evilsocket authored
View
10 README.md
@@ -2,8 +2,6 @@ SWG - Static Website Generator
==============================
Copyleft by Simone Margaritelli <evilsocket@gmail.com>
-http://www.evilsocket.net/
-http://www.github.com/evilsocket
What is SWG ?
-------------
@@ -63,15 +61,15 @@ To a display the complete list.
Importing from another platform
-------------------------------
-Right now, in the 'importers' directory of the project, there's a script to convert a WordPress XML backup file to the
+Right now, there's the swg-wordpress script you can use to convert a WordPress XML backup file to the
SWG format, to use it consider the following:
::
- python wordpress.py --help
+ swg-wordpress --help
- SWG Wordpress Backup Importer -
- Usage: wordpress.py -i wordpress-backup.xml -u 'http://www.your-site-url.com' <options>
+ Usage: swg-wordpress -i wordpress-backup.xml -u 'http://www.your-site-url.com' <options>
Options:
@@ -95,7 +93,7 @@ will use the command line:
::
- python wordpress.py -i wp.xml -u http://www.example-site.com -o 'example-site.com' -I 'example-site.com/images'
+ swg-wordpress -i wp.xml -u http://www.example-site.com -o 'example-site.com' -I 'example-site.com/images'
And it's all done!
Now you just have to create the templates, fix the categories hyerarchy inside the file 'example-site.com/db/categories.txt', customize
View
7 setup.py
@@ -12,7 +12,7 @@ def find_package_data( where = '.',
exclude = ( '*.pyc', '*~', '*.bak', '*.swp*', '.*'),
exclude_directories = ('.*', 'CVS', '_darcs', './build', './dist', 'EGG-INFO', '*.egg-info'),
only_in_packages = True,
- show_ignored = False):
+ show_ignored = False ):
out = {}
stack = [(convert_path(where), '', package, only_in_packages)]
@@ -68,8 +68,9 @@ def find_package_data( where = '.',
packages = find_packages(),
include_package_data = True,
package_data = find_package_data( package = 'swg', only_in_packages = False ),
- install_requires = ( 'mako >= 0.4.1', 'pytidylib >= 0.2.1' ),
- scripts = [ 'swg/swg' ],
+ install_requires = ( 'mako >= 0.4.1', 'utidylib' ),
+ dependency_links = [ 'http://cctools.svn.sourceforge.net/svnroot/cctools/vendorlibs/utidylib/#egg=utidylib-0.2-cvs' ],
+ scripts = [ 'swg/swg', 'swg/swg-wordpress' ],
license = 'GPL',
zip_safe = False,
classifiers = [
View
147 swg/basic/db/pages/0.txt
@@ -2,151 +2,12 @@ Date: 2011-04-25 17:34:00
Author: Your Name Here
Categories: Personal, Experience
Tags: swg, test, post, basic, website, structure
-Title: Hello World / Instructions
+Title: Hello World
<p align="justify">
Hello world!
-This is your new static website installation, to read the instructions on how to customize everything, please click on the <b>Read More</b>
-link.
-
-<break>
-
-<ul>
- <li><a href="#intro0">Changing website main properties</a></li>
- <li><a href="#intro1">Setting up your author name</a></li>
- <li><a href="#intro2">Defining site categories</a></li>
- <li><a href="#intro3">Customizing the templates</a></li>
- <li><a href="#intro4">Creating a new article</a></li>
- <li><a href="#intro5">Add comment capabilities to each article</a></li>
- <li><a href="#final"><b>!!! Final Note !!!</b></a></li>
-</ul>
-
-<h2><a name="intro0">Changing website main properties</a></h2>
-You can change those properties by editing the <b>swg.cfg</b> file inside the folder of the site project, the main properties you are probably
-interested in are:
-
-<pre>
-siteurl = http://www.swg-example-website.com
-sitename = SWG Example Website
-charset = utf-8
-language = en
-keywords = swg,example,website,static,static website,generator,static website generator
-</pre>
-
-Where siteurl is the url of your website, sitename the name displayed in the header, then you can define the html charset and language and finally the
-keywords to be used in the meta html fields.
-
-<h2><a name="intro1">Setting up your author name</a></h2>
-The first thing you wanna do, is to change the main author name, because as you have noticed it's set to '<b>Your Name Here</b>' right now ... pretty ugly isn't it?
-
-Open the file <b>db/Your Name Here.txt</b> with your favourite text editor (better if it supports HTML syntax highlighting) and edit the first four rows with your
-own details, for instance:
-
-<pre>
-username: Joe Black
-avatar: /images/myavatar.png
-email: joeblack@gmail.com
-website: http://www.example-website.com
-</pre>
-
-Leave the next line empty and write something about yourself (HTML allowed), this description will be the one displayed in the <b>About Me</b> section.
-Now <b>rename</b> the file with the username you've just used in those fields, so it will be renamed (following the example) like so:
-
-<pre>
-db/Your Name Here.txt ---> renamed to ---> db/Joe Black.txt
-</pre>
-
-Also you will have to replace the string <b>your-name-here</b> with <b>joe-black</b> inside <b>templates/sidebar.tpl</b> and <b>templates/header.tpl</b> to fix
-the links to your profile.
-
-<h2><a name="intro2">Defining site categories</a></h2>
-To define the hierarchy of your categories, open the file <b>db/categories.txt</b> and edit it.
-Each line must begin with one root category, so for instance:
-
-<pre>
-Personal
-Experience
-</pre>
-
-Are two root categories.
-To add a new one, simply add a new line with the name of the new category.
-
-If you want to define a <b>sub category</b>, you shall use the following syntax:
-
-<pre>
-Personal: Projects, Work
-Experience
-</pre>
-
-So that <b>Projects</b> and <b>Work</b> are now sub categories of <b>Personal</b>.
-
-<h2><a name="intro3">Customizing the templates</a></h2>
-SWG uses the <a href="http://www.makotemplates.org/" target="_blank">Mako Template Engine</a> to render the html contents, so you might want to follow its
-<a href="http://www.makotemplates.org/docs/" target="_blank">documentation</a> to fully understand how to customize the tpl files inside the <b>templates</b>
-directory.
-
-Anyway, if you just want to edit the html, reading the Mako documentation is not needed, you can edit the templates just as normal html files :)
-
-<h2><a name="intro4">Creating a new article</a></h2>
-Once you are in your website SWG folder, you can use the command:
-
-<pre>
-swg --new
-</pre>
-
-or
-
-<pre>
-swg -N
-</pre>
-
-To create a new entry.
-The editor you've configured in your swg.cfg file will then be available to edit the new entry and you will have to fill the first lines:
-
-<pre>
-Date: 2011-04-25 17:34:00
-Author: Joe Black
-Categories: Personal, Experience
-Tags: put, some, comma, separated, tag, here
-Title: Hello World again, put the title here.
-</pre>
-
-Leave the following line blank and start inserting the content.
-If you want to split the abstract of the article and the body itself, you can use the optional <b>&lt;break&gt;</b> tag, for instance:
-
-<pre>
-Date: 2011-04-25 17:34:00
-Author: Joe Black
-Categories: Personal, Experience
-Tags: put, some, comma, separated, tag, here
-Title: Hello World again, put the title here.
-
-&lt;p&gt;
- This is the abstract.
- <b>&lt;break&gt;</b>
- And this is the rest of the article that will be shown only in the article page itself.
-&lt;/p&gt;
-</pre>
-
-<h2><a name="intro5">Add comment capabilities to each article</a></h2>
-You can easily add a comment feature to each article using the <a href="http://disqus.com/" target="_blank">DISQUS</a> free service,
-just register your website and edit the file <b>templates/page.tpl</b> adding the DISQUS javascript code where you want the comments
-to be shown.
-
-<h2><a name="final">Final Note</a></h2>
-After <b>every</b> modification to the site, do not forget to regenerate it with the:
-
-<pre>
-swg --generate
-</pre>
-
-command executed inside the website folder, or, to test it locally:
-
-<pre>
-swg --serve
-</pre>
-
-Then you will be able to browse it at the address <em>http://localhost:8080</em> .
-
+This is your new static website installation, to read the instructions on how to customize everything, please click on the <b>Instructions</b>
+link on top menu.
</p>
+
View
150 swg/basic/db/pages/1.txt
@@ -0,0 +1,150 @@
+Date: 2011-04-25 17:34:00
+Static: true
+Author: Your Name Here
+Categories: Personal, Experience
+Tags: swg, test, post, basic, website, structure, instructions, howto, doc, documentation
+Title: Instructions
+
+<p align="justify">
+
+<break>
+
+<ul>
+ <li><a href="#intro0">Changing website main properties</a></li>
+ <li><a href="#intro1">Setting up your author name</a></li>
+ <li><a href="#intro2">Defining site categories</a></li>
+ <li><a href="#intro3">Customizing the templates</a></li>
+ <li><a href="#intro4">Creating a new article</a></li>
+ <li><a href="#intro5">Add comment capabilities to each article</a></li>
+ <li><a href="#final"><b>!!! Final Note !!!</b></a></li>
+</ul>
+
+<h2><a name="intro0">Changing website main properties</a></h2>
+You can change those properties by editing the <b>swg.cfg</b> file inside the folder of the site project, the main properties you are probably
+interested in are:
+
+<pre>
+siteurl = http://www.swg-example-website.com
+sitename = SWG Example Website
+charset = utf-8
+language = en
+keywords = swg,example,website,static,static website,generator,static website generator
+</pre>
+
+Where siteurl is the url of your website, sitename the name displayed in the header, then you can define the html charset and language and finally the
+keywords to be used in the meta html fields.
+
+<h2><a name="intro1">Setting up your author name</a></h2>
+The first thing you wanna do, is to change the main author name, because as you have noticed it's set to '<b>Your Name Here</b>' right now ... pretty ugly isn't it?
+
+Open the file <b>db/Your Name Here.txt</b> with your favourite text editor (better if it supports HTML syntax highlighting) and edit the first four rows with your
+own details, for instance:
+
+<pre>
+username: Joe Black
+avatar: /images/myavatar.png
+email: joeblack@gmail.com
+website: http://www.example-website.com
+</pre>
+
+Leave the next line empty and write something about yourself (HTML allowed), this description will be the one displayed in the <b>About Me</b> section.
+Now <b>rename</b> the file with the username you've just used in those fields, so it will be renamed (following the example) like so:
+
+<pre>
+db/Your Name Here.txt ---> renamed to ---> db/Joe Black.txt
+</pre>
+
+Also you will have to replace the string <b>your-name-here</b> with <b>joe-black</b> inside <b>templates/sidebar.tpl</b> and <b>templates/header.tpl</b> to fix
+the links to your profile.
+
+<h2><a name="intro2">Defining site categories</a></h2>
+To define the hierarchy of your categories, open the file <b>db/categories.txt</b> and edit it.
+Each line must begin with one root category, so for instance:
+
+<pre>
+Personal
+Experience
+</pre>
+
+Are two root categories.
+To add a new one, simply add a new line with the name of the new category.
+
+If you want to define a <b>sub category</b>, you shall use the following syntax:
+
+<pre>
+Personal: Projects, Work
+Experience
+</pre>
+
+So that <b>Projects</b> and <b>Work</b> are now sub categories of <b>Personal</b>.
+
+<h2><a name="intro3">Customizing the templates</a></h2>
+SWG uses the <a href="http://www.makotemplates.org/" target="_blank">Mako Template Engine</a> to render the html contents, so you might want to follow its
+<a href="http://www.makotemplates.org/docs/" target="_blank">documentation</a> to fully understand how to customize the tpl files inside the <b>templates</b>
+directory.
+
+Anyway, if you just want to edit the html, reading the Mako documentation is not needed, you can edit the templates just as normal html files :)
+
+<h2><a name="intro4">Creating a new article</a></h2>
+Once you are in your website SWG folder, you can use the command:
+
+<pre>
+swg --new
+</pre>
+
+or
+
+<pre>
+swg -N
+</pre>
+
+To create a new entry.
+The editor you've configured in your swg.cfg file will then be available to edit the new entry and you will have to fill the first lines:
+
+<pre>
+Date: 2011-04-25 17:34:00
+Author: Joe Black
+Categories: Personal, Experience
+Tags: put, some, comma, separated, tag, here
+Title: Hello World again, put the title here.
+</pre>
+
+Leave the following line blank and start inserting the content.
+If you want to split the abstract of the article and the body itself, you can use the optional <b>&lt;break&gt;</b> tag, for instance:
+
+<pre>
+Date: 2011-04-25 17:34:00
+Author: Joe Black
+Categories: Personal, Experience
+Tags: put, some, comma, separated, tag, here
+Title: Hello World again, put the title here.
+
+&lt;p&gt;
+ This is the abstract.
+ <b>&lt;break&gt;</b>
+ And this is the rest of the article that will be shown only in the article page itself.
+&lt;/p&gt;
+</pre>
+
+<h2><a name="intro5">Add comment capabilities to each article</a></h2>
+You can easily add a comment feature to each article using the <a href="http://disqus.com/" target="_blank">DISQUS</a> free service,
+just register your website and edit the file <b>templates/page.tpl</b> adding the DISQUS javascript code where you want the comments
+to be shown.
+
+<h2><a name="final">Final Note</a></h2>
+After <b>every</b> modification to the site, do not forget to regenerate it with the:
+
+<pre>
+swg --generate
+</pre>
+
+command executed inside the website folder, or, to test it locally:
+
+<pre>
+swg --serve
+</pre>
+
+Then you will be able to browse it at the address <em>http://localhost:8080</em> .
+
+</p>
+
View
11 swg/basic/db/pages/2.txt
@@ -0,0 +1,11 @@
+Date: 2011-04-24 17:34:00
+Author: Your Name Here
+Categories: Personal, Experience
+Tags: swg, test, post, basic, website, structure
+Title: Worth A Thousand Words
+
+<p align="justify">
+<img src='/images/boat.jpg'/>
+</p>
+
+
View
BIN  swg/basic/images/boat.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2  swg/basic/templates/author.tpl
@@ -13,7 +13,7 @@
<br/>
<h3 class="entrytitle">I wrote ${len(author.items)} articles:</h3>
<br/>
- % for page in pager.getCurrentPages():
+ % for page in pager.getCurrentPages( includeStatic = True ):
<div class="post post-index" id="post" >
<h2 class="entry-title index-entry-title"><a href="${config.siteurl}${page.url}" title="${page.title | h}">${page.title | h}</a> </h2>
View
12 swg/basic/templates/header.tpl
@@ -71,6 +71,7 @@
>
<a href='${config.siteurl}/index.${config.page_ext}'>Home</a>
</li>
+
%for cat in categories:
%if category != UNDEFINED and category.title == cat.title:
<li class="cat-item current-cat"><a href="${config.siteurl}${cat.url}" title="View category ${cat.title | h} archive">${cat.title | h}</a></li>
@@ -88,6 +89,17 @@
>
<a href='${config.siteurl}/members/your-name-here.${config.page_ext}'>About Me</a>
</li>
+
+ <li
+ %if page != UNDEFINED and page.title == 'Instructions':
+ class="cat-item current-cat"
+ %else:
+ class="cat-item"
+ %endif
+ >
+ <a href='${config.siteurl}${swg.getPageByTitle('Instructions').url}'>Instructions</a>
+ </li>
+
</ul>
</div>
View
54 swg/basic/templates/sidebar.tpl
@@ -1,53 +1,35 @@
# -*- coding: utf-8 -*-
<div id="sidebar">
<ul id="sidelist">
- <li id="pages-3" class="widget widget_pages"><h2 class="widgettitle">Pages</h2>
- <ul>
- <li
- %if page != UNDEFINED and page.title == 'index':
- class="cat-item current-cat"
- %else:
- class="cat-item"
- %endif
- >
- <a href='${config.siteurl}/index.${config.page_ext}'>Home</a>
- </li>
-
- <li
- %if author != UNDEFINED:
- class="cat-item current-cat"
- %else:
- class="cat-item"
- %endif
- >
- <a href='${config.siteurl}/members/your-name-here.${config.page_ext}'>About Me</a>
- </li>
- </ul>
- </li>
+ <li id="pages-3" class="widget widget_pages"><h2 class="widgettitle">Pages</h2>
+ <ul>
+ <li class="cat-item"><a href='${config.siteurl}/index.${config.page_ext}'>Home</a></li>
+ %for static in swg.getStaticPages():
+ <li class="cat-item"><a href="${config.siteurl}${static.url}" title="${static.title | h}">${static.title | h}</a></li>
+ %endfor
+ <li class="cat-item"><a href='${config.siteurl}/members/your-name-here.${config.page_ext}'>About Me</a></li>
+ </ul>
+ </li>
<li id="categories-2" class="widget widget_categories"><h2 class="widgettitle">Categories</h2>
- <ul>
+ <ul>
%for cat in categories:
- %if category != UNDEFINED and category.title == cat.title:
- <li class="cat-item current-cat"><a href="${config.siteurl}${cat.url}" title="View category ${cat.title | h} archive">${cat.title | h}</a></li>
- %else:
- <li class="cat-item"><a href="${config.siteurl}${cat.url}" title="View category ${cat.title | h} archive">${cat.title | h}</a></li>
- %endif
+ <li class="cat-item"><a href="${config.siteurl}${cat.url}" title="View category ${cat.title | h} archive">${cat.title | h}</a></li>
%endfor
- </ul>
+ </ul>
</li>
<li id="linkcat-2" class="widget widget_links"><h2 class="widgettitle">Blogroll</h2>
- <ul class='xoxo blogroll'>
+ <ul class='blogroll'>
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
<li><a href="#">Example Link</a></li>
- </ul>
+ </ul>
</li>
- <div id="tag_cloud" class="widget">
- <h2>Tag Cloud</h2>
+ <div id="tag_cloud" class="widget">
+ <h2>Tag Cloud</h2>
<%
import math
import random
@@ -63,7 +45,9 @@
% for tag in randomized:
<%
current = len( tag.items )
- weight = ( math.log(current) - math.log(minOccurs) ) / ( math.log(maxOccurs) - math.log(minOccurs) );
+ a = math.log(current) - math.log(minOccurs)
+ b = math.log(maxOccurs) - math.log(minOccurs)
+ weight = (a / b) if b != 0 else a
size = minFontSize + round( ( maxFontSize - minFontSize ) * weight );
%>
<a href="${config.siteurl}${tag.url}" title="${len(tag.items)} argomenti" style="font-size: ${size}px">${tag.title | h}</a>
View
3  swg/core/categorymanager.py
@@ -78,8 +78,7 @@ def __build_hierarchy(self):
if ':' in line:
( root, children ) = line.split( ':', 1 )
root = root.strip()
- children = children.strip().split(',')
- children = map( lambda s: s.strip(), children )
+ children = [ s.strip() for s in children.strip().split(',') ]
else:
root = line
children = []
View
8 swg/core/config.py
@@ -25,7 +25,7 @@
class Config:
__instance = None;
- version = '1.2.6'
+ version = '1.2.7'
def __init__(self):
self.now = datetime.datetime.now()
@@ -95,13 +95,11 @@ def load( self, filename ):
elif key == 'items_per_page':
self.items_per_page = int(value)
elif key == 'copypaths':
- items = value.split(',')
- items = map( lambda s: s.strip(), items )
+ items = [ s.strip() for s in value.split(',') ]
for item in items:
self.copypaths[ os.path.join( self.datapath, item ) ] = os.path.join( self.outputpath, item )
elif key == 'keywords':
- items = value.split(',')
- self.keywords = map( lambda s: s.strip(), items )
+ self.keywords = [ s.strip() for s in value.split(',') ]
elif key == 'transfer':
self.transfer = value
else:
View
43 swg/core/itemparser.py
@@ -69,14 +69,15 @@ def __parse_datetime( self, data ):
return datetime.datetime.strptime( data, '%Y-%m-%d %H:%M:%S' )
def __parse_string( self, data ):
- return data.strip()
+ return data
def __parse_array( self, data ):
- data = data.strip()
- items = data.split(',')
- return map( lambda s: s.strip(), items )
+ return [ s.strip() for s in data.split(',') ]
+
+ def __parse_boolean( self, data ):
+ return True if data.lower() == 'true' else False
- def parse( self, mandatory_fields_map, filename ):
+ def parse( self, mandatory_fields_map, filename, optional_fields_map = None ):
fd = codecs.open( filename, "r", "utf-8" )
self.state = ItemParser.PARSE_INFO_STATE
@@ -90,19 +91,25 @@ def parse( self, mandatory_fields_map, filename ):
( info_id, info_data ) = line.split( ':', 1 )
info_id = info_id.strip().lower()
info_data = info_data.strip()
-
- if mandatory_fields_map.has_key(info_id):
- type = mandatory_fields_map[info_id]
- if type == 'datetime':
- self.info[info_id] = self.__parse_datetime(info_data)
- elif type == 'string':
- self.info[info_id] = self.__parse_string(info_data)
- elif type == 'array':
- self.info[info_id] = self.__parse_array(info_data)
-
- else:
- raise Exception( "Unknown key %s on line %d." % ( info_id, self.lineno ) )
-
+ info_type = None
+
+ try:
+ info_type = mandatory_fields_map[info_id]
+ except KeyError:
+ try:
+ info_type = optional_fields_map[info_id]
+ except:
+ raise Exception( "Unknown key %s on line %d." % ( info_id, self.lineno ) )
+
+ if info_type == 'datetime':
+ self.info[info_id] = self.__parse_datetime(info_data)
+ elif info_type == 'string':
+ self.info[info_id] = self.__parse_string(info_data)
+ elif info_type == 'array':
+ self.info[info_id] = self.__parse_array(info_data)
+ elif info_type == 'boolean':
+ self.info[info_id] = self.__parse_boolean(info_data)
+
elif self.state == ItemParser.PARSE_BODY_STATE:
self.body += line
else:
View
9 swg/core/pageparser.py
@@ -32,15 +32,22 @@ class PageParser(ItemParser):
'tags' : 'array',
'title' : 'string'
}
+
+ OPTIONAL_FIELDS = {
+ 'static' : 'boolean'
+ }
def __init__(self):
ItemParser.__init__(self)
def parse( self, filename ):
- ItemParser.parse( self, PageParser.MANDATORY_FIELDS, filename )
+ ItemParser.parse( self, PageParser.MANDATORY_FIELDS, filename, PageParser.OPTIONAL_FIELDS )
page = Page( self.info['title'] )
+ if 'static' in self.info:
+ page.static = self.info['static']
+
author = AuthorManager.getInstance().get( self.info['author'] )
author.items.append(page)
View
27 swg/core/pager.py
@@ -36,7 +36,7 @@ def __init__( self, firstpage, format ):
def setPages( self, pages ):
self.pages = pages
- self.max = len(pages)
+ self.max = len(pages)
self.left = self.max
self.total = math.ceil( self.max / self.config.items_per_page )
self.total += 1 if self.max % self.config.items_per_page != 0 else 0
@@ -51,17 +51,32 @@ def getCurrentPageNumber(self):
def getTotalPages(self):
return self.total
- def getCurrentPages(self):
- begin = (self.pagen - 1) * self.config.items_per_page
- end = (begin + self.config.items_per_page) if self.left > self.config.items_per_page else (begin + self.left)
- return self.pages[begin:end]
+ def getCurrentPages( self, includeStatic = False ):
+ begin = (self.pagen - 1) * self.config.items_per_page
+ number = min( self.config.items_per_page, self.left )
+ end = begin + number
+
+ if includeStatic:
+ return self.pages[begin:end]
+ else:
+ done = 0
+ current = []
+
+ for page in self.pages[begin:]:
+ if page.static is False:
+ current.append(page)
+ done += 1
+ if done >= number:
+ break
+
+ return current
def goToNext(self):
self.left = self.max - self.current
if self.left <= 0:
return False
else:
- self.current += self.config.items_per_page if self.left > self.config.items_per_page else self.left
+ self.current += min( self.config.items_per_page, self.left )
return True
def __iter__(self):
View
73 swg/engine.py
@@ -33,12 +33,33 @@
from swg.core.diffmanager import DiffManager
class Engine:
+ __instance = None
def __init__(self):
- self.config = Config.getInstance()
- self.dbdir = os.path.join( self.config.dbpath, 'pages' )
- self.files = os.listdir( self.dbdir ) if os.path.exists( self.dbdir ) else []
- self.path = os.path.dirname( os.path.realpath( __file__ ) )
+ self.config = Config.getInstance()
+ self.dbdir = os.path.join( self.config.dbpath, 'pages' )
+ self.files = os.listdir( self.dbdir ) if os.path.exists( self.dbdir ) else []
+ self.path = os.path.dirname( os.path.realpath( __file__ ) )
+ self.pages = []
+ self.statics = None
+ self.index = None
+ self.e404 = None
+ self.sitemap = None
+ self.feed = None
+
+ def getPageByTitle( self, title, caseSensitive = True ):
+ lwr_title = title.lower() if caseSensitive is False else None
+ for page in self.pages:
+ if page.title == title or (caseSensitive is False and page.title.lower() == lwr_title):
+ return page
+
+ return None
+
+ def getStaticPages( self ):
+ if self.statics is None:
+ self.statics = filter( lambda page: page.static is True, self.pages )
+
+ return self.statics
def new( self ):
maxid = 0
@@ -108,17 +129,16 @@ class SWGServer(SocketServer.TCPServer):
def generate( self ):
parser = PageParser( )
- pages = []
-
+
print "@ Parsing pages ..."
for file in self.files:
if re.match( '^.+\.' + self.config.dbitem_ext + '$', file ):
filename = os.path.join( self.dbdir, file )
page = parser.parse( filename )
- pages.append(page)
+ self.pages.append(page)
print "@ Sorting pages by date ..."
- pages.sort( reverse=True, key=lambda p: p.datetime )
+ self.pages.sort( reverse=True, key=lambda p: p.datetime )
# delete output directory and recreate it
if os.path.exists(self.config.outputpath ):
@@ -139,33 +159,35 @@ def generate( self ):
if os.path.exists( os.path.join( self.config.tplpath, 'index.tpl' ) ):
print "@ Creating index file ..."
- index = Page( 'index', 'index.tpl' ).addObject( 'pages', pages )
- index.create()
+ self.index = Page( 'index', 'index.tpl' )
+ self.index.addObjects( { 'pages' : self.pages, 'swg' : self } )
+ self.index.create()
else:
raise Exception( "No index template found." )
if os.path.exists( os.path.join( self.config.tplpath, '404.tpl' ) ):
print "@ Creating 404 file ..."
- Page( '404', '404.tpl' ).addObject( 'pages', pages ).create()
+ self.e404 = Page( '404', '404.tpl' )
+ self.e404.addObjects( { 'pages' : self.pages, 'swg' : self } )
+ self.e404.create()
if os.path.exists( os.path.join( self.config.tplpath, 'feed.tpl' ) ):
print "@ Creating feed.xml file ..."
- feed = Page( 'feed', 'feed.tpl' )
- feed.addObject( 'pages', pages )
- feed.extension = 'xml'
- feed.create()
+ self.feed = Page( 'feed', 'feed.tpl' )
+ self.feed.addObjects( { 'pages' : self.pages, 'swg' : self } )
+ self.feed.extension = 'xml'
+ self.feed.create()
- print "@ Rendering %d pages ..." % len(pages)
- for page in pages:
- page.addObject( 'pages', pages ).create()
+ print "@ Rendering %d pages ..." % len(self.pages)
+ for page in self.pages:
+ page.addObjects( { 'pages' : self.pages, 'swg' : self } ).create()
if os.path.exists( os.path.join( self.config.tplpath, 'sitemap.tpl' ) ):
print "@ Creating sitemap.xml file ..."
- sitemap = Page( 'sitemap', 'sitemap.tpl' )
- sitemap.addObject( 'index', index )
- sitemap.addObject( 'pages', pages )
- sitemap.extension = 'xml'
- sitemap.create()
+ self.sitemap = Page( 'sitemap', 'sitemap.tpl' )
+ self.sitemap.addObjects( { 'index' : self.index, 'pages' : self.pages, 'swg' : self } )
+ self.sitemap.extension = 'xml'
+ self.sitemap.create()
if self.config.gzip is True:
htaccess = os.path.join( self.config.outputpath, '.htaccess' )
@@ -216,3 +238,8 @@ def generate( self ):
( digest, status ) = info
print "@ %-8s : '%s'" % ( status, filename.encode( "UTF-8" ) )
+ @classmethod
+ def getInstance(cls):
+ if cls.__instance is None:
+ cls.__instance = Engine()
+ return cls.__instance
View
18 swg/entities/item.py
@@ -36,8 +36,8 @@ class Item:
def __init__( self, path, title, extension ):
self.path = path.replace( '//', '/' )
- self.title = title
- self.extension = extension
+ self.title = title.strip()
+ self.extension = extension.strip()
self.name = self.__generate_name()
self.url = ("%s/%s.%s" % (self.path,self.name,self.extension)).replace( '//', '/' )
self.objects = {}
@@ -49,11 +49,11 @@ def __init__( self, path, title, extension ):
self.gzip_allow = re.compile( '^.+\.' + Config.getInstance().page_ext + '$', re.IGNORECASE )
def __generate_name( self ):
- result = []
- for word in Item.SLUGIFY_SPLIT_REGEXP.split( self.title.lower() ):
- result.extend( word.split() )
+ result = []
+ for word in Item.SLUGIFY_SPLIT_REGEXP.split( self.title.lower() ):
+ result.extend( word.split() )
- return '-'.join(result)
+ return '-'.join(result)
def __save_contents( self, filename, contents ):
if self.gzip is True and self.gzip_allow.match( filename ):
@@ -88,6 +88,12 @@ def addObject( self, name, value ):
return self
+ def addObjects( self, dictionary ):
+ for name, value in dictionary.items():
+ self.addObject( name, value )
+
+ return self
+
def create(self):
config = Config.getInstance()
path = config.outputpath + os.sep + self.path
View
1  swg/entities/page.py
@@ -33,6 +33,7 @@ def __init__( self, title, template = None ):
self.tags = []
self.abstract = ""
self.content = ""
+ self.static = False
self.template = TemplateManager.getInstance().get( 'page.tpl' if template is None else template )
def render( self ):
View
2  swg/swg
@@ -55,5 +55,7 @@ try:
else:
oparser.error( "%s invalid action!" % options.action )
+except IOError as e:
+ print "@ IO Error: %s" % e
except Exception as e:
raise
View
0  swg/importers/wordpress.py → swg/swg-wordpress 100644 → 100755
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.