Add OPML export
This commit is contained in:
parent
1015fd5162
commit
b559bd9dc3
|
@ -0,0 +1,32 @@
|
||||||
|
defmodule Frenzy.OPML.Exporter do
|
||||||
|
import XmlBuilder
|
||||||
|
|
||||||
|
@spec export([Frenzy.Group.t()]) :: String.t()
|
||||||
|
def export(groups) do
|
||||||
|
element(:opml, %{version: "1.0"}, [
|
||||||
|
element(:head, %{}, [
|
||||||
|
element(:title, "Frenzy export")
|
||||||
|
]),
|
||||||
|
element(
|
||||||
|
:body,
|
||||||
|
%{},
|
||||||
|
Enum.map(groups, fn group ->
|
||||||
|
element(
|
||||||
|
:outline,
|
||||||
|
%{text: group.title, title: group.title},
|
||||||
|
Enum.map(group.feeds, fn feed ->
|
||||||
|
element(:outline, %{
|
||||||
|
type: "rss",
|
||||||
|
text: feed.title,
|
||||||
|
title: feed.title,
|
||||||
|
xmlUrl: feed.feed_url,
|
||||||
|
htmlUrl: feed.site_url
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|> generate()
|
||||||
|
end
|
||||||
|
end
|
|
@ -146,4 +146,10 @@ defmodule FrenzyWeb.AccountController do
|
||||||
)
|
)
|
||||||
|> redirect(to: Routes.group_path(Endpoint, :index))
|
|> redirect(to: Routes.group_path(Endpoint, :index))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def export(conn, _params) do
|
||||||
|
user = conn.assigns[:user] |> Repo.preload(:groups)
|
||||||
|
opml = Frenzy.OPML.Exporter.export(user.groups)
|
||||||
|
send_download(conn, {:binary, opml}, filename: "frenzy_export.opml")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,7 @@ defmodule FrenzyWeb.Router do
|
||||||
post "/account/change_fever_password", AccountController, :do_change_fever_password
|
post "/account/change_fever_password", AccountController, :do_change_fever_password
|
||||||
post "/account/remove_client", AccountController, :remove_client
|
post "/account/remove_client", AccountController, :remove_client
|
||||||
post "/account/import", AccountController, :import
|
post "/account/import", AccountController, :import
|
||||||
|
post "/account/export", AccountController, :export
|
||||||
|
|
||||||
get "/", GroupController, :index
|
get "/", GroupController, :index
|
||||||
resources "/groups", GroupController, except: [:edit, :update]
|
resources "/groups", GroupController, except: [:edit, :update]
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
<%= file_input f, :file %>
|
<%= file_input f, :file %>
|
||||||
<%= submit "Import OPML", class: "btn btn-primary" %>
|
<%= submit "Import OPML", class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= form_for @conn, Routes.account_path(@conn, :export), [method: :post, class: "mt-2"], fn f -> %>
|
||||||
|
<%= submit "Export OPML", class: "btn btn-primary" %>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="mt-4">
|
<section class="mt-4">
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -48,7 +48,7 @@ defmodule Frenzy.MixProject do
|
||||||
{:timex, "~> 3.0"},
|
{:timex, "~> 3.0"},
|
||||||
{:readability, git: "https://github.com/shadowfacts/readability.git", branch: "master"},
|
{:readability, git: "https://github.com/shadowfacts/readability.git", branch: "master"},
|
||||||
{:bcrypt_elixir, "~> 2.0"},
|
{:bcrypt_elixir, "~> 2.0"},
|
||||||
{:dialyxir, "~> 1.0.0-rc.6"},
|
{:dialyxir, "~> 1.0.0-rc.6", only: :dev, runtime: false},
|
||||||
{:xml_builder, "~> 2.1.1"}
|
{:xml_builder, "~> 2.1.1"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue