Add feature to hide "Read more" if there is no more content to read

This commit is contained in:
Mikko Ahlroth 2015-11-17 23:43:24 +02:00
parent e19dc4a70f
commit 512ba73f10
5 changed files with 20 additions and 9 deletions

View file

@ -22,6 +22,9 @@ config :mebe_web,,
blog_name: "My awesome blog",
blog_author: "Author McAuthor",
absolute_url: "http://localhost:4000", # Absolute URL to the site without trailing slash, including protocol
force_read_more: false, # Force "Read more…" text to display even if there is no more content
enable_feeds: false, # Set to true to enable RSS feeds
feeds_full_content: false, # Show full content in feeds instead of short content

View file

@ -17,7 +17,8 @@ defmodule MebeEngine.Models do
tags: [],
content: nil,
short_content: nil,
order: 0
order: 0,
has_more: false
end
defmodule Page do

View file

@ -67,14 +67,17 @@ defmodule MebeEngine.Parser do
order = format_order order
split_content = String.split content, ~R/<!--\s*SPLIT\s*-->/u
%Post{
slug: slug,
title: title,
date: date_to_int_tuple({year, month, day}),
tags: parse_tags(tags),
content: content,
short_content: hd(String.split content, ~R/<!--\s*SPLIT\s*-->/u),
order: order
short_content: hd(split_content),
order: order,
has_more: (Enum.count(split_content) > 1)
}
end
end

View file

@ -13,6 +13,7 @@ defmodule MebeWeb.ControllerUtils do
@page_commenting Application.get_env(:mebe_web, :page_commenting)
@disqus_shortname Application.get_env(:mebe_web, :disqus_shortname)
@feeds_enabled Application.get_env(:mebe_web, :enable_feeds)
@force_read_more Application.get_env(:mebe_web, :force_read_more)
@doc """
Render a list of posts with the given template and params. The posts
@ -38,5 +39,6 @@ defmodule MebeWeb.ControllerUtils do
|> assign(:page_commenting, @page_commenting)
|> assign(:disqus_shortname, @disqus_shortname)
|> assign(:feeds_enabled, @feeds_enabled)
|> assign(:force_read_more, @force_read_more)
end
end

View file

@ -43,11 +43,13 @@
<div class="post-content post-short-content">
<%= raw @post.short_content %>
<p>
<a href="<%= page_path @conn, :post, year, j_month, j_day, @post.slug %>">
Read more
</a>
</p>
<%= if @force_read_more or @post.has_more do %>
<p>
<a href="<%= page_path @conn, :post, year, j_month, j_day, @post.slug %>">
Read more
</a>
</p>
<% end %>
</div>
<%= else %>
<div class="post-content">
@ -70,7 +72,7 @@
})();
</script>
<noscript>
Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a>
Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus</a>.
</noscript>
<% end %>