From b3166102c714bf96fa2b77f319f912fecdb87bf3 Mon Sep 17 00:00:00 2001 From: Edward Loveall Date: Sat, 4 Sep 2021 21:31:48 -0400 Subject: [PATCH] Parse medium URLs As far as I can tell, the post id for all medium posts is always 12 hex characters. We'll find out if that's true. --- src/actions/articles/show.cr | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/actions/articles/show.cr b/src/actions/articles/show.cr index 867a84a..35a66f7 100644 --- a/src/actions/articles/show.cr +++ b/src/actions/articles/show.cr @@ -1,7 +1,17 @@ require "json" class Articles::Show < BrowserAction - get "/posts/:post_id" do + get "/posts/:post_slug" do + id_match = post_slug.match(/([0-9a-f]{12})$/i) + if id_match + post_id = id_match[1] + else + return html( + Errors::ShowPage, + message: "Error parsing the URL", + status: 500, + ) + end if Lucky::Env.use_local? response = LocalClient.post_data(post_id) else