Current section

36 Versions

Jump to

Compare versions

5 files changed
+135 additions
-30 deletions
  @@ -12,7 +12,6 @@ Generating sitemap.xml
12 12
13 13 ## Installation
14 14
15 - `Still developing.`
16 15
17 16 If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
18 17
  @@ -65,7 +64,7 @@ defmodule Sitemaps do
65 64 end
66 65 ```
67 66
68 - ###### With Ecto
67 + ###### With Phoenix
69 68
70 69 ```elixir
71 70 defmodule Sitemaps do
  @@ -77,16 +76,13 @@ defmodule Sitemaps do
77 76 alias MyApp.Router.Helpers
78 77
79 78 create do
80 - entries =
81 - MyApp.Entry
82 - |> MyApp.Repo.all
79 + entries = MyApp.Repo.all MyApp.Entry
83 80
84 81 Enum.each [false, true], fn bool ->
85 82 add Helpers.entry_path(MyApp.Endpoint, :index),
86 83 priority: 0.5, changefreq: "hourly", expires: nil, mobile: bool
87 84
88 - entries
89 - |> Enum.each(fn entry ->
85 + Enum.each(entries, fn entry ->
90 86 add Helpers.entry_path(MyApp.Endpoint, :show, entry.id, entry.title),
91 87 priority: 0.5, changefreq: "hourly", expires: nil, mobile: bool
92 88 end)
  @@ -106,7 +102,7 @@ end
106 102
107 103 ```elixir
108 104 defmodule Sitemaps do
109 - use Sitemap, compress: false, create_index: true
105 + use Sitemap, compress: false, host: "http://example.com"
110 106
111 107 create do
112 108 add "path1", priority: 0.5, changefreq: "hourly"
  @@ -124,7 +120,7 @@ end
124 120 defmodule Sitemaps do
125 121 use Sitemap
126 122
127 - create compress: false, create_index: true do
123 + create compress: false, host: "http://example.com" do
128 124 add "path1", priority: 0.5, changefreq: "hourly"
129 125 add "path2", priority: 0.5, changefreq: "hourly"
130 126 end
  @@ -137,13 +133,13 @@ end
137 133
138 134 Current Features or To-Do
139 135
140 - - [x] Supports: generate kind of some sitemaps.
141 - - [x] News sitemaps
142 - - [x] Video sitemaps
143 - - [x] Image sitemaps
144 - - [x] Geo sitemaps
145 - - [x] Mobile sitemaps
146 - - [x] PageMap sitemap
136 + - [x] [Supports: generate kind of some sitemaps](#supports-generate-kind-of-some-sitemaps)
137 + - [x] [News Sitemaps](#news-sitemaps)
138 + - [x] Video Sitemaps
139 + - [x] Image Sitemaps
140 + - [x] Geo Sitemaps
141 + - [x] Mobile Sitemaps
142 + - [x] PageMap Sitemap
147 143 - [x] Alternate Links
148 144 - [ ] Supports: write some kind of filesystem and object storage.
149 145 - [x] Filesystem
  @@ -154,3 +150,99 @@ Current Features or To-Do
154 150 - [x] Customizable sitemap compression
155 151 - [ ] Intelligent sitemap indexing
156 152 - [ ] All of completing Examples
153 +
154 +
155 +
156 + ## Supports: generate kind of some sitemaps
157 +
158 +
159 + ### News Sitemaps
160 +
161 + ```elixir
162 + defmodule Sitemaps do
163 + use Sitemap, compress: false, host: "http://example.com"
164 +
165 + create do
166 + add "index.html", news: [
167 + publication_name: "Example",
168 + publication_language: "en",
169 + title: "My Article",
170 + keywords: "my article, articles about myself",
171 + stock_tickers: "SAO:PETR3",
172 + publication_date: "2011-08-22",
173 + access: "Subscription",
174 + genres: "PressRelease"
175 + ]
176 + end
177 + end
178 + ```
179 +
180 + ###### Generated Result
181 +
182 + ```xml
183 + <url>
184 + <loc>http://www.example.com/index.html</loc>
185 + <lastmod>2016-05-30T13:13:12Z</lastmod>
186 + <news:news>
187 + <news:publication>
188 + <news:name>Example</news:name>
189 + <news:language>en</news:language>
190 + </news:publication>
191 + <news:title>My Article</news:title>
192 + <news:access>Subscription</news:access>
193 + <news:genres>PressRelease</news:genres>
194 + <news:keywords>my article, articles about myself</news:keywords>
195 + <news:stock_tickers>SAO:PETR3</news:stock_tickers>
196 + <news:publication_date>2011-08-22</news:publication_date>
197 + </news:news>
198 + </url>
199 + ```
200 +
201 + Look at [Creating a Google News Sitemap](https://support.google.com/news/publisher/answer/74288) as required.
202 +
203 + ### Video sitemaps
204 +
205 + ```elixir
206 + defmodule Sitemaps do
207 + use Sitemap, compress: true, host: "http://example.com"
208 +
209 + create do
210 + add "index.html", videos: [
211 + thumbnail_loc: "Example",
212 + publication_language: "http://www.example.com/video1_thumbnail.png",
213 + title: "My Video",
214 + description: "my video, videos about itself",
215 + content_loc: "http://www.example.com/cool_video.mpg",
216 + tags: ~w(and then nothing),
217 + category: "Category"
218 + ]
219 + end
220 + end
221 +
222 + ```
223 +
224 + ###### Generated Result
225 +
226 + ```xml
227 + <url>
228 + <loc>http://www.example.com/video.html</loc>
229 + <lastmod>2016-05-30T14:53:00Z</lastmod>
230 + <video:video>
231 + <video:title>Grilling steaks for summer</video:title>
232 + <video:description>Alkis shows you how to get perfectly done steaks every time</video:description>
233 + <video:rating>0.5</video:rating>
234 + <video:duration>600</video:duration>
235 + <video:view_count>1000</video:view_count>
236 + <video:expiration_date>2009-11-05T19:20:30+08:00</video:expiration_date>
237 + <video:publication_date>2007-11-05T19:20:30+08:00</video:publication_date>
238 + <video:tag>tag1</video:tag>
239 + <video:tag>tag2</video:tag>
240 + <video:tag>tag3</video:tag>
241 + <video:tag>tag4</video:tag>
242 + <video:category>Category</video:category>
243 + <video:family_friendly>yes</video:family_friendly>
244 + </video:video>
245 + </url>
246 + ```
247 +
248 + Look at [Video sitemaps](https://support.google.com/webmasters/answer/80471) as required.
  @@ -23,4 +23,4 @@
23 23 [{<<"app">>,<<"xml_builder">>},
24 24 {<<"optional">>,false},
25 25 {<<"requirement">>,<<">= 0.0.0">>}]}]}.
26 - {<<"version">>,<<"0.6.0">>}.
26 + {<<"version">>,<<"0.6.1">>}.
  @@ -70,31 +70,31 @@ defmodule Sitemap.Builders.Url do
70 70 element(:"video:title", data[:title]),
71 71 element(:"video:description", data[:description]),
72 72
73 - # TODO: Elase nil when this statement returns that.
74 73 (if data[:player_loc] do
75 - attrs = %{allow_embed: data[:allow_embed]}
76 - if data[:autoplay], do: attrs = Map.put(attrs, :autoplay, data[:autoplay])
74 + attrs = %{allow_embed: Funcs.yes_no(data[:allow_embed])}
75 + if data[:autoplay], do: attrs = Map.put(attrs, :autoplay, Funcs.autoplay(data[:autoplay]))
77 76 element(:"video:player_loc", attrs, data[:player_loc])
78 77 end),
79 - element(:"video:content_loc", data[:content_loc]),
80 - element(:"video:thumbnail_loc", data[:thumbnail_loc]),
81 - element(:"video:gallery_loc", %{title: data[:gallery_title]}, data[:gallery_loc]),
78 + # element(:"video:content_loc", data[:content_loc]),
79 + # element(:"video:thumbnail_loc", data[:thumbnail_loc]),
80 + # element(:"video:gallery_loc", %{title: data[:gallery_title]}, data[:gallery_loc]),
82 81
83 - element(:"video:price", video_price_attrs(data), data[:price]),
82 + # element(:"video:price", video_price_attrs(data), data[:price]),
84 83 element(:"video:rating", data[:rating]),
85 84 element(:"video:duration", data[:duration]),
86 85 element(:"video:view_count", data[:view_count]),
87 86
88 - element(:"video:expiration_date", data[:expiration_date]),
89 - element(:"video:publication_date",data[:publication_date]),
87 + element(:"video:expiration_date", data[:expiration_date]), # TODO: gonna be convinient
88 + element(:"video:publication_date",data[:publication_date]), # TODO: gonna be convinient
90 89
91 90 Enum.map(data[:tags] || [], &(element(:"video:tag", &1))),
92 91 element(:"video:tag", data[:tag]),
93 92 element(:"video:category", data[:category]),
94 93
95 - element(:"video:family_friendly", data[:family_friendly]),
94 + (if Keyword.has_key?(data, :family_friendly) do
95 + element(:"video:family_friendly", Funcs.yes_no(data[:family_friendly]))
96 + end),
96 97
97 - # TODO: Elase nil when this statement returns that.
98 98 (if data[:uploader] do
99 99 attrs = %{}
100 100 if data[:uploader_info], do: attrs = %{info: data[:uploader_info]}
  @@ -11,7 +11,20 @@ defmodule Sitemap.Funcs do
11 11
12 12 def eraser(elements) do
13 13 Enum.filter elements, fn elm ->
14 - !!elem(elm, 2)
14 + case elm do
15 + e when is_list(e) -> eraser(e)
16 + nil -> false
17 + _ -> !!elem(elm, 2)
18 + end
15 19 end
16 20 end
21 +
22 + def yes_no(bool) do
23 + if bool == false, do: "no", else: "yes"
24 + end
25 +
26 + def autoplay(bool) do
27 + if bool, do: "ap=1", else: "ap=0"
28 + end
29 +
17 30 end
  @@ -9,7 +9,7 @@ defmodule Sitemap.Mixfile do
9 9 [
10 10 app: :sitemap,
11 11 name: "Sitemap",
12 - version: "0.6.0",
12 + version: "0.6.1",
13 13 elixir: ">= 1.0.0",
14 14 description: @description,
15 15 build_embedded: Mix.env == :prod,