Skip to content

Commit 1b480fc

Browse files
committed
Add simple topics display to articles
1 parent 2d92d04 commit 1b480fc

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

app/content/layouts/article.html.erb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
) %>
1414
<%= render "application/skip_to_content" %>
1515
<%= render_layout "application" do %>
16-
<article itemscope itemtype="http://schema.org/Article">
16+
<article itemscope itemtype="http://schema.org/Article" class="mb-3xl">
1717
<%= render Pages::Header.new(
1818
title: current_page.data.title!,
1919
description: current_page.data.description,
@@ -33,9 +33,14 @@
3333
</nav>
3434
</aside>
3535
<%- end -%>
36-
<div class="article-content container mb-3xl" itemprop="articleBody">
36+
<div class="article-content container" itemprop="articleBody">
3737
<%= yield %>
3838
</div>
39+
<% if @page.topics.any? %>
40+
<section class="section-content container">
41+
<%= render Pages::Topics.new(topics: @page.topics.pluck(:slug)) %>
42+
</section>
43+
<% end %>
3944
</article>
4045
<section id="newsletter-signup">
4146
<%= render "users/newsletter_subscriptions/banner" %>

app/controllers/site_controller.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ class SiteController < Sitepress::SiteController
55
# render_resource is a helper method provided by Sitepress to render the current resource.
66
# requested_resource is the Sitepress::Resource object that represents the current page.
77
#
8-
# def show
9-
# render_resource requeste_resource
10-
# end
8+
def show
9+
@page = Page.find_or_initialize_by(request_path: request.path)
10+
11+
super
12+
end
1113

1214
protected
1315

@@ -19,7 +21,7 @@ class SiteController < Sitepress::SiteController
1921
#
2022
# For example, the rendition could be modified via `Nokogiri::HTML5::DocumentFragment(rendition)`.
2123
#
22-
# @param rendition [Sitepress::Rendition] Rendered representatio of current_resource
24+
# @param rendition [Sitepress::Rendition] Rendered representation of current_resource
2325
#
2426
def process_rendition(rendition)
2527
end

app/views/application/_footer.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<li>
1515
<a href="/articles">Articles</a>
1616
</li>
17+
<li>
18+
<%= link_to "Topics", topics_path %>
19+
</li>
1720
<li>
1821
<%= link_to "Snippets", share_snippets_path %>
1922
</li>

app/views/components/pages/topics.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Pages
2+
class Topics < ApplicationComponent
3+
include PhlexConcerns::FlexBlock
4+
5+
attr_reader :topics
6+
7+
def initialize(topics: [])
8+
@topics = topics
9+
end
10+
11+
def view_template
12+
if topics.empty?
13+
plain ""
14+
return
15+
end
16+
17+
p(class: "topics") do
18+
topics.each do |topic|
19+
a(href: topic_path(topic), class: "topic step--1") do
20+
"##{topic.try(:slug) || topic}"
21+
end
22+
whitespace
23+
end
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)