diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-08 16:59:30 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-08 16:59:30 -0500 |
commit | b5d66c8d5ce941a6ee290128807f1f9e50aee4e9 (patch) | |
tree | 8e65a5f082f41f66a9b2b7f7821a884a6a9cdc6a /src/guff/handlers/blog-handler.cr | |
parent | 575e4c49131e7699fc23fca78ec14b400680839a (diff) | |
download | old-guff-b5d66c8d5ce941a6ee290128807f1f9e50aee4e9.tar.bz2 old-guff-b5d66c8d5ce941a6ee290128807f1f9e50aee4e9.zip |
mv src/guff/*-handler.cr src/guff/handler/
Diffstat (limited to 'src/guff/handlers/blog-handler.cr')
-rw-r--r-- | src/guff/handlers/blog-handler.cr | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/guff/handlers/blog-handler.cr b/src/guff/handlers/blog-handler.cr new file mode 100644 index 0000000..988eab5 --- /dev/null +++ b/src/guff/handlers/blog-handler.cr @@ -0,0 +1,106 @@ +require "./handler" + +module Guff + class BlogHandler < Handler + ROUTES = [{ + list: false, + blog: true, + re: %r{ + ^/ + + # match YYYY/MM/DD/SLUG.html + (?<year>\d{4}) + / + (?<month>\d{2}) + / + (?<day>\d{2}) + / + (?<slug>[a-z0-9._-]+) + \.html + + $ + }x, + }, { + list: true, + blog: true, + re: %r{ + ^/ + + # match YYYY/MM/DD + (?<year>\d{4}) + / + (?<month>\d{2}) + / + (?<day>\d{2}) + /? + + $ + }x, + }, { + list: true, + blog: true, + re: %r{ + ^/ + + # match YYYY/MM + (?<year>\d{4}) + / + (?<month>\d{2}) + /? + + $ + }x, + }, { + list: true, + blog: true, + re: %r{ + ^/ + + # match YYYY + (?<year>\d{4}) + /? + + $ + }x, + }, { + list: false, + blog: false, + re: %r{ + ^/ + + # match slug + (?<slug>[a-z0-9._-]+) + \.html + + $ + }x, + }, { + list: true, + blog: true, + re: %r{ + # match index + ^/$ + }x, + }] + + def call(context : HTTP::Server::Context) + path = context.request.path || "" + + call_next(context) unless ROUTES.reduce(false) do |matched, route| + unless matched + if md = (route[:re] as Regex).match(path) + # matched route + matched = true + + context.response.puts "blog: route = %s, md = %s" % [ + route.to_s, + md.to_s + ] + end + end + + matched + end + end + end +end |