Skip to content

Commit 7ac3e55

Browse files
committed
fix: adjust html markup so that it's parsed nicely by safari's reader
mode * rework html markup by removing extra section tag and replacing h1 with header * fixes css that was broken by changes to structure * add structured data so browser can infer things like markup, type, title, and author
1 parent 35bfdaa commit 7ac3e55

File tree

7 files changed

+91
-79
lines changed

7 files changed

+91
-79
lines changed

assets/css/components.css

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ nav.pagination a:hover {
4747
}
4848
.post {
4949
display: flex;
50-
align-items: flex-start;
50+
flex-direction: column;
51+
margin: 0 auto;
5152
margin-bottom: 3vw;
52-
justify-content: center;
53+
min-width: 35rem;
54+
max-width: 60%;
55+
background: rgb(251, 253, 254);
56+
border: 0.2rem solid rgb(255, 255, 255);
57+
box-shadow: 5px 5px 7px var(--navy-light);
58+
box-sizing: border-box;
5359
}
5460
.post:after {
5561
content: "";
@@ -62,37 +68,34 @@ nav.pagination a:hover {
6268
@media screen and (max-width: 480px) {
6369
.post {
6470
display: block;
65-
padding: 0 1rem;
71+
margin: 1rem;
6672
}
6773
}
6874
.post.draft {
6975
opacity: 0.8;
7076
}
71-
.post section {
72-
flex: 0 1 auto;
73-
box-sizing: border-box;
74-
min-width: 35rem;
75-
max-width: 60%;
76-
background: rgb(251, 253, 254);
77-
border: 0.2rem solid rgb(255, 255, 255);
78-
box-shadow: 5px 5px 7px var(--navy-light);
79-
}
8077
@media screen and (max-width: 480px) {
81-
.post section {
78+
.post {
8279
max-width: none;
8380
min-width: 0;
8481
}
8582
}
86-
.post .post__content {
83+
.post.post__content {
8784
overflow: auto;
88-
padding: 4vw;
85+
padding-top: 4vw;
86+
87+
header, footer, .copy, a.twitter-share-button {
88+
padding: 0 4vw;
89+
}
8990
}
90-
.post .post__content h1:first-of-type a {
91+
.post.post__content header:first-of-type a {
92+
font-family: var(--primary-typeface);
93+
font-weight: bold;
9194
color: inherit;
9295
display: block;
9396
transition: color 0.1s;
9497
}
95-
.post .post__content h1:first-of-type a:hover {
98+
.post.post__content header:first-of-type a:hover {
9699
color: var(--red);
97100
}
98101
.post footer {
@@ -125,6 +128,9 @@ nav.pagination a:hover {
125128
.post footer a:hover {
126129
text-decoration: underline;
127130
}
131+
.post aside {
132+
padding-top: 4vw;
133+
}
128134
.post aside ul {
129135
display: flex;
130136
width: 100%;
@@ -341,15 +347,25 @@ form input[type='submit']:active, form button[type='submit']:active, form input[
341347
font-size: 0.85em;
342348
}
343349
}
344-
.copy h1, .copy h2, .copy h3, .copy p, .copy ul, .copy ol {
345-
margin: 0 0 1.2em 0;
350+
.post.post__content header, .copy {
351+
h1, h2, h3, h4, h5, p, ul, ol {
352+
margin: 0 0 1.2em 0;
353+
}
354+
header:first-type-of a {
355+
margin: 0 0 1.2em 0;
356+
}
346357
}
347358
@media screen and (max-width: 480px) {
348-
.copy h1, .copy h2, .copy h3, .copy p, .copy ul, .copy ol {
349-
margin-bottom: 0.7em;
350-
}
351-
}
352-
.copy h1 {
359+
.post.post__content header, .copy {
360+
h1, h2, h3, h4, h5, p, ul, ol {
361+
margin-bottom: 0.7em;
362+
}
363+
header:first-type-of a {
364+
margin-bottom: 0.7em;
365+
}
366+
}
367+
}
368+
.copy h1, .post.post__content header:first-of-type a {
353369
font-size: 1.6em;
354370
}
355371
.copy h2, .copy h3 {

assets/js/like.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ $(function(){
7171
new LikeButton(this);
7272
});
7373

74-
$('header').attr('data-likes-loaded', 'true')
74+
$('header.site_head').attr('data-likes-loaded', 'true')
7575
});
Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1-
<article class="post">
2-
<section>
3-
<div class="post__content copy">
4-
<h1>
5-
<%= link(@post.title, to: Routes.post_path(@conn, :show, @post)) %>
6-
</h1>
7-
<%= raw Tilex.Markdown.to_html(@post.body) %>
1+
<article class="post post__content" itemscope itemtype="https://schema.org/BlogPosting">
2+
<header itemprop="headline">
3+
<h3><%= link(@post.title, to: Routes.post_path(@conn, :show, @post)) %></h3>
4+
</header>
85

9-
<%= if assigns[:twitter_shareable] && Mix.env != :test do %>
10-
<a href='http://twitter.com/share'
11-
class='twitter-share-button'
12-
data-text= "Today I learned: <%= @post.title %>"
13-
data-via= "<%= Tilex.Blog.Developer.twitter_handle(@post.developer) %>"
14-
data-hashtags= "<%= @post.channel.twitter_hashtag %>"
15-
data-url= "<%= Routes.post_url(@conn, :show, @post) %>">
16-
Tweet
17-
</a>
18-
<% end %>
6+
<div class="copy" itemprop="blogPost">
7+
<%= raw Tilex.Markdown.to_html(@post.body) %>
8+
</div>
9+
10+
<%= if assigns[:twitter_shareable] && Mix.env != :test do %>
11+
<a href='http://twitter.com/share'
12+
class='twitter-share-button'
13+
data-text= "Today I learned: <%= @post.title %>"
14+
data-via= "<%= Tilex.Blog.Developer.twitter_handle(@post.developer) %>"
15+
data-hashtags= "<%= @post.channel.twitter_hashtag %>"
16+
data-url= "<%= Routes.post_url(@conn, :show, @post) %>">
17+
Tweet
18+
</a>
19+
<% end %>
1920

20-
<footer>
21-
<p class="byline">
22-
<%= link(@post.developer.username, to: Routes.developer_path(@conn, :show, @post.developer)) %>
23-
<br/>
24-
<time datetime="<%= @post.inserted_at %>">
25-
<%= link(display_date(@post), to: Routes.post_path(@conn, :show, @post), class: "post__permalink") %>
26-
</time>
27-
</p>
28-
</footer>
21+
<footer class="byline">
22+
<%= link(@post.developer.username, to: Routes.developer_path(@conn, :show, @post.developer), itemprop: "author") %>
23+
<div itemprop="datePublished">
24+
<%= link(display_date(@post), to: Routes.post_path(@conn, :show, @post), class: "post__permalink") %>
2925
</div>
30-
<aside>
31-
<ul>
26+
</footer>
27+
<aside>
28+
<ul>
29+
<li>
30+
<%= link("##{@post.channel.name}", to: Routes.channel_path(@conn, :show, @post.channel.name), class: "post__tag-link", itemprop: "keywords") %>
31+
</li>
32+
<li>
33+
<%= link("permalink", to: Routes.post_path(@conn, :show, @post), class: "post__permalink") %>
34+
</li>
35+
<li>
36+
<%= link("raw", to: "#{Routes.post_path(@conn, :show, @post)}.md", class: "post__raw-link") %>
37+
</li>
38+
<%= if TilexWeb.SharedView.post_creator_or_admin?(@conn, @post) do %>
3239
<li>
33-
<%= link("##{@post.channel.name}", to: Routes.channel_path(@conn, :show, @post.channel.name), class: "post__tag-link") %>
40+
<%= link("edit", to: Routes.post_path(@conn, :edit, @post), class: "post__permalink") %>
3441
</li>
35-
<li>
36-
<%= link("permalink", to: Routes.post_path(@conn, :show, @post), class: "post__permalink") %>
37-
</li>
38-
<li>
39-
<%= link("raw", to: "#{Routes.post_path(@conn, :show, @post)}.md", class: "post__raw-link") %>
40-
</li>
41-
<%= if TilexWeb.SharedView.post_creator_or_admin?(@conn, @post) do %>
42-
<li>
43-
<%= link("edit", to: Routes.post_path(@conn, :edit, @post), class: "post__permalink") %>
44-
</li>
42+
<% end %>
43+
<li>
44+
<%= link to: "#", class: "js-like-action post__like-link", id: @post.slug do %>
45+
<span class="post__like-heart"><%= icon("heart", :small, "likes") %></span>
46+
<span class="post__like-count"><%= @post.likes %></span>
4547
<% end %>
46-
<li>
47-
<%= link to: "#", class: "js-like-action post__like-link", id: @post.slug do %>
48-
<span class="post__like-heart"><%= icon("heart", :small, "likes") %></span>
49-
<span class="post__like-count"><%= @post.likes %></span>
50-
<% end %>
51-
</li>
52-
</ul>
53-
</aside>
54-
</section>
48+
</li>
49+
</ul>
50+
</aside>
5551
</article>

test/features/visitor_searches_posts_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ defmodule VisiorSearchesPosts do
6464
end
6565

6666
defp get_first_post_on_page_title(session) do
67-
get_text(session, "#home > article:first-child h1 a")
67+
get_text(session, "#home > article:first-child header a")
6868
end
6969
end

test/features/visitor_views_channel_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ defmodule Features.VisitorViewsChannelTest do
4242
|> assert_has(Query.css("article.post", count: 5))
4343
|> assert_has(Query.css("nav.pagination", visible: true))
4444
|> visit("/smalltalk?page=2")
45-
|> assert_has(Query.css("h1", text: "Title1", visible: true))
45+
|> assert_has(Query.css("article header a", text: "Title1", visible: true))
4646
|> assert_has(Query.css("article.post", count: 1))
4747
|> visit("/smalltalk")
48-
|> assert_has(Query.css("h1", text: "Title5", visible: true))
48+
|> assert_has(Query.css("article header a", text: "Title5", visible: true))
4949
|> assert_has(Query.css("article.post", count: 5))
5050
end
5151
end

test/features/visitor_visits_homepage_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule VisitorVisitsHomepageTest do
3535
Element.text(find(session, Query.css(selector)))
3636
end
3737

38-
post_header = element_text.(session, "article h1")
38+
post_header = element_text.(session, "article header a")
3939
post_body = element_text.(session, "article")
4040
post_footer = element_text.(session, ".post aside")
4141

test/support/pages/post_show_page.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Tilex.Integration.Pages.PostShowPage do
1010
|> Browser.find(Query.css("article.post"))
1111

1212
session
13-
|> Browser.find(Query.css("h1", text: title))
13+
|> Browser.find(Query.css("header a", text: title))
1414

1515
session
1616
end
@@ -29,7 +29,7 @@ defmodule Tilex.Integration.Pages.PostShowPage do
2929
expected_likes_count = attrs |> Map.fetch!(:likes_count) |> to_string()
3030

3131
session
32-
|> Browser.find(Query.css(".post h1", text: expected_title))
32+
|> Browser.find(Query.css(".post header a", text: expected_title))
3333

3434
session
3535
|> Browser.find(Query.css(".post .copy", text: expected_body))

0 commit comments

Comments
 (0)