Skip to content

XML Sitemap generator for Plug / Phoenix Framework

License

Notifications You must be signed in to change notification settings

nerdslabs/plugmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hex.pm Downloads Inline docs

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

About

XML Sitemap generator for Plug / Phoenix Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages