Add post creation date/time

This commit is contained in:
Edward Loveall 2021-09-04 17:32:27 -04:00
parent c681d2e2ee
commit 8939772b12
No known key found for this signature in database
GPG key ID: 789A4AE983AC8901
7 changed files with 53 additions and 1 deletions

View file

@ -80,6 +80,31 @@ describe PageConverter do
page.author.should eq "Author" page.author.should eq "Author"
end end
it "sets the publish date/time" do
data_json = <<-JSON
{
"post": {
"title": "This is a story",
"createdAt": 1000,
"creator": {
"id": "abc123",
"name": "Author"
},
"content": {
"bodyModel": {
"paragraphs": []
}
}
}
}
JSON
data = PostResponse::Data.from_json(data_json)
page = PageConverter.new.convert(data)
page.created_at.should eq Time.utc(1970, 1, 1, 0, 0, 1)
end
it "calls ParagraphConverter to convert the remaining paragraph content" do it "calls ParagraphConverter to convert the remaining paragraph content" do
paragraph_json = <<-JSON paragraph_json = <<-JSON
[ [

View file

@ -8,6 +8,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
Text.new(content: "hi"), Text.new(content: "hi"),
@ -25,6 +26,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
Text.new(content: "Hello, "), Text.new(content: "Hello, "),
@ -53,6 +55,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Anchor.new(children: [Text.new("link")] of Child, href: "https://example.com"), Anchor.new(children: [Text.new("link")] of Child, href: "https://example.com"),
] of Child ] of Child
@ -68,6 +71,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
BlockQuote.new(children: [ BlockQuote.new(children: [
Text.new("Wayne Gretzky. Michael Scott."), Text.new("Wayne Gretzky. Michael Scott."),
@ -85,6 +89,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Code.new(children: [ Code.new(children: [
Text.new("foo = bar"), Text.new("foo = bar"),
@ -102,6 +107,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
Text.new(content: "This is "), Text.new(content: "This is "),
@ -123,6 +129,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Figure.new(children: [ Figure.new(children: [
Image.new(src: "image.png", originalWidth: 100, originalHeight: 200), Image.new(src: "image.png", originalWidth: 100, originalHeight: 200),
@ -150,6 +157,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Heading2.new(children: [ Heading2.new(children: [
Text.new(content: "Title!"), Text.new(content: "Title!"),
@ -167,6 +175,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Heading3.new(children: [ Heading3.new(children: [
Text.new(content: "In Conclusion..."), Text.new(content: "In Conclusion..."),
@ -184,6 +193,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
Image.new(src: "image.png", originalWidth: 100, originalHeight: 200), Image.new(src: "image.png", originalWidth: 100, originalHeight: 200),
@ -205,6 +215,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
IFrame.new(href: "https://example.com"), IFrame.new(href: "https://example.com"),
@ -228,6 +239,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
OrderedList.new(children: [ OrderedList.new(children: [
ListItem.new(children: [Text.new("One")] of Child), ListItem.new(children: [Text.new("One")] of Child),
@ -246,6 +258,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Paragraph.new(children: [ Paragraph.new(children: [
Text.new("Hello, world!"), Text.new("Hello, world!"),
@ -263,6 +276,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Preformatted.new(children: [ Preformatted.new(children: [
Text.new("New\nline"), Text.new("New\nline"),
@ -280,6 +294,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
Strong.new(children: [ Strong.new(children: [
Text.new("Oh yeah!"), Text.new("Oh yeah!"),
@ -297,6 +312,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
UnorderedList.new(children: [ UnorderedList.new(children: [
ListItem.new(children: [Text.new("Apple")] of Child), ListItem.new(children: [Text.new("Apple")] of Child),
@ -315,6 +331,7 @@ describe PageContent do
title: "Title", title: "Title",
subtitle: nil, subtitle: nil,
author: "Author", author: "Author",
created_at: Time.local,
nodes: [ nodes: [
UserAnchor.new(children: [Text.new("Some User")] of Child, userId: "abc123"), UserAnchor.new(children: [Text.new("Some User")] of Child, userId: "abc123"),
] of Child ] of Child

View file

@ -20,6 +20,7 @@ class PageConverter
def convert(data : PostResponse::Data) : Page def convert(data : PostResponse::Data) : Page
paragraphs = data.post.content.bodyModel.paragraphs paragraphs = data.post.content.bodyModel.paragraphs
author = data.post.creator.name author = data.post.creator.name
created_at = Time.unix_ms(data.post.createdAt)
header = header_data(paragraphs) header = header_data(paragraphs)
if header.first_content_paragraph_index.zero? if header.first_content_paragraph_index.zero?
content = [] of PostResponse::Paragraph content = [] of PostResponse::Paragraph
@ -30,6 +31,7 @@ class PageConverter
title: header.title, title: header.title,
subtitle: header.subtitle, subtitle: header.subtitle,
author: author, author: author,
created_at: Time.unix_ms(data.post.createdAt),
nodes: ParagraphConverter.new.convert(content) nodes: ParagraphConverter.new.convert(content)
) )
end end

View file

@ -19,6 +19,7 @@ class MediumClient
query { query {
post(id: "#{post_id}") { post(id: "#{post_id}") {
title title
createdAt
creator { creator {
id id
name name

View file

@ -3,11 +3,13 @@ class Page
getter title : String getter title : String
getter subtitle : String? getter subtitle : String?
getter author : String getter author : String
getter created_at : Time
def initialize( def initialize(
@title : String, @title : String,
@subtitle : String?, @subtitle : String?,
@author : String, @author : String,
@created_at : Time,
@nodes : Nodes::Children = [] of Nodes::Child @nodes : Nodes::Children = [] of Nodes::Child
) )
end end

View file

@ -13,6 +13,7 @@ class PostResponse
class Post < Base class Post < Base
property title : String property title : String
property createdAt : Int64
property creator : Creator property creator : Creator
property content : Content property content : Content
end end

View file

@ -11,7 +11,7 @@ class Articles::ShowPage < MainLayout
para subtitle, class: "subtitle" para subtitle, class: "subtitle"
end end
para do para do
text "#{page.author}" text "#{page.author} #{created_at(page.created_at)}"
end end
article do article do
section do section do
@ -19,4 +19,8 @@ class Articles::ShowPage < MainLayout
end end
end end
end end
def created_at(time : Time) : String
"at #{time.to_s("%I:%M%p")} on #{time.to_s("%F")}"
end
end end