Browse Source

fix: fetch the hostname from the url to print the current link

danilo silva 3 years ago
parent
commit
1ee361938e
2 changed files with 17 additions and 2 deletions
  1. 2 2
      lib/openpod_web/templates/feed/feed.xml.eex
  2. 15 0
      lib/openpod_web/views/feed_view.ex

+ 2 - 2
lib/openpod_web/templates/feed/feed.xml.eex

@@ -2,7 +2,7 @@
 <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0">
   <channel>
     <link><%= @podcast.link %></link>
-    <language><![CDATA[<%= @podcast.language %>]]></language>
+    <language><%= @podcast.language %></language>
     <copyright>&#xA9;2022</copyright>
     <webMaster><![CDATA[<%= @podcast.webmaster %>]]></webMaster>
     <managingEditor><![CDATA[<%= @podcast.webmaster %>]]></managingEditor>
@@ -21,7 +21,7 @@
     <itunes:keywords><%= @podcast.keywords |> Enum.join(", ") %></itunes:keywords>
     <itunes:explicit><![CDATA[<%= @podcast.explicit %>]]></itunes:explicit>
     <itunes:image href="<%= @podcast.image.url %>" />
-    <atom:link href="<%= OpenpodWeb.Endpoint.url <> Routes.feed_path(@conn, :by_identifier, @identifier) %>" rel="self" type="application/rss+xml" />
+    <atom:link href="<%= base_url(@conn)  <> Routes.feed_path(@conn, :by_identifier, @identifier) %>" rel="self" type="application/rss+xml" />
     <pubDate><%= @podcast.pubDate |> Calendar.DateTime.Format.rfc2822 %></pubDate>
     <title><![CDATA[<%= @podcast.title %>]]></title>
     <itunes:author><![CDATA[<%= @podcast.owner.name %>]]></itunes:author>

+ 15 - 0
lib/openpod_web/views/feed_view.ex

@@ -6,4 +6,19 @@ defmodule OpenpodWeb.FeedView do
     sec = length - (min * 60) |> Integer.to_string |> String.pad_leading(2, "0")
     "#{min}:#{sec}"
   end
+
+  def base_url(conn) do
+    scheme = conn
+    |> Map.fetch!(:scheme)
+    |> Atom.to_string
+
+    host = conn
+    |> Map.fetch!(:host)
+
+    port = conn
+    |> Map.fetch!(:port)
+    |> Integer.to_string
+
+    "#{scheme}://#{host}:#{port}"
+  end
 end