diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-07-15 18:48:01 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-07-15 18:48:01 -0400 |
commit | 7f1e563feb8efd97a54d943cb4ec4d58a454d7e8 (patch) | |
tree | 507fe0e361b093f286a1d78d256a90f4d354cf48 /src/guff.cr | |
parent | 63bc54d966831929eb66da8e06291fd924fb4aef (diff) | |
download | guff-7f1e563feb8efd97a54d943cb4ec4d58a454d7e8.tar.bz2 guff-7f1e563feb8efd97a54d943cb4ec4d58a454d7e8.zip |
add blog id paging and point index at blog
Diffstat (limited to 'src/guff.cr')
-rw-r--r-- | src/guff.cr | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/guff.cr b/src/guff.cr index 8ea29fa..87e58ad 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -858,6 +858,8 @@ module Guff -- TODO: handle posted_at and expired_at ORDER BY COALESCE(b.posted_at, b.created_at) DESC + + LIMIT ? OFFSET ? ", add: " @@ -896,14 +898,18 @@ module Guff (ids.size > 0) ? ids.first : nil end + # TODO: make this configurable + LIMIT = 50 + def get_ids( site_id : Int64, year : Int32? = nil, month : Int32? = nil, day : Int32? = nil, - slug : String? = nil + slug : String? = nil, + page : Int32? = nil ) : Array(Int64) - sql = [] of String + sql = ["1"] args = [site_id.to_s] # STDERR.puts "DEBUG: site_id = #{site_id}, year = #{year}, month = #{month}, day = #{day}, slug = \"#{slug}\"" @@ -932,6 +938,12 @@ module Guff args << slug end + page ||= 1 + raise "invalid page: #{page}" if page < 1 + + args << LIMIT.to_s + args << ((page - 1) * LIMIT).to_s + # STDERR.puts "DEBUG: args = #{args.to_json}" # exec query, build result @@ -2109,6 +2121,10 @@ module Guff class LogoutPageView < HTMLView ECR.def_to_s("src/views/logout-page.ecr") end + + class BlogListView < HTMLView + ECR.def_to_s("src/views/blog-list.ecr") + end end module Handlers @@ -2522,6 +2538,7 @@ module Guff class BlogPostHandler < Handler PATH_RE = %r{^ + (/blog)? /(?<year>\d{4}) /(?<month>\d{2}) /(?<day>\d{2}) @@ -2564,11 +2581,15 @@ module Guff end class BlogListHandler < Handler - PATH_RE = %r{^ - /(?<year>\d{4})/ + # TODO: make index page configurable + PATH_RE = %r{^/ + (blog/?)? ( - (?<month>\d{2})/ - ((?<day>\d{2})/)? + (?<year>\d{4})/ + ( + (?<month>\d{2})/ + ((?<day>\d{2})/)? + )? )? $}x @@ -2593,9 +2614,10 @@ module Guff if site_id = get_site_id(request.headers["host"]?) r = @context.models.blog.get_ids( site_id: site_id, - year: md["year"].to_i, + year: md["year"]? ? md["year"].to_i : nil, month: md["month"]? ? md["month"].to_i : nil, day: md["day"]? ? md["day"].to_i : nil, + page: md["page"]? ? md["page"].to_i : nil, ) end end @@ -2685,12 +2707,12 @@ module Guff LogoutPageHandler.new(context) when :page PageHandler.new(context) - when :project - ProjectHandler.new(context) when :blog_post BlogPostHandler.new(context) when :blog_list BlogListHandler.new(context) + when :project + ProjectHandler.new(context) else raise "unknown handler id: #{handler_id}" end |