diff options
author | Indrajith K L | 2024-06-22 03:40:56 +0530 |
---|---|---|
committer | Indrajith K L | 2024-06-22 03:40:56 +0530 |
commit | 646fdccac5f0ec506b80ed532baa4012965b682e (patch) | |
tree | ced54009d8d5f20b61d7a873a6bb54907e8b7e5d /src/indrajith-dev-crystal.cr | |
parent | a5b35ffb182e4b2aa250059b0e44c13373999d76 (diff) | |
download | indrajith-dev-crystal-646fdccac5f0ec506b80ed532baa4012965b682e.tar.gz indrajith-dev-crystal-646fdccac5f0ec506b80ed532baa4012965b682e.tar.bz2 indrajith-dev-crystal-646fdccac5f0ec506b80ed532baa4012965b682e.zip |
Date Utils, Cosmetic and Implementation Changes
* Adds Utils method for formatting date
* Adds Published at to the posts page
* Adds new logo, removes font dependency
* Renames Posts link to Blog
Diffstat (limited to 'src/indrajith-dev-crystal.cr')
-rw-r--r-- | src/indrajith-dev-crystal.cr | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/indrajith-dev-crystal.cr b/src/indrajith-dev-crystal.cr index f5ddabd..f49f134 100644 --- a/src/indrajith-dev-crystal.cr +++ b/src/indrajith-dev-crystal.cr @@ -2,6 +2,8 @@ require "kemal" require "crest" require "json" require "dotenv" +require "./utils/utils" +require "time" Dotenv.load @@ -13,6 +15,7 @@ module Indrajith::Dev::Crystal macro page_renderer(filename, title) page_title = {{title}} + published_at="" render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr" end @@ -41,6 +44,11 @@ module Indrajith::Dev::Crystal page_renderer "contact", "Contact" end + get "/blog" do |context| + context.response.content_type = "text/html" + page_renderer "blog", "Blog" + end + get "/posts" do |context| begin site = Crest::Resource.new("#{STRAPI_URL}") @@ -80,7 +88,7 @@ module Indrajith::Dev::Crystal get "/post/:slug" do |context| begin slug = context.params.url["slug"] - site = Crest::Resource.new("http://localhost:1337") + site = Crest::Resource.new("#{STRAPI_URL}") response = site.get("/api/posts", params: { @@ -94,6 +102,9 @@ module Indrajith::Dev::Crystal post_item = data[0] post_attribute = post_item["attributes"] content = post_attribute["post_content"] + published_raw_time = post_attribute["publishedAt"].as_s + published_time = Time.parse(published_raw_time, "%Y-%m-%dT%H:%M:%S.%3NZ", Time::Location.local) + published_at = format_date(published_time) page_title = post_attribute["post_title"] render "src/views/layout.ecr" rescue ex |