aboutsummaryrefslogtreecommitdiff
path: root/src/guff/handlers/blog-handler.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/handlers/blog-handler.cr')
-rw-r--r--src/guff/handlers/blog-handler.cr172
1 files changed, 85 insertions, 87 deletions
diff --git a/src/guff/handlers/blog-handler.cr b/src/guff/handlers/blog-handler.cr
index 988eab5..c95938c 100644
--- a/src/guff/handlers/blog-handler.cr
+++ b/src/guff/handlers/blog-handler.cr
@@ -1,106 +1,104 @@
-require "./handler"
+require "../handler"
-module Guff
- class BlogHandler < Handler
- ROUTES = [{
- list: false,
- blog: true,
- re: %r{
- ^/
+class Guff::Handlers::BlogHandler < Guff::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
+ # 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{
- ^/
+ $
+ }x,
+ }, {
+ list: true,
+ blog: true,
+ re: %r{
+ ^/
- # match YYYY/MM/DD
- (?<year>\d{4})
- /
- (?<month>\d{2})
- /
- (?<day>\d{2})
- /?
+ # match YYYY/MM/DD
+ (?<year>\d{4})
+ /
+ (?<month>\d{2})
+ /
+ (?<day>\d{2})
+ /?
- $
- }x,
- }, {
- list: true,
- blog: true,
- re: %r{
- ^/
+ $
+ }x,
+ }, {
+ list: true,
+ blog: true,
+ re: %r{
+ ^/
- # match YYYY/MM
- (?<year>\d{4})
- /
- (?<month>\d{2})
- /?
+ # match YYYY/MM
+ (?<year>\d{4})
+ /
+ (?<month>\d{2})
+ /?
- $
- }x,
- }, {
- list: true,
- blog: true,
- re: %r{
- ^/
+ $
+ }x,
+ }, {
+ list: true,
+ blog: true,
+ re: %r{
+ ^/
- # match YYYY
- (?<year>\d{4})
- /?
+ # match YYYY
+ (?<year>\d{4})
+ /?
- $
- }x,
- }, {
- list: false,
- blog: false,
- re: %r{
- ^/
+ $
+ }x,
+ }, {
+ list: false,
+ blog: false,
+ re: %r{
+ ^/
- # match slug
- (?<slug>[a-z0-9._-]+)
- \.html
+ # match slug
+ (?<slug>[a-z0-9._-]+)
+ \.html
- $
- }x,
- }, {
- list: true,
- blog: true,
- re: %r{
- # match index
- ^/$
- }x,
- }]
+ $
+ }x,
+ }, {
+ list: true,
+ blog: true,
+ re: %r{
+ # match index
+ ^/$
+ }x,
+ }]
- def call(context : HTTP::Server::Context)
- path = context.request.path || ""
+ 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
+ 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
+ context.response.puts "blog: route = %s, md = %s" % [
+ route.to_s,
+ md.to_s
+ ]
end
-
- matched
end
+
+ matched
end
end
end