Link to the author's page
Right now this links to the user's medium page. It may link to an internal page in the future. Instead of the Page taking the author as a string, it now takes a PostResponse::Creator object. The Articles::ShowPage then converts the Creator (a name and user_id) to an author link. Finally, I did some refactoring of UserAnchor (which I thought I was going to use for this) to change it's userId attribute to user_id as is Crystal convention.
This commit is contained in:
parent
1c20c81d06
commit
561483cf9f
8 changed files with 47 additions and 32 deletions
|
@ -112,7 +112,7 @@ describe MarkupConverter do
|
||||||
|
|
||||||
result.should eq([
|
result.should eq([
|
||||||
Text.new("Hi "),
|
Text.new("Hi "),
|
||||||
UserAnchor.new(children: [Text.new("Dr Nick")] of Child, userId: "abc123"),
|
UserAnchor.new(children: [Text.new("Dr Nick")] of Child, user_id: "abc123"),
|
||||||
Text.new("!"),
|
Text.new("!"),
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
@ -189,7 +189,7 @@ describe MarkupConverter do
|
||||||
Strong.new([
|
Strong.new([
|
||||||
Text.new("jack"),
|
Text.new("jack"),
|
||||||
] of Child),
|
] of Child),
|
||||||
] of Child, userId: "abc123"),
|
] of Child, user_id: "abc123"),
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,8 @@ describe PageConverter do
|
||||||
|
|
||||||
page = PageConverter.new.convert(data)
|
page = PageConverter.new.convert(data)
|
||||||
|
|
||||||
page.author.should eq "Author"
|
page.author.name.should eq "Author"
|
||||||
|
page.author.id.should eq "abc123"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the publish date/time" do
|
it "sets the publish date/time" do
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -25,7 +25,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -54,7 +54,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
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"),
|
||||||
|
@ -70,7 +70,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
BlockQuote.new(children: [
|
BlockQuote.new(children: [
|
||||||
|
@ -88,7 +88,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Code.new(children: [
|
Code.new(children: [
|
||||||
|
@ -106,7 +106,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -128,7 +128,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Figure.new(children: [
|
Figure.new(children: [
|
||||||
|
@ -156,7 +156,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
GithubGist.new(href: "https://gist.github.com/user/some_id"),
|
GithubGist.new(href: "https://gist.github.com/user/some_id"),
|
||||||
|
@ -174,7 +174,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Heading2.new(children: [
|
Heading2.new(children: [
|
||||||
|
@ -192,7 +192,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Heading3.new(children: [
|
Heading3.new(children: [
|
||||||
|
@ -210,7 +210,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -232,7 +232,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
EmbeddedContent.new(
|
EmbeddedContent.new(
|
||||||
|
@ -257,7 +257,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -281,7 +281,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -310,7 +310,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
OrderedList.new(children: [
|
OrderedList.new(children: [
|
||||||
|
@ -329,7 +329,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Paragraph.new(children: [
|
Paragraph.new(children: [
|
||||||
|
@ -347,7 +347,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Preformatted.new(children: [
|
Preformatted.new(children: [
|
||||||
|
@ -365,7 +365,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
Strong.new(children: [
|
Strong.new(children: [
|
||||||
|
@ -383,7 +383,7 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
created_at: Time.local,
|
||||||
nodes: [
|
nodes: [
|
||||||
UnorderedList.new(children: [
|
UnorderedList.new(children: [
|
||||||
|
@ -402,10 +402,10 @@ describe PageContent do
|
||||||
page = Page.new(
|
page = Page.new(
|
||||||
title: "Title",
|
title: "Title",
|
||||||
subtitle: nil,
|
subtitle: nil,
|
||||||
author: "Author",
|
author: user_anchor_factory,
|
||||||
created_at: Time.local,
|
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, user_id: "abc123"),
|
||||||
] of Child
|
] of Child
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -418,3 +418,12 @@ end
|
||||||
def stripped_html(html : String)
|
def stripped_html(html : String)
|
||||||
html.gsub(/\n\s*/, "").strip
|
html.gsub(/\n\s*/, "").strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_anchor_factory(username = "someone", user_id = "abc123")
|
||||||
|
PostResponse::Creator.from_json <<-JSON
|
||||||
|
{
|
||||||
|
"id": "#{user_id}",
|
||||||
|
"name": "#{username}"
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
end
|
||||||
|
|
|
@ -54,8 +54,8 @@ class MarkupConverter
|
||||||
when PostResponse::MarkupType::A
|
when PostResponse::MarkupType::A
|
||||||
if href = markup.href
|
if href = markup.href
|
||||||
Anchor.new(href: href, children: [child] of Child)
|
Anchor.new(href: href, children: [child] of Child)
|
||||||
elsif userId = markup.userId
|
elsif user_id = markup.userId
|
||||||
UserAnchor.new(userId: userId, children: [child] of Child)
|
UserAnchor.new(user_id: user_id, children: [child] of Child)
|
||||||
else
|
else
|
||||||
Empty.new
|
Empty.new
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ end
|
||||||
class PageConverter
|
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
|
||||||
created_at = Time.unix_ms(data.post.createdAt)
|
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?
|
||||||
|
|
|
@ -193,8 +193,8 @@ module Nodes
|
||||||
|
|
||||||
getter href : String
|
getter href : String
|
||||||
|
|
||||||
def initialize(@children : Children, userId : String)
|
def initialize(@children : Children, user_id : String)
|
||||||
@href = USER_BASE_URL + userId
|
@href = USER_BASE_URL + user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other : UserAnchor)
|
def ==(other : UserAnchor)
|
||||||
|
|
|
@ -2,13 +2,13 @@ class Page
|
||||||
getter nodes : Nodes::Children
|
getter nodes : Nodes::Children
|
||||||
getter title : String
|
getter title : String
|
||||||
getter subtitle : String?
|
getter subtitle : String?
|
||||||
getter author : String
|
getter author : PostResponse::Creator
|
||||||
getter created_at : Time
|
getter created_at : Time
|
||||||
|
|
||||||
def initialize(
|
def initialize(
|
||||||
@title : String,
|
@title : String,
|
||||||
@subtitle : String?,
|
@subtitle : String?,
|
||||||
@author : String,
|
@author : PostResponse::Creator,
|
||||||
@created_at : Time,
|
@created_at : Time,
|
||||||
@nodes : Nodes::Children = [] of Nodes::Child
|
@nodes : Nodes::Children = [] of Nodes::Child
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Articles::ShowPage < MainLayout
|
||||||
para subtitle, class: "subtitle"
|
para subtitle, class: "subtitle"
|
||||||
end
|
end
|
||||||
para class: "meta" do
|
para class: "meta" do
|
||||||
text "#{page.author} on #{page.created_at.to_s("%F")}"
|
text "#{author_link(page.author)} on #{page.created_at.to_s("%F")}"
|
||||||
end
|
end
|
||||||
article do
|
article do
|
||||||
section do
|
section do
|
||||||
|
@ -19,4 +19,9 @@ class Articles::ShowPage < MainLayout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def author_link(creator : PostResponse::Creator)
|
||||||
|
href = Nodes::UserAnchor::USER_BASE_URL + creator.id
|
||||||
|
a(href: href) { text creator.name }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue