Current section
36 Versions
Jump to
Current section
36 Versions
Compare versions
8
files changed
+52
additions
-7
deletions
| @@ -477,6 +477,21 @@ end | |
| 477 477 | Look at [PageMap sitemap](https://developers.google.com/custom-search/docs/structured_data#addtositemaps) as required. |
| 478 478 | |
| 479 479 | |
| 480 | + ### Additional links into the Sitemap Index |
| 481 | + |
| 482 | + |
| 483 | + ```elixir |
| 484 | + create do |
| 485 | + add_to_index "/mysitemap1.xml.gz" |
| 486 | + add_to_index "/alternatemap.xml" |
| 487 | + add_to_index "/changehost.xml.gz", host: "http://example.com" |
| 488 | + |
| 489 | + add ... |
| 490 | + add .... |
| 491 | + end |
| 492 | + ``` |
| 493 | + |
| 494 | + |
| 480 495 | ### Known issue |
| 481 496 | |
| 482 497 | - [Compilation error with ** (EXIT) no process](https://github.com/ikeikeikeike/sitemap/issues/5#issue-200979852) |
| @@ -23,4 +23,4 @@ | |
| 23 23 | {<<"name">>,<<"xml_builder">>}, |
| 24 24 | {<<"optional">>,false}, |
| 25 25 | {<<"requirement">>,<<">= 0.0.0">>}]]}. |
| 26 | - {<<"version">>,<<"0.8.1">>}. |
| 26 | + {<<"version">>,<<"0.8.2">>}. |
| @@ -23,6 +23,16 @@ defmodule Sitemap.Builders.Indexfile do | |
| 23 23 | incr_state :total_count, FileBuilder.state.link_count |
| 24 24 | end |
| 25 25 | |
| 26 | + def add(link, options) do |
| 27 | + content = |
| 28 | + Indexurl.to_xml(Location.url(link), options) |
| 29 | + |> XmlBuilder.generate |
| 30 | + |
| 31 | + # TODO: Count-Up sitemap line. |
| 32 | + |
| 33 | + add_state :content, content |
| 34 | + end |
| 35 | + |
| 26 36 | def write do |
| 27 37 | s = state() |
| 28 38 | content = Consts.xml_idxheader <> s.content <> Consts.xml_idxfooter |
| @@ -4,7 +4,7 @@ defmodule Sitemap.Builders.Indexurl do | |
| 4 4 | |
| 5 5 | def to_xml(link, opts \\ []) do |
| 6 6 | element(:sitemap, Funcs.eraser([ |
| 7 | - element(:loc, link), |
| 7 | + element(:loc, if(opts[:host], do: Funcs.urljoin(link, opts[:host]), else: link)), |
| 8 8 | element(:lastmod, Keyword.get_lazy(opts, :lastmod, fn -> Funcs.iso8601 end)) |
| 9 9 | ])) |
| 10 10 | end |
| @@ -61,4 +61,17 @@ defmodule Sitemap.Funcs do | |
| 61 61 | end |
| 62 62 | end |
| 63 63 | |
| 64 | + def urljoin(src, dest) do |
| 65 | + {s, d} = {URI.parse(src), URI.parse(dest)} |
| 66 | + to_string struct(s, [ |
| 67 | + authority: d.authority || s.authority, |
| 68 | + fragment: d.fragment || s.fragment, |
| 69 | + host: d.host || s.host, |
| 70 | + path: d.path || s.path, |
| 71 | + port: d.port || s.port, |
| 72 | + query: d.query || s.query, |
| 73 | + scheme: d.scheme || s.scheme, |
| 74 | + userinfo: d.userinfo || s.userinfo, |
| 75 | + ]) |
| 76 | + end |
| 64 77 | end |
Loading more files…