diff --git a/Build.PL b/Build.PL index 2f0539c..20df077 100755 --- a/Build.PL +++ b/Build.PL @@ -18,6 +18,7 @@ my $build = Module::Build->new( 'DateTime::Format::ISO8601.pm' => 0, 'DateTime::Format::Mail.pm' => 0, 'SVG' => 0, + 'XML::LibXML::PrettyPrint' => 0, }, ); $build->create_build_script; diff --git a/lib/BurguillosInfo/Controller/Sitemap.pm b/lib/BurguillosInfo/Controller/Sitemap.pm index ad4ccf7..7f8d6fd 100644 --- a/lib/BurguillosInfo/Controller/Sitemap.pm +++ b/lib/BurguillosInfo/Controller/Sitemap.pm @@ -10,6 +10,9 @@ use BurguillosInfo::Posts; use DateTime::Format::ISO8601; +use XML::LibXML; +use XML::LibXML::PrettyPrint; + use Mojo::Base 'Mojolicious::Controller', '-signatures'; sub sitemap ($self) { @@ -23,7 +26,12 @@ sub sitemap ($self) { for my $category_key ( keys %$categories ) { $self->_append_category_dom( $dom, $category_key, $categories ); } - $self->render(text => $dom, format => 'xml'); + my $xml_string = "$dom"; + my $document = XML::LibXML->load_xml(string => $xml_string); + my $pretty_print = XML::LibXML::PrettyPrint->new(indent_string => (" " x 4)); + $pretty_print->pretty_print($document); + $xml_string = $document->toString(); + $self->render(text => $xml_string, format => 'xml'); } sub _append_category_dom ( $self, $dom, $category_key, $categories ) {