Skip to content

Instantly share code, notes, and snippets.

@vonglasow
Created June 22, 2014 15:01
Show Gist options
  • Save vonglasow/08e3ae813e00313c383e to your computer and use it in GitHub Desktop.
Save vonglasow/08e3ae813e00313c383e to your computer and use it in GitHub Desktop.
suffix.py
# -*- coding: utf-8 -*-
from hyde.plugin import CLTransformer
from hyde.fs import File
from operator import attrgetter
#Fork of lepture/suffix.py
class SuffixPlugin(CLTransformer):
"""
The plugin class for suffix modified
"""
def __init__(self, site):
super(SuffixPlugin, self).__init__(site)
def begin_site(self):
"""
Configuration example
---------------------
#yaml
suffix:
-
target_extension:
- markdown
- md
output_extension: html
-
target_extension:
- rst
- md
output_extension: html
"""
config = self.site.config
if not hasattr(config, 'suffix'):
return
suffix_config = attrgetter('suffix')(config)
for resource in self.site.content.walk_resources():
for conf in suffix_config:
conf = conf.to_dict()
target = conf.get('target_extension', [])
output = conf.get('output_extension', 'html')
if resource.source_file.kind in target:
new_name = resource.source_file.name_without_extension + "." + output
target_folder = File(resource.relative_deploy_path).parent
resource.relative_deploy_path = target_folder.child(new_name)
@property
def plugin_name(self):
"""
The name of the plugin.
"""
return "suffix"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment