From efe09d414a7a8e71974dde57833ebbe97e997146 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 5 Mar 2016 19:03:32 -0500 Subject: refactor blog-handler --- src/guff/blog-handler.cr | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/guff/blog-handler.cr (limited to 'src/guff') diff --git a/src/guff/blog-handler.cr b/src/guff/blog-handler.cr new file mode 100644 index 0000000..577ce70 --- /dev/null +++ b/src/guff/blog-handler.cr @@ -0,0 +1,63 @@ +require "./handler" + +module Guff + class BlogHandler < Handler + MATCHES = [%r{ + ^/ + + # match YYYY/MM/DD/SLUG.html + (?\d{4}) + / + (?\d{2}) + / + (?\d{2}) + / + (?[a-z0-9._-]+) + \.html + + $ + }x, %r{ + ^/ + + # match YYYY/MM/DD + (?\d{4}) + / + (?\d{2}) + / + (?\d{2}) + /? + + $ + }x, %r{ + ^/ + + # match YYYY/MM + (?\d{4}) + / + (?\d{2}) + /? + + $ + }x, %r{ + ^/ + + # match YYYY + (?\d{4}) + /? + + $ + }x, %r{ + # match index + ^/$ + }x] + + def call(context : HTTP::Server::Context) + path = context.request.path || "" + if md = MATCHES.reduce(nil) { |r, m| r || m.match(path) } + context.response.puts "blog match: %s" % [md.to_s] + else + call_next(context) + end + end + end +end -- cgit v1.2.3