Add feature to hide "Read more" if there is no more content to read
This commit is contained in:
parent
e19dc4a70f
commit
512ba73f10
5 changed files with 20 additions and 9 deletions
|
@ -22,6 +22,9 @@ config :mebe_web,,
|
||||||
blog_name: "My awesome blog",
|
blog_name: "My awesome blog",
|
||||||
blog_author: "Author McAuthor",
|
blog_author: "Author McAuthor",
|
||||||
absolute_url: "http://localhost:4000", # Absolute URL to the site without trailing slash, including protocol
|
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
|
enable_feeds: false, # Set to true to enable RSS feeds
|
||||||
feeds_full_content: false, # Show full content in feeds instead of short content
|
feeds_full_content: false, # Show full content in feeds instead of short content
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ defmodule MebeEngine.Models do
|
||||||
tags: [],
|
tags: [],
|
||||||
content: nil,
|
content: nil,
|
||||||
short_content: nil,
|
short_content: nil,
|
||||||
order: 0
|
order: 0,
|
||||||
|
has_more: false
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Page do
|
defmodule Page do
|
||||||
|
|
|
@ -67,14 +67,17 @@ defmodule MebeEngine.Parser do
|
||||||
|
|
||||||
order = format_order order
|
order = format_order order
|
||||||
|
|
||||||
|
split_content = String.split content, ~R/<!--\s*SPLIT\s*-->/u
|
||||||
|
|
||||||
%Post{
|
%Post{
|
||||||
slug: slug,
|
slug: slug,
|
||||||
title: title,
|
title: title,
|
||||||
date: date_to_int_tuple({year, month, day}),
|
date: date_to_int_tuple({year, month, day}),
|
||||||
tags: parse_tags(tags),
|
tags: parse_tags(tags),
|
||||||
content: content,
|
content: content,
|
||||||
short_content: hd(String.split content, ~R/<!--\s*SPLIT\s*-->/u),
|
short_content: hd(split_content),
|
||||||
order: order
|
order: order,
|
||||||
|
has_more: (Enum.count(split_content) > 1)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule MebeWeb.ControllerUtils do
|
||||||
@page_commenting Application.get_env(:mebe_web, :page_commenting)
|
@page_commenting Application.get_env(:mebe_web, :page_commenting)
|
||||||
@disqus_shortname Application.get_env(:mebe_web, :disqus_shortname)
|
@disqus_shortname Application.get_env(:mebe_web, :disqus_shortname)
|
||||||
@feeds_enabled Application.get_env(:mebe_web, :enable_feeds)
|
@feeds_enabled Application.get_env(:mebe_web, :enable_feeds)
|
||||||
|
@force_read_more Application.get_env(:mebe_web, :force_read_more)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Render a list of posts with the given template and params. The posts
|
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(:page_commenting, @page_commenting)
|
||||||
|> assign(:disqus_shortname, @disqus_shortname)
|
|> assign(:disqus_shortname, @disqus_shortname)
|
||||||
|> assign(:feeds_enabled, @feeds_enabled)
|
|> assign(:feeds_enabled, @feeds_enabled)
|
||||||
|
|> assign(:force_read_more, @force_read_more)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,11 +43,13 @@
|
||||||
<div class="post-content post-short-content">
|
<div class="post-content post-short-content">
|
||||||
<%= raw @post.short_content %>
|
<%= raw @post.short_content %>
|
||||||
|
|
||||||
<p>
|
<%= if @force_read_more or @post.has_more do %>
|
||||||
<a href="<%= page_path @conn, :post, year, j_month, j_day, @post.slug %>">
|
<p>
|
||||||
Read more…
|
<a href="<%= page_path @conn, :post, year, j_month, j_day, @post.slug %>">
|
||||||
</a>
|
Read more…
|
||||||
</p>
|
</a>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<%= else %>
|
<%= else %>
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
|
@ -70,7 +72,7 @@
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
<noscript>
|
<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>
|
</noscript>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
Reference in a new issue