Awesome
Plugmap
Plugmap is sitemap generation library for Plug/Phoenix Framework
Installation
Add plugmap
to your list of dependencies in mix.exs
:
def deps do
[{:plugmap, "~> 0.3.0"}]
end
Usage
Plug
defmodule Sitemaps do
use Plugmap
import Plug.Conn
defsitemap :pages do
static do
page "https://website.com", changefreq: "daily", priority: 1.0
page "https://website.com/page", changefreq: "monthly", priority: 0.5
end
end
defsitemap :pages_dynamic do
dynamic do
Enum.reduce(1..10, [], fn(x, acc) ->
item = page "https://website.com", changefreq: "daily", priority: x/10
[item | acc]
end)
end
end
end
Then you can call method Sitemaps.pages(conn)
in Plug
call
function or in Plug.Router
Phoenix Framework
Controller
defmodule SomeApp.SitemapsController do
use SomeApp.Web, :controller
use Plugmap
defsitemap :pages do
static do
page "https://website.com", changefreq: "daily", priority: 1.0
page "https://website.com/page", changefreq: "monthly", priority: 0.5
end
end
defsitemap :pages_dynamic do
dynamic do
Enum.reduce(1..10, [], fn(x, acc) ->
item = page "https://website.com", changefreq: "daily", priority: x/10
[item | acc]
end)
end
end
end
Router
get "/sitemap/pages", SitemapsController, :pages
get "/sitemap/items", SitemapsController, :pages_dynamic
More info in documentation
Routemap
- Cache sitemaps
- Add news sitemap