c9bd1ea7bd
* Added OPML Endpoint for podcast rss feeds * changed opml route and added controller test for opml endpoint * add copy opml feed button * add copy opml feed button - correct url * fix html indenting * add indentation to opml Co-authored-by: Kieran <kieran.eglin@gmail.com> * use convention for unused controller params Co-authored-by: Kieran <kieran.eglin@gmail.com> * add test for opml_sources helper function * change opml endpoint to be more inline with the other routes --------- Co-authored-by: robs <git@robs.social> Co-authored-by: Kieran <kieran.eglin@gmail.com>
41 lines
950 B
Elixir
41 lines
950 B
Elixir
defmodule Pinchflat.Podcasts.OpmlFeedBuilder do
|
|
@moduledoc """
|
|
Methods for building an OPML feed for a list of sources.
|
|
"""
|
|
|
|
import Pinchflat.Utils.XmlUtils, only: [safe: 1]
|
|
|
|
alias PinchflatWeb.Router.Helpers, as: Routes
|
|
|
|
@doc """
|
|
Builds an OPML feed for a given list of sources.
|
|
|
|
Returns an XML document as a string.
|
|
"""
|
|
def build(url_base, sources) do
|
|
sources_xml =
|
|
Enum.map(
|
|
sources,
|
|
&"""
|
|
<outline type="rss" text="#{safe(&1.custom_name)}" xmlUrl="#{safe(source_route(url_base, &1))}" />
|
|
"""
|
|
)
|
|
|
|
"""
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<opml version="2.0">
|
|
<head>
|
|
<title>All Sources</title>
|
|
</head>
|
|
<body>
|
|
#{Enum.join(sources_xml, "\n")}
|
|
</body>
|
|
</opml>
|
|
"""
|
|
end
|
|
|
|
defp source_route(url_base, source) do
|
|
Path.join(url_base, "#{Routes.podcast_path(PinchflatWeb.Endpoint, :rss_feed, source.uuid)}.xml")
|
|
end
|
|
end
|