Browse Source

Merge pull request #50 from stiell/hyde

---

These commits add better support for generating and serving files with custom or no filename extensions.

The tagger plugin can now generate archives without any filename extension if it is set to `null` in `site.yaml`:

    tagger:
        archives:
            all:
                extension:
                target: t
                …

The `hyde serve` command has a new argument to modify the MIME type extensions map. Example:

    hyde serve -t text/html -t text/plain .srt .asc -t application/x-xz .xz

This sets the default MIME type to `text/html` (rather than `application/octet-stream`) and maps `.srt` and `.asc` to `text/plain` and `.xz` to `application/x-xz`.
main
Lakshmi Vyasarajan 13 years ago
parent
commit
117100faa2
2 changed files with 9 additions and 2 deletions
  1. +7
    -1
      hyde/engine.py
  2. +2
    -1
      hyde/ext/plugins/tagger.py

+ 7
- 1
hyde/engine.py View File

@@ -99,6 +99,9 @@ class Engine(Application):
help='The configuration used to generate the site') help='The configuration used to generate the site')
@store('-d', '--deploy-path', dest='deploy', default=None, @store('-d', '--deploy-path', dest='deploy', default=None,
help='Where should the site be generated?') help='Where should the site be generated?')
@append('-t', '--type', dest='types', default=[], nargs='+',
metavar=('TYPE', 'EXT'), help='Add a MIME type mapping for'
' one or more extensions, or set the default MIME type.')
def serve(self, args): def serve(self, args):
""" """
The serve command. Serves the site at the given The serve command. Serves the site at the given
@@ -109,7 +112,10 @@ class Engine(Application):
sitepath = Folder(Folder(args.sitepath).fully_expanded_path) sitepath = Folder(Folder(args.sitepath).fully_expanded_path)
config_file = sitepath.child(args.config) config_file = sitepath.child(args.config)
site = self.make_site(args.sitepath, args.config, args.deploy) site = self.make_site(args.sitepath, args.config, args.deploy)
from hyde.server import HydeWebServer
from hyde.server import HydeWebServer, HydeRequestHandler
for t in args.types:
for e in t[1:] or ['']:
HydeRequestHandler.extensions_map[e] = t[0]
server = HydeWebServer(site, args.address, args.port) server = HydeWebServer(site, args.address, args.port)
logger.info("Starting webserver at [%s]:[%d]", args.address, args.port) logger.info("Starting webserver at [%s]:[%d]", args.address, args.port)
try: try:


+ 2
- 1
hyde/ext/plugins/tagger.py View File

@@ -142,5 +142,6 @@ class TaggerPlugin(Plugin):
"walk_resources_tagged_with_%s" % tag) "walk_resources_tagged_with_%s" % tag)
)) ))
archive_text = self.template.render(text, context) archive_text = self.template.render(text, context)
archive_file = File(target.child("%s.%s" % (tag, extension)))
archive_file = File(target.child("%s.%s" % (tag, extension)
if extension is not None else tag))
archive_file.write(archive_text) archive_file.write(archive_text)

Loading…
Cancel
Save