Pretty printing sitemap.xml

This commit is contained in:
sergiotarxz 2023-05-02 16:49:00 +02:00
parent d195e26842
commit 423e813490
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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 ) {