aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/guff.cr60
-rw-r--r--src/guff/blog-handler.cr63
2 files changed, 63 insertions, 60 deletions
diff --git a/src/guff.cr b/src/guff.cr
index e62ff1f..2bec70d 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -2,66 +2,6 @@ require "http/server"
require "./guff/*"
module Guff
- class BlogHandler < Handler
- MATCHES = [%r{
- ^/
-
- # match YYYY/MM/DD/SLUG.html
- (?<year>\d{4})
- /
- (?<month>\d{2})
- /
- (?<day>\d{2})
- /
- (?<slug>[a-z0-9._-]+)
- \.html
-
- $
- }x, %r{
- ^/
-
- # match YYYY/MM/DD
- (?<year>\d{4})
- /
- (?<month>\d{2})
- /
- (?<day>\d{2})
- /?
-
- $
- }x, %r{
- ^/
-
- # match YYYY/MM
- (?<year>\d{4})
- /
- (?<month>\d{2})
- /?
-
- $
- }x, %r{
- ^/
-
- # match YYYY
- (?<year>\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
-
class SlugHandler < Handler
MOCK_SLUGS = {
"foo": "test slug foo",
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
+ (?<year>\d{4})
+ /
+ (?<month>\d{2})
+ /
+ (?<day>\d{2})
+ /
+ (?<slug>[a-z0-9._-]+)
+ \.html
+
+ $
+ }x, %r{
+ ^/
+
+ # match YYYY/MM/DD
+ (?<year>\d{4})
+ /
+ (?<month>\d{2})
+ /
+ (?<day>\d{2})
+ /?
+
+ $
+ }x, %r{
+ ^/
+
+ # match YYYY/MM
+ (?<year>\d{4})
+ /
+ (?<month>\d{2})
+ /?
+
+ $
+ }x, %r{
+ ^/
+
+ # match YYYY
+ (?<year>\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