ElixirForum Discourse RSS OPML Generator
defmodule Discourse.OPML do
defmodule Behaviour do
@callback outline(list(String.t())) :: String.t()
end
def generate(usernames, forum_specific_generator) do
outline = forum_specific_generator.outline(usernames)
"""
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>RSS OPML Subscriptions</title>
</head>
<body>
#{outline}
</body>
</opml>
"""
end
defmodule ElixirForum do
@behaviour Discourse.OPML.Behaviour
@impl true
def outline(usernames) do
inner_outlines = Enum.map(usernames, &outlines_for_user/1)
"""
<outline title="ElixirForum" text="ElixirForum">
#{inner_outlines}
</outline>
"""
end
defp outlines_for_user(username) do
"""
<outline
text="Latest posts by @#{username}"
title="Latest posts by @#{username}"
type="rss"
xmlUrl="https://elixirforum.com/users/#{username}/activity.rss"
htmlUrl="https://elixirforum.com/u/#{username}/activity"
/>
<outline
text="Latest topics by @#{username}"
title="Latest topics by @#{username}"
type="rss"
xmlUrl="https://elixirforum.com/users/#{username}/activity/topics.rss"
htmlUrl="https://elixirforum.com/u/#{username}/activity/topics"
/>
"""
end
end
end
[
"josevalim",
"mhanberg",
"wojtekmach",
"nicd",
"dorgan",
"axelson",
"benwilson512",
"LostKobrakai",
"Fl4m3Ph03n1x",
"NobbZ",
"hauleth",
"astonj",
"michalmuskala",
"mbuhot",
"ConnorRigby",
"derpycoder"
]
|> Enum.map(&String.downcase/1)
|> Enum.sort()
|> Discourse.OPML.generate(Discourse.OPML.ElixirForum)
|> IO.puts()