Coder Social home page Coder Social logo

plain_sitemap's Introduction

PlainSitemap

PlainSitemap is a simple sitemap generator for Elixir.

Installation

Add plain_sitemap to your list of dependencies in mix.exs:

def deps do
  [{:plain_sitemap, github: "kenta-aktsk/plain_sitemap"}]
end

Ensure plain_sitemap is started before your application:

def application do
  [applications: [:plain_sitemap]]
end

Usage

(Assume that your app name is my_app, your site url is http://example.com, and you have Entry model)

Add module and define urlset like below:

# web/sitemap.ex
defmodule MyApp.Sitemap do
  use PlainSitemap, app: :my_app, default_host: "http://example.com"
  alias MyApp.{Repo, Entry}

  urlset do
    add "/", changefreq: "hourly", priority: 1.0
    Entry |> Repo.all |> Enum.each(fn(entry) ->
      add "/entries/#{entry.id}", lastmod: entry.updated_at, changefreq: "daily", priority: 0.5
    end)
  end
end

Now You can generate sitemap on iex like below: (output path is priv/static/sitemap.xml.gz)

MyApp.Sitemap.refresh

And you can generate sitemap by using rpc call to compiled package: (output path is lib/my_app-{version}/priv/static/sitemap.xml.gz)

bin/my_app rpc Elixir.MyApp.Sitemap refresh

Generated sitemap example is below:

<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns=...>
  <url>
    <loc>http://example.com/</loc>
    <lastmod>2016-04-10T10:10:10+00:00</lastmod>
    <changefreq>hourly</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://example.com/entries/1</loc>
    <lastmod>2016-04-20T02:02:02+00:00</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>
  ...
</urlset>

Supported Options to add

Similar to sitemap_generator.

  • expires option is not supported.

Datetime support

PlainSitemap support Ecto.DateTime and Timex.

plain_sitemap's People

Contributors

kenta-aktsk avatar mjcloutier avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.