A fork of hyde, the static site generation. Some patches will be pushed upstream.
 
 
 

45 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Plugins related to folders and paths
  4. """
  5. from hyde.plugin import Plugin
  6. from hyde.fs import Folder
  7. class FlattenerPlugin(Plugin):
  8. """
  9. The plugin class for flattening nested folders.
  10. """
  11. def __init__(self, site):
  12. super(FlattenerPlugin, self).__init__(site)
  13. def begin_site(self):
  14. """
  15. Finds all the folders that need flattening and changes the
  16. relative deploy path of all resources in those folders.
  17. """
  18. items = []
  19. try:
  20. items = self.site.config.flattener.items
  21. except AttributeError:
  22. pass
  23. for item in items:
  24. node = None
  25. target = ''
  26. try:
  27. node = self.site.content.node_from_relative_path(item.source)
  28. target = Folder(item.target)
  29. except AttributeError:
  30. continue
  31. if node:
  32. for resource in node.walk_resources():
  33. target_path = target.child(resource.name)
  34. self.logger.debug(
  35. 'Flattening resource path [%s] to [%s]' %
  36. (resource, target_path))
  37. resource.relative_deploy_path = target_path
  38. for child in node.walk():
  39. child.relative_deploy_path = target.path