Add post creation date/time
This commit is contained in:
parent
c681d2e2ee
commit
8939772b12
7 changed files with 53 additions and 1 deletions
|
@ -80,6 +80,31 @@ describe PageConverter do
|
|||
page.author.should eq "Author"
|
||||
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
|
||||
paragraph_json = <<-JSON
|
||||
[
|
||||
|
|
|
@ -8,6 +8,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
Text.new(content: "hi"),
|
||||
|
@ -25,6 +26,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
Text.new(content: "Hello, "),
|
||||
|
@ -53,6 +55,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Anchor.new(children: [Text.new("link")] of Child, href: "https://example.com"),
|
||||
] of Child
|
||||
|
@ -68,6 +71,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
BlockQuote.new(children: [
|
||||
Text.new("Wayne Gretzky. Michael Scott."),
|
||||
|
@ -85,6 +89,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Code.new(children: [
|
||||
Text.new("foo = bar"),
|
||||
|
@ -102,6 +107,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
Text.new(content: "This is "),
|
||||
|
@ -123,6 +129,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Figure.new(children: [
|
||||
Image.new(src: "image.png", originalWidth: 100, originalHeight: 200),
|
||||
|
@ -150,6 +157,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Heading2.new(children: [
|
||||
Text.new(content: "Title!"),
|
||||
|
@ -167,6 +175,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Heading3.new(children: [
|
||||
Text.new(content: "In Conclusion..."),
|
||||
|
@ -184,6 +193,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
Image.new(src: "image.png", originalWidth: 100, originalHeight: 200),
|
||||
|
@ -205,6 +215,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
IFrame.new(href: "https://example.com"),
|
||||
|
@ -228,6 +239,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
OrderedList.new(children: [
|
||||
ListItem.new(children: [Text.new("One")] of Child),
|
||||
|
@ -246,6 +258,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Paragraph.new(children: [
|
||||
Text.new("Hello, world!"),
|
||||
|
@ -263,6 +276,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Preformatted.new(children: [
|
||||
Text.new("New\nline"),
|
||||
|
@ -280,6 +294,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
Strong.new(children: [
|
||||
Text.new("Oh yeah!"),
|
||||
|
@ -297,6 +312,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
UnorderedList.new(children: [
|
||||
ListItem.new(children: [Text.new("Apple")] of Child),
|
||||
|
@ -315,6 +331,7 @@ describe PageContent do
|
|||
title: "Title",
|
||||
subtitle: nil,
|
||||
author: "Author",
|
||||
created_at: Time.local,
|
||||
nodes: [
|
||||
UserAnchor.new(children: [Text.new("Some User")] of Child, userId: "abc123"),
|
||||
] of Child
|
||||
|
|
|
@ -20,6 +20,7 @@ class PageConverter
|
|||
def convert(data : PostResponse::Data) : Page
|
||||
paragraphs = data.post.content.bodyModel.paragraphs
|
||||
author = data.post.creator.name
|
||||
created_at = Time.unix_ms(data.post.createdAt)
|
||||
header = header_data(paragraphs)
|
||||
if header.first_content_paragraph_index.zero?
|
||||
content = [] of PostResponse::Paragraph
|
||||
|
@ -30,6 +31,7 @@ class PageConverter
|
|||
title: header.title,
|
||||
subtitle: header.subtitle,
|
||||
author: author,
|
||||
created_at: Time.unix_ms(data.post.createdAt),
|
||||
nodes: ParagraphConverter.new.convert(content)
|
||||
)
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@ class MediumClient
|
|||
query {
|
||||
post(id: "#{post_id}") {
|
||||
title
|
||||
createdAt
|
||||
creator {
|
||||
id
|
||||
name
|
||||
|
|
|
@ -3,11 +3,13 @@ class Page
|
|||
getter title : String
|
||||
getter subtitle : String?
|
||||
getter author : String
|
||||
getter created_at : Time
|
||||
|
||||
def initialize(
|
||||
@title : String,
|
||||
@subtitle : String?,
|
||||
@author : String,
|
||||
@created_at : Time,
|
||||
@nodes : Nodes::Children = [] of Nodes::Child
|
||||
)
|
||||
end
|
||||
|
|
|
@ -13,6 +13,7 @@ class PostResponse
|
|||
|
||||
class Post < Base
|
||||
property title : String
|
||||
property createdAt : Int64
|
||||
property creator : Creator
|
||||
property content : Content
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Articles::ShowPage < MainLayout
|
|||
para subtitle, class: "subtitle"
|
||||
end
|
||||
para do
|
||||
text "#{page.author}"
|
||||
text "#{page.author} #{created_at(page.created_at)}"
|
||||
end
|
||||
article do
|
||||
section do
|
||||
|
@ -19,4 +19,8 @@ class Articles::ShowPage < MainLayout
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def created_at(time : Time) : String
|
||||
"at #{time.to_s("%I:%M%p")} on #{time.to_s("%F")}"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue