Improve title parsing

The subtitle has been removed because it's difficult to find and error
prone to guess at. It is somewhat accessible from the post's
previewContent field in GraphQL but that can be truncated.
This commit is contained in:
Edward Loveall
2021-10-03 18:14:46 -04:00
parent 2808505b4e
commit fba87c1076
5 changed files with 25 additions and 117 deletions

View File

@@ -3,56 +3,26 @@ require "../spec_helper"
include Nodes
describe PageConverter do
it "sets the title and subtitle if present" do
it "sets the page title" do
title = "Hello, world!"
paragraph_json = <<-JSON
[
{
"text": "Title",
"text": "#{title}",
"type": "H3",
"markups": [],
"iframe": null,
"layout": null,
"metadata": null
},
{
"text": "Subtitle",
"type": "H4",
"markups": [],
"iframe": null,
"layout": null,
"metadata": null
}
]
JSON
data_json = default_data_json(paragraph_json)
data_json = default_data_json(title, paragraph_json)
data = PostResponse::Data.from_json(data_json)
page = PageConverter.new.convert(data)
page.title.should eq "Title"
page.subtitle.should eq "Subtitle"
end
it "sets the title to the first paragraph if no title" do
paragraph_json = <<-JSON
[
{
"text": "Not a title",
"type": "P",
"markups": [],
"iframe": null,
"layout": null,
"metadata": null
}
]
JSON
data_json = default_data_json(paragraph_json)
data = PostResponse::Data.from_json(data_json)
page = PageConverter.new.convert(data)
page.title.should eq "Not a title"
page.subtitle.should eq nil
page.title.should eq title
end
it "sets the author" do
@@ -106,25 +76,18 @@ describe PageConverter do
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 converts the remaining paragraph content" do
title = "Title"
paragraph_json = <<-JSON
[
{
"text": "Title",
"text": "#{title}",
"type": "H3",
"markups": [],
"iframe": null,
"layout": null,
"metadata": null
},
{
"text": "Subtitle",
"type": "H4",
"markups": [],
"iframe": null,
"layout": null,
"metadata": null
},
{
"text": "Content",
"type": "P",
@@ -135,7 +98,7 @@ describe PageConverter do
}
]
JSON
data_json = default_data_json(paragraph_json)
data_json = default_data_json(title, paragraph_json)
data = PostResponse::Data.from_json(data_json)
page = PageConverter.new.convert(data)
@@ -148,11 +111,18 @@ describe PageConverter do
end
end
def default_data_json(paragraph_json : String)
def default_paragraph_json
"[]"
end
def default_data_json(
title : String = "This is a story",
paragraph_json : String = default_paragraph_json
)
<<-JSON
{
"post": {
"title": "This is a story",
"title": "#{title}",
"createdAt": 1628974309758,
"creator": {
"id": "abc123",

View File

@@ -6,7 +6,6 @@ describe PageContent do
it "renders a single parent/child node structure" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -24,7 +23,6 @@ describe PageContent do
it "renders multiple childrens" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -53,7 +51,6 @@ describe PageContent do
it "renders an anchor" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -69,7 +66,6 @@ describe PageContent do
it "renders a blockquote" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -87,7 +83,6 @@ describe PageContent do
it "renders code" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -105,7 +100,6 @@ describe PageContent do
it "renders empasis" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -127,7 +121,6 @@ describe PageContent do
children = [Text.new("A caption")] of Child
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -155,7 +148,6 @@ describe PageContent do
it "renders a GitHub Gist" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -173,7 +165,6 @@ describe PageContent do
it "renders an H3" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -191,7 +182,6 @@ describe PageContent do
it "renders an H4" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -209,7 +199,6 @@ describe PageContent do
it "renders an image" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -231,7 +220,6 @@ describe PageContent do
it "renders embedded content" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -256,7 +244,6 @@ describe PageContent do
it "renders an embedded link container" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -280,7 +267,6 @@ describe PageContent do
it "renders an mixtape embed container" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -311,7 +297,6 @@ describe PageContent do
it "renders an ordered list" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -330,7 +315,6 @@ describe PageContent do
it "renders an preformatted text" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -348,7 +332,6 @@ describe PageContent do
it "renders an preformatted text" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -366,7 +349,6 @@ describe PageContent do
it "renders strong text" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -384,7 +366,6 @@ describe PageContent do
it "renders an unordered list" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [
@@ -403,7 +384,6 @@ describe PageContent do
it "renders a user anchor" do
page = Page.new(
title: "Title",
subtitle: nil,
author: user_anchor_factory,
created_at: Time.local,
nodes: [