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.
main
Edward Loveall 2021-09-15 15:44:28 -04:00
rodzic 1c20c81d06
commit 561483cf9f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 789A4AE983AC8901
8 zmienionych plików z 47 dodań i 32 usunięć

Wyświetl plik

@ -112,7 +112,7 @@ describe MarkupConverter do
result.should eq([
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("!"),
])
end
@ -189,7 +189,7 @@ describe MarkupConverter do
Strong.new([
Text.new("jack"),
] of Child),
] of Child, userId: "abc123"),
] of Child, user_id: "abc123"),
])
end
end

Wyświetl plik

@ -77,7 +77,8 @@ describe PageConverter do
page = PageConverter.new.convert(data)
page.author.should eq "Author"
page.author.name.should eq "Author"
page.author.id.should eq "abc123"
end
it "sets the publish date/time" do

Wyświetl plik

@ -7,7 +7,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -25,7 +25,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -54,7 +54,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Anchor.new(children: [Text.new("link")] of Child, href: "https://example.com"),
@ -70,7 +70,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
BlockQuote.new(children: [
@ -88,7 +88,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Code.new(children: [
@ -106,7 +106,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -128,7 +128,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Figure.new(children: [
@ -156,7 +156,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
GithubGist.new(href: "https://gist.github.com/user/some_id"),
@ -174,7 +174,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Heading2.new(children: [
@ -192,7 +192,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Heading3.new(children: [
@ -210,7 +210,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -232,7 +232,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
EmbeddedContent.new(
@ -257,7 +257,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -281,7 +281,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -310,7 +310,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
OrderedList.new(children: [
@ -329,7 +329,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Paragraph.new(children: [
@ -347,7 +347,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Preformatted.new(children: [
@ -365,7 +365,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
Strong.new(children: [
@ -383,7 +383,7 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
nodes: [
UnorderedList.new(children: [
@ -402,10 +402,10 @@ describe PageContent do
page = Page.new(
title: "Title",
subtitle: nil,
author: "Author",
author: user_anchor_factory,
created_at: Time.local,
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
)
@ -418,3 +418,12 @@ end
def stripped_html(html : String)
html.gsub(/\n\s*/, "").strip
end
def user_anchor_factory(username = "someone", user_id = "abc123")
PostResponse::Creator.from_json <<-JSON
{
"id": "#{user_id}",
"name": "#{username}"
}
JSON
end

Wyświetl plik

@ -54,8 +54,8 @@ class MarkupConverter
when PostResponse::MarkupType::A
if href = markup.href
Anchor.new(href: href, children: [child] of Child)
elsif userId = markup.userId
UserAnchor.new(userId: userId, children: [child] of Child)
elsif user_id = markup.userId
UserAnchor.new(user_id: user_id, children: [child] of Child)
else
Empty.new
end

Wyświetl plik

@ -19,7 +19,7 @@ end
class PageConverter
def convert(data : PostResponse::Data) : Page
paragraphs = data.post.content.bodyModel.paragraphs
author = data.post.creator.name
author = data.post.creator
created_at = Time.unix_ms(data.post.createdAt)
header = header_data(paragraphs)
if header.first_content_paragraph_index.zero?

Wyświetl plik

@ -193,8 +193,8 @@ module Nodes
getter href : String
def initialize(@children : Children, userId : String)
@href = USER_BASE_URL + userId
def initialize(@children : Children, user_id : String)
@href = USER_BASE_URL + user_id
end
def ==(other : UserAnchor)

Wyświetl plik

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

Wyświetl plik

@ -11,7 +11,7 @@ class Articles::ShowPage < MainLayout
para subtitle, class: "subtitle"
end
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
article do
section do
@ -19,4 +19,9 @@ class Articles::ShowPage < MainLayout
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