From 2d149be50f74973965abec8c826fe5576a4f2440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstro=CC=88m?= Date: Wed, 3 Mar 2021 14:36:42 +0100 Subject: web: Ensure date is right in post URL --- interfaces/http/web/web.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'interfaces') diff --git a/interfaces/http/web/web.rb b/interfaces/http/web/web.rb index 16492c2..0903bb4 100644 --- a/interfaces/http/web/web.rb +++ b/interfaces/http/web/web.rb @@ -5,10 +5,11 @@ class WebInterface < Sinatra::Base erb :index end - get '/:year/:month/:day/:slug' do - @posts = Post.where(slug: params['slug']) + get '/:year/:month/:day/:slug' do |y, m, d, slug| + @posts = Post.where(slug: slug) - if @posts.empty? then + date = DateTime.strptime("#{y}-#{m}-#{d}", "%Y-%m-%d") + if @posts.empty? or @posts[0].created_at.to_date != date.to_date then status 404 @title = '404 Not Found' erb :not_found -- cgit v1.2.3