Skip to content

Instantly share code, notes, and snippets.

@navilan
Last active December 10, 2015 02:58
Show Gist options
  • Save navilan/4371257 to your computer and use it in GitHub Desktop.
Save navilan/4371257 to your computer and use it in GitHub Desktop.
A simple plugin to rename file extensions. See: https://groups.google.com/forum/#!topic/hyde-dev/EtJ7bRUQEBA.

How to test:

  1. Create a new hyde site hyde -s test create
  2. Overwrite the generated site.yaml with the one in the gist
  3. Add site_plugins.py to the root folder
  4. Rename *.html under content to *.md
  5. Run hyde hyde gen -r
mode: development
media_root: media # Relative path from content folder.
media_url: /media # URL where the media files are served from.
base_url: / # The base url for autogenerated links.
plugins:
- hyde.ext.plugins.meta.MetaPlugin
- hyde.ext.plugins.auto_extend.AutoExtendPlugin
- hyde.ext.plugins.sorter.SorterPlugin
- hyde.ext.plugins.tagger.TaggerPlugin
- hyde.ext.plugins.syntext.SyntextPlugin
- hyde.ext.plugins.textlinks.TextlinksPlugin
- site_plugins.RenamerPlugin
context:
data:
tweet_via: ringce
menu:
-
name: Home
description: Home Page
css_class: home
type: page
url: index.html
-
name: Portfolio
description: Portfolio
css_class: portfolio
type: node
url: portfolio
-
name: Blog
description: Blog
css_class: blog
type: node
url: blog
-
name: About
description: About
css_class: about
type: page
url: about.html
meta:
nodemeta: meta.yaml
created: !!timestamp 2010-01-01 00:00:00
author: Lakshmi Vyasarajan
sorter:
time:
attr:
- meta.created
reverse: true
filters:
source.kind: html
meta.listable: true
renamer:
include_file_patterns:
- '*.md'
- '*.markdown'
config:
html:
- '*.md'
- '*.markdown'
tagger:
sorter: time
archives:
blog:
source: blog
target: blog/tags
template: tagged_posts.j2
archive_extension: html
meta:
listable: false
from fnmatch import fnmatch
import os
from hyde.plugin import Plugin
class RenamerPlugin(Plugin):
'''
Sample config:
# site.yaml
#...
renamer:
config:
html:
- '*.md'
- '*.markdown'
'''
def begin_site(self):
try:
config = self.settings.config
except AttributeError:
return
for resource in self.site.content.walk_resources():
for new_ext, source_patterns in config.to_dict().iteritems():
matched = any(fnmatch(resource.source.path, p)
for p in source_patterns)
if matched:
orig = os.path.splitext(resource.relative_deploy_path)[0]
resource.relative_deploy_path = orig + '.' + new_ext
print resource.relative_deploy_path
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment