Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google requires an xmlns for PageMap #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/sitemap/builders/url.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Sitemap.Builders.Url do
alias Sitemap.Funcs
alias Sitemap.Config
alias Sitemap.Consts
import XmlBuilder

def to_xml(link, attrs \\ []) do
Expand Down Expand Up @@ -201,6 +202,7 @@ defmodule Sitemap.Builders.Url do
defp pagemap(data) do
element(
:PageMap,
%{xmlns: Consts.schemas.pagemap},
Enum.map(data[:dataobjects] || [], fn obj ->
element(
:DataObject,
Expand Down
4 changes: 4 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Sitemap.Mixfile do
name: "Sitemap",
version: "1.1.0",
elixir: ">= 1.3.0",
elixirc_paths: elixirc_paths(Mix.env()),
description: @description,
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
Expand All @@ -20,6 +21,9 @@ defmodule Sitemap.Mixfile do
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
Expand Down
2 changes: 2 additions & 0 deletions test/sitemap/builders_url_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Sitemap.BuildersUrlTest do

alias Sitemap.Builders.Url
import SweetXml
import Sitemap.XpathNamespace
require XmlBuilder

setup do
Expand Down Expand Up @@ -498,6 +499,7 @@ defmodule Sitemap.BuildersUrlTest do
assert xpath(parsed, ~x"//PageMap/DataObject/@type") == 'document'
assert xpath(parsed, ~x"//PageMap/DataObject/Attribute/text()") == 'Dragon'
assert xpath(parsed, ~x"//PageMap/DataObject/Attribute/@name") == 'name'
assert xpath_namespace(parsed, ~x"//PageMap") == Sitemap.Consts.schemas.pagemap
end

test "date and datetime convert to iso8601" do
Expand Down
13 changes: 13 additions & 0 deletions test/support/xpath_namespace.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Sitemap.XpathNamespace do
import SweetXml

def xpath_namespace(parsed, spec) do
parsed
|> xpath(spec)
|> xpath(~x"//namespace::*[name()='']")
|> case do
{_, _, _, _, namespace} -> to_string(namespace)
_ -> nil
end
end
end