Current section
36 Versions
Jump to
Current section
36 Versions
Compare versions
5
files changed
+84
additions
-11
deletions
| @@ -8,7 +8,7 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed | |
| 8 8 | |
| 9 9 | ```elixir |
| 10 10 | def deps do |
| 11 | - [{:sitemap, "~> 0.0.1"}] |
| 11 | + [{:sitemap, ">= 0.0.0"}] |
| 12 12 | end |
| 13 13 | ``` |
| 14 14 | |
| @@ -19,3 +19,76 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed | |
| 19 19 | [applications: [:sitemap]] |
| 20 20 | end |
| 21 21 | ``` |
| 22 | + |
| 23 | + #### Usage |
| 24 | + |
| 25 | + ##### Basic |
| 26 | + |
| 27 | + ```elixir |
| 28 | + defmodule Sitemaps do |
| 29 | + use Sitemap |
| 30 | + |
| 31 | + create do |
| 32 | + add "path1", priority: 0.5, changefreq: "hourly", expires: nil, mobile: true |
| 33 | + end |
| 34 | + |
| 35 | + ping |
| 36 | + end |
| 37 | + ``` |
| 38 | + |
| 39 | + ##### As a function |
| 40 | + |
| 41 | + ```elixir |
| 42 | + defmodule Sitemaps do |
| 43 | + use Sitemap |
| 44 | + |
| 45 | + def generate do |
| 46 | + create do |
| 47 | + add "path1", priority: 0.5, changefreq: "hourly", expires: nil, mobile: true |
| 48 | + end |
| 49 | + |
| 50 | + ping |
| 51 | + end |
| 52 | + |
| 53 | + end |
| 54 | + ``` |
| 55 | + |
| 56 | + ##### With Ecto |
| 57 | + |
| 58 | + ```elixir |
| 59 | + a |
| 60 | + b |
| 61 | + ``` |
| 62 | + |
| 63 | + #### Change options. |
| 64 | + |
| 65 | + ###### Change option( use statement ) |
| 66 | + |
| 67 | + ```elixir |
| 68 | + defmodule Sitemaps do |
| 69 | + use Sitemap, compress: false, create_index: true |
| 70 | + |
| 71 | + create do |
| 72 | + add "path1", priority: 0.5, changefreq: "hourly" |
| 73 | + add "path2", priority: 0.5, changefreq: "hourly" |
| 74 | + end |
| 75 | + |
| 76 | + ping |
| 77 | + end |
| 78 | + ``` |
| 79 | + |
| 80 | + ###### Change option( create function's option ) |
| 81 | + |
| 82 | + |
| 83 | + ```elixir |
| 84 | + defmodule Sitemaps do |
| 85 | + use Sitemap |
| 86 | + |
| 87 | + create compress: false, create_index: true do |
| 88 | + add "path1", priority: 0.5, changefreq: "hourly" |
| 89 | + add "path2", priority: 0.5, changefreq: "hourly" |
| 90 | + end |
| 91 | + |
| 92 | + ping |
| 93 | + end |
| 94 | + ``` |
| @@ -22,4 +22,4 @@ | |
| 22 22 | [{<<"app">>,<<"xml_builder">>}, |
| 23 23 | {<<"optional">>,false}, |
| 24 24 | {<<"requirement">>,<<">= 0.0.0">>}]}]}. |
| 25 | - {<<"version">>,<<"0.5.5">>}. |
| 25 | + {<<"version">>,<<"0.5.6">>}. |
| @@ -1,11 +1,12 @@ | |
| 1 1 | defmodule Sitemap.Builders.Url do |
| 2 2 | alias Sitemap.Funcs |
| 3 | + alias Sitemap.Config |
| 3 4 | import XmlBuilder |
| 4 5 | |
| 5 6 | def to_xml(link, attrs \\ []) do |
| 6 7 | elms = |
| 7 8 | element(:url, Funcs.eraser([ |
| 8 | - element(:loc, link), |
| 9 | + element(:loc, Path.join(Config.get.host, link || "")), |
| 9 10 | element(:lastmod, Keyword.get_lazy(attrs, :lastmod, fn -> Funcs.iso8601 end)), |
| 10 11 | element(:expires, attrs[:expires]), |
| 11 12 | element(:changefreq, attrs[:changefreq]), |
| @@ -20,6 +20,10 @@ defmodule Sitemap.Generator do | |
| 20 20 | |
| 21 21 | def fin do |
| 22 22 | full |
| 23 | + reset |
| 24 | + end |
| 25 | + |
| 26 | + def reset do |
| 23 27 | Indexfile.write |
| 24 28 | Indexfile.finalize_state |
| 25 29 | Namer.update_state :file, :count, nil |
| @@ -28,12 +32,10 @@ defmodule Sitemap.Generator do | |
| 28 32 | # def group do end |
| 29 33 | |
| 30 34 | def ping(urls \\ []) do |
| 31 | - urls = ~w( |
| 32 | - http://google.com/ping?sitemap= |
| 35 | + urls = ~w(http://google.com/ping?sitemap= |
| 33 36 | http://www.google.com/webmasters/sitemaps/ping?sitemap= |
| 34 37 | http://www.bing.com/webmaster/ping.aspx?sitemap= |
| 35 | - http://submissions.ask.com/ping?sitemap= |
| 36 | - ) ++ urls |
| 38 | + http://submissions.ask.com/ping?sitemap=) ++ urls |
| 37 39 | |
| 38 40 | indexurl = Location.url :indexfile |
| 39 41 | |
| @@ -46,7 +48,4 @@ defmodule Sitemap.Generator do | |
| 46 48 | end |
| 47 49 | end |
| 48 50 | |
| 49 | - def set_options(options \\ []) do |
| 50 | - end |
| 51 | - |
| 52 51 | end |
| @@ -9,7 +9,7 @@ defmodule Sitemap.Mixfile do | |
| 9 9 | [ |
| 10 10 | app: :sitemap, |
| 11 11 | name: "Sitemap", |
| 12 | - version: "0.5.5", |
| 12 | + version: "0.5.6", |
| 13 13 | elixir: ">= 1.0.0", |
| 14 14 | description: @description, |
| 15 15 | build_embedded: Mix.env == :prod, |