diff --git a/app/lib/firehose_web/components/core_components.ex b/app/lib/firehose_web/components/core_components.ex index dcb60ad..d0be6c1 100644 --- a/app/lib/firehose_web/components/core_components.ex +++ b/app/lib/firehose_web/components/core_components.ex @@ -420,6 +420,30 @@ defmodule FirehoseWeb.CoreComponents do """ end + @doc """ + Renders an RSS feed icon (inline SVG). + + ## Examples + + <.rss_icon class="size-5" /> + """ + attr :class, :string, default: "size-4" + attr :rest, :global + + def rss_icon(assigns) do + ~H""" + + """ + end + ## JS Commands def show(js \\ %JS{}, selector) do diff --git a/app/lib/firehose_web/components/layouts/app.html.heex b/app/lib/firehose_web/components/layouts/app.html.heex index 5d99688..d787052 100644 --- a/app/lib/firehose_web/components/layouts/app.html.heex +++ b/app/lib/firehose_web/components/layouts/app.html.heex @@ -39,4 +39,30 @@ + + <.flash_group flash={@flash} /> diff --git a/app/lib/firehose_web/components/layouts/root.html.heex b/app/lib/firehose_web/components/layouts/root.html.heex index 4147954..74b7879 100644 --- a/app/lib/firehose_web/components/layouts/root.html.heex +++ b/app/lib/firehose_web/components/layouts/root.html.heex @@ -41,6 +41,9 @@ <% end %> <% end %> + <%= for feed <- get_content_for(assigns, :feed_links) do %> + + <% end %>
{@inner_content} diff --git a/app/lib/firehose_web/controllers/blog_controller.ex b/app/lib/firehose_web/controllers/blog_controller.ex index 43cab46..72fa372 100644 --- a/app/lib/firehose_web/controllers/blog_controller.ex +++ b/app/lib/firehose_web/controllers/blog_controller.ex @@ -9,9 +9,11 @@ defmodule FirehoseWeb.BlogController do result = blog.paginate(page) meta = Blogex.SEO.meta_tags_for_blog(blog, FirehoseWeb.Endpoint.url()) + rss_url = rss_feed_url(blog) conn |> FirehoseWeb.Layouts.put_content_for(:meta_tags, meta) + |> FirehoseWeb.Layouts.put_content_for(:feed_links, %{rss_url: rss_url, title: blog.title()}) |> render(:index, page_title: blog.title(), blog_title: blog.title(), @@ -19,7 +21,8 @@ defmodule FirehoseWeb.BlogController do posts: result.entries, base_path: blog.base_path(), page: result.page, - total_pages: result.total_pages + total_pages: result.total_pages, + rss_feed_url: rss_url ) end @@ -27,31 +30,40 @@ defmodule FirehoseWeb.BlogController do blog = conn.assigns.blog post = blog.get_post!(slug) visibility = Blogex.Post.visibility(post) + rss_url = rss_feed_url(blog) meta = Blogex.SEO.meta_tags(post, FirehoseWeb.Endpoint.url(), blog) conn |> FirehoseWeb.Layouts.put_content_for(:meta_tags, meta) + |> FirehoseWeb.Layouts.put_content_for(:feed_links, %{rss_url: rss_url, title: blog.title()}) |> render(:show, page_title: post.title, post: post, meta: meta, base_path: blog.base_path(), visibility: visibility, - authenticated: !!(conn.assigns[:current_scope] && conn.assigns.current_scope.user) + authenticated: !!(conn.assigns[:current_scope] && conn.assigns.current_scope.user), + rss_feed_url: rss_url ) end def tag(conn, %{"tag" => tag}) do blog = conn.assigns.blog posts = blog.posts_by_tag(tag) + rss_url = rss_feed_url(blog) - render(conn, :tag, + rss_link = %{rss_url: rss_url, title: blog.title()} + + conn + |> FirehoseWeb.Layouts.put_content_for(:feed_links, rss_link) + |> render(:tag, page_title: "#{blog.title()} — #{tag}", blog_title: blog.title(), tag: tag, posts: posts, - base_path: blog.base_path() + base_path: blog.base_path(), + rss_feed_url: rss_url ) end @@ -77,4 +89,9 @@ defmodule FirehoseWeb.BlogController do _ -> 1 end end + + defp rss_feed_url(blog) do + base_id = blog.base_path() |> String.trim_leading("/blog/") + FirehoseWeb.Endpoint.url() <> "/api/blog/#{base_id}/feed.xml" + end end diff --git a/app/lib/firehose_web/controllers/blog_html/index.html.heex b/app/lib/firehose_web/controllers/blog_html/index.html.heex index c96f07a..7a7c119 100644 --- a/app/lib/firehose_web/controllers/blog_html/index.html.heex +++ b/app/lib/firehose_web/controllers/blog_html/index.html.heex @@ -1,6 +1,17 @@{@blog_description}
Posts tagged "{@tag}"