require "kemal" require "crest" require "json" require "dotenv" Dotenv.load TOKEN = ENV["TOKEN"] module Indrajith::Dev::Crystal VERSION = "0.1.0" macro page_renderer(filename, title) page_title = {{title}} render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr" end macro render_404() page_renderer "404", "The VOID" end get "/" do |context| context.response.content_type = "text/html" page_renderer "home", "Home" end get "/about" do |context| context.response.content_type = "text/html" page_renderer "about", "About " end get "/timeline" do |context| context.response.content_type = "text/html" page_renderer "timeline", "Timeline" end get "/contact" do |context| context.response.content_type = "text/html" page_renderer "contact", "Contact" end get "/posts" do |context| begin site = Crest::Resource.new("http://localhost:1337") response = site.get("/api/posts", params: { "fields[0]" => "post_title", "fields[1]" => "slug", "pagination[pageSize]" => 3, }, headers: {"Authorization" => "Bearer #{TOKEN}"} ) json_data = JSON.parse(response.body) data = json_data["data"].as_a html_string = "" data.each do |item| attributes = item["attributes"] # puts attributes["post_title"] html_string += "