Skip to content

Commit

Permalink
Avoid showing HTML tag in page title (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmterrorf committed Dec 15, 2023
1 parent a3a51b5 commit 946f45a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/mix/tasks/school_house.gen.rss.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Mix.Tasks.SchoolHouse.Gen.Rss do

"""
<item>
<title>#{post.title}</title>
<title>#{post.title_text}</title>
<description>#{post.excerpt}</description>
<pubDate>#{Calendar.strftime(post.date, "%a, %d %B %Y 00:00:00 +0000")}</pubDate>
<link>#{link}</link>
Expand Down
10 changes: 6 additions & 4 deletions lib/school_house/content/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule SchoolHouse.Content.Post do
Encapsulates an individual post and handles parsing the originating markdown file
"""

@enforce_keys [:author, :author_link, :body, :date, :excerpt, :slug, :tags, :title]
@enforce_keys [:author, :author_link, :body, :date, :excerpt, :slug, :tags, :title, :title_text]
defstruct [
:author,
:author_link,
Expand All @@ -12,7 +12,8 @@ defmodule SchoolHouse.Content.Post do
:excerpt,
:slug,
:tags,
:title
:title,
:title_text
]

@doc """
Expand All @@ -32,12 +33,13 @@ defmodule SchoolHouse.Content.Post do
|> Path.basename(".md")
|> String.slice(date_prefix_length..-1)

{title, attrs} = Map.pop!(attrs, :title)
{title_text, attrs} = Map.pop!(attrs, :title)
{excerpt, attrs} = Map.pop!(attrs, :excerpt)

attrs =
attrs
|> Map.put(:title, Earmark.as_html!(title))
|> Map.put(:title_text, title_text)
|> Map.put(:title, Earmark.as_html!(title_text))
|> Map.put(:excerpt, Earmark.as_html!(excerpt))

struct!(__MODULE__, [body: body, slug: slug] ++ Map.to_list(attrs))
Expand Down
2 changes: 1 addition & 1 deletion lib/school_house_web/controllers/post_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ defmodule SchoolHouseWeb.PostController do
end
end

defp format_page_title(%Post{title: title}), do: title <> " | " <> @page_title
defp format_page_title(%Post{title_text: title}), do: title <> " | " <> @page_title
defp format_page_title(_), do: @page_title
end

0 comments on commit 946f45a

Please sign in to comment.