from events import add_filter def process(page): """ Look for the 'shadow' header. If found, split the CSV and then append a style block for each value. """ if "shadow" in page.headers: for alt in page.headers["shadow"].split(","): page.template.append( "head", """ <style type="text/css"> [alt="%s"] { -moz-box-shadow: 4px 4px 5px #aaaaaa; -webkit-box-shadow: 4px 4px 5px #aaaaaa; box-shadow: 4px 4px 5px #aaaaaa; /* For IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#aaaaaa')"; /* For IE 5.5 - 7 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#aaaaaa'); } </style> """ % alt, ) add_filter("pre-markdown", process)
from events import add_filter from proton import template def process(page): # include the head if 'head' in page.headers: tmp = template.get_template(page.headers['head']) page.template.replace('head', tmp) elif page.config.has_option('templates', 'head'): tmp = template.get_template(page.config.get('templates', 'head')) page.template.replace('head', tmp) if page.config.has_option('templates', 'header'): tmp = template.get_template(page.config.get('templates', 'header')) page.template.replace('header', tmp) return page add_filter('page-head', process)
from events import add_filter from proton import template def process(page): # include the head if 'foot' in page.headers: tmp = template.get_template(page.headers['foot']) page.template.replace('foot', tmp) elif page.config.has_option('templates', 'foot'): tmp = template.get_template(page.config.get('templates', 'foot')) page.template.replace('foot', tmp) return page add_filter('page-foot', process)
if path.startswith('/'): path = path[1:] feed_file = os.path.join(output_path, path, 'feed.xml') if os.path.exists(feed_file): statbuf = os.stat(feed_file) last_modified = datetime.datetime.fromtimestamp(statbuf.st_mtime) else: last_modified = None if not last_modified or max_modified >= last_modified: out = str(tmp) f = open(feed_file, 'w+') f.write(out) f.close() def process(pages, output_path): root_page = get_root_page(pages, 'blog') if not root_page: return pages paths = root_page.config.get('blog', 'paths') if paths: for path in paths.split(','): process_path(path, output_path, pages) return pages add_filter('pages', process)
write_file(os.path.join(path, 'theme', 'rss.xml'), default_rss) write_file(os.path.join(path, 'index.text'), default_text) write_file(os.path.join(path, '.htaccess'), default_htaccess) def createsite(kernel, *args): """ Create the skeleton of a SiteBaker website. """ if len(args) <= 0 or len(args[0]) <= 0: print('A path to generate the new site is required') sys.exit(1) elif os.path.exists(args[0][0]): print('Path "%s" already exists' % args[0][0]) sys.exit(1) path = args[0][0] print('Creating new site at %s' % path) os.makedirs(path) os.makedirs(os.path.join(path, 'theme')) os.makedirs(os.path.join(path, 'tags')) os.makedirs(os.path.join(path, 'resources')) generate_files(path) def process_commands(commands): commands['create'] = createsite return commands add_filter('commands', process_commands)
for key in sorted(tag_classes, reverse=True): if count >= int(key): tmp.set_attribute('tag', 'class', tag_classes[key], x) x += 1 cpage = Page() cpage.copy(page) cpage.template = tmp apply_filter('page-head', cpage) apply_filter('page-meta', cpage) apply_filter('page-menu', cpage) apply_filter('page-foot', cpage) tmp.set_value('page-title', index_title) apply_filter('tags-index-page', cpage) output_name = os.path.join(tag_dir, 'index.html') f = open(output_name, 'w+') f.write(str(tmp)) f.close() print(' - complete') return pages add_filter('pages', process_pages) add_filter('post-meta', process_postmeta) add_action('post-meta-reset', reset)
from events import add_filter def process(page): """ TBD """ for header in page.headers: if header.startswith('meta-'): metatag = '<meta name="%s" content="%s" />' % (header[5:], page.headers[header]) page.template.append('head', metatag) if 'title' in page.headers: page.template.set_value('page-title', page.headers['title']) return page add_filter('page-meta', process)
from events import add_filter def process(page, index=0): global tag_repeat_count if 'posted-on' in page.headers: page.template.set_value('posted-on', 'Posted on %s' % page.get_posted_date(), index) page.template.set_value('post-date', page.get_posted_date(), index) if 'title' in page.headers: page.template.set_value('title', page.headers['title'], index) if 'sub-title' in page.headers: page.template.set_value('sub-title', page.headers['sub-title'], index) page.template.set_value('permalink', 'Permalink', index) page.template.set_attribute('permalink', 'href', page.url + '.html', index) page.template.set_value('permalink-url', page.url, index) page.template.set_attribute('permalink-url', 'href', page.url + '.html', index) return page add_filter('post-meta', process)
''' % { 'title': title, 'posted-on': posted_on, 'dashes': ('-' * len(title)) } with open(filename, 'w') as blog_file: blog_file.write(content) def process_pages(pages, output_path): root_page = get_root_page(pages, 'blog') if not root_page: return pages paths = root_page.config.get('blog', 'paths') print('Generating blog index pages') if paths: for path in paths.split(','): process_path(path, output_path, pages) print(' - complete') return pages def process_commands(commands): commands['blog'] = blog_command return commands add_filter('pages', process_pages) add_filter('commands', process_commands)
def markdown(content): content = content.replace('[break]', '<br class="clear" />') rtn = markdown2.markdown(content, extras=['fenced-code-blocks', 'wiki-tables']) while strong_re.search(rtn): rtn = strong_re.sub(r'<span class="lolite">', rtn, 1) rtn = strong_off_re.sub('</span>', rtn, 1) return rtn def add_anchors(content): for mat in heading_re.finditer(content): heading = mat.group(1) heading_anchor = heading.replace(' ', '-').replace('"', '') content = content.replace('<h2>%s</h2>' % heading, '<h2 id="%s">%s</h2>' % (heading_anchor, heading)) return content def process(page, index=0): apply_filter('pre-markdown', page) content = apply_filter('markdown', page.content) content = add_anchors(content) page.template.set_value('content', content, index) return page add_filter('page-markdown', process) add_filter('markdown', markdown)