Adding sitemap and deleting images from the el bocaton.
This commit is contained in:
parent
8c617bed1d
commit
82d0427424
@ -3,5 +3,6 @@
|
|||||||
"bcrypt_pass_stats": ["change_for_bcrypted_password"],
|
"bcrypt_pass_stats": ["change_for_bcrypted_password"],
|
||||||
"db": {
|
"db": {
|
||||||
"database": "example"
|
"database": "example"
|
||||||
}
|
},
|
||||||
|
"base_url": "https://burguillos.info"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<post>
|
<post>
|
||||||
<author>Burguillos.info</author>
|
<author>Burguillos.info</author>
|
||||||
<date>2022-11-18T00:00+00:00</date>
|
<date>2022-11-18T00:00+00:00</date>
|
||||||
|
<last_modification_date>2023-05-02T00:00+00:00</last_modification_date>
|
||||||
<title>El Bocatón - Café - Bar - Pastelería - Pizzeria - Hamburguesería.</title>
|
<title>El Bocatón - Café - Bar - Pastelería - Pizzeria - Hamburguesería.</title>
|
||||||
<ogdesc>El Bocatón - Café - Bar - Pastelería - Pizzeria - Hamburguesería.</ogdesc>
|
<ogdesc>El Bocatón - Café - Bar - Pastelería - Pizzeria - Hamburguesería.</ogdesc>
|
||||||
<category>comercios</category>
|
<category>comercios</category>
|
||||||
@ -130,9 +131,5 @@
|
|||||||
|
|
||||||
<p>Aprovechamos este espacio final tras terminar de listar el menú para adjuntaros más imágenes del local y desearos una feliz comida.</p>
|
<p>Aprovechamos este espacio final tras terminar de listar el menú para adjuntaros más imágenes del local y desearos una feliz comida.</p>
|
||||||
|
|
||||||
<img alt="Exterior del Bar Bocatón." src="/img/bocaton-1.jpg"/>
|
|
||||||
<img alt="Exterior del Bar Bocatón." src="/img/bocaton-2.jpg"/>
|
|
||||||
<img alt="Exterior del Bar Bocatón." src="/img/bocaton-3.jpg"/>
|
|
||||||
|
|
||||||
</content>
|
</content>
|
||||||
</post>
|
</post>
|
||||||
|
@ -28,6 +28,7 @@ sub startup ($self) {
|
|||||||
|
|
||||||
# Normal route to controller
|
# Normal route to controller
|
||||||
$r->get('/')->to('Page#index');
|
$r->get('/')->to('Page#index');
|
||||||
|
$r->get('/sitemap.xml')->to('Sitemap#sitemap');
|
||||||
|
|
||||||
# $r->get('/:post')->to('Page#post');
|
# $r->get('/:post')->to('Page#post');
|
||||||
$r->get('/stats')->to('Metrics#stats');
|
$r->get('/stats')->to('Metrics#stats');
|
||||||
|
111
lib/BurguillosInfo/Controller/Sitemap.pm
Normal file
111
lib/BurguillosInfo/Controller/Sitemap.pm
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package BurguillosInfo::Controller::Sitemap;
|
||||||
|
|
||||||
|
use v5.34.1;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use BurguillosInfo::Categories;
|
||||||
|
use BurguillosInfo::Posts;
|
||||||
|
|
||||||
|
use DateTime::Format::ISO8601;
|
||||||
|
|
||||||
|
use Mojo::Base 'Mojolicious::Controller', '-signatures';
|
||||||
|
|
||||||
|
sub sitemap ($self) {
|
||||||
|
my $categories = BurguillosInfo::Categories->new->Retrieve;
|
||||||
|
my $dom = Mojo::DOM->new_tag(
|
||||||
|
'urlset',
|
||||||
|
xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9',
|
||||||
|
undef
|
||||||
|
);
|
||||||
|
$dom->xml(1);
|
||||||
|
for my $category_key ( keys %$categories ) {
|
||||||
|
$self->_append_category_dom( $dom, $category_key, $categories );
|
||||||
|
}
|
||||||
|
$self->render(text => $dom, format => 'xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _append_category_dom ( $self, $dom, $category_key, $categories ) {
|
||||||
|
my $category = $categories->{$category_key};
|
||||||
|
my $slug = $category->{'slug'};
|
||||||
|
my $date_publish_category;
|
||||||
|
my $date_last_modification_category;
|
||||||
|
|
||||||
|
my ( $posts_categories, $posts_slug ) =
|
||||||
|
BurguillosInfo::Posts->new->Retrieve;
|
||||||
|
for my $post ( $posts_categories->{$category_key}->@* ) {
|
||||||
|
( $date_publish_category, $date_last_modification_category ) =
|
||||||
|
_get_dates_for_category( $date_publish_category,
|
||||||
|
$date_last_modification_category, $post );
|
||||||
|
my $url_post = $self->_generate_url_for_post($post);
|
||||||
|
$dom->child_nodes->first->append_content($url_post);
|
||||||
|
}
|
||||||
|
my $url = Mojo::DOM->new_tag('url');
|
||||||
|
my $base_url = $self->config('base_url');
|
||||||
|
my $location_tag = Mojo::DOM->new_tag( loc => "$base_url/$slug" );
|
||||||
|
my $final_date_last_modification_category =
|
||||||
|
_compare_dates_return_most_recent( $date_publish_category,
|
||||||
|
$date_last_modification_category );
|
||||||
|
my $last_modification_tag =
|
||||||
|
Mojo::DOM->new_tag( lastmod => $final_date_last_modification_category );
|
||||||
|
my $priority_tag = Mojo::DOM->new_tag( priority => 0.6 );
|
||||||
|
$url->child_nodes->first->append_content($location_tag);
|
||||||
|
$url->child_nodes->first->append_content($last_modification_tag);
|
||||||
|
$url->child_nodes->first->append_content($priority_tag);
|
||||||
|
|
||||||
|
$dom->child_nodes->first->append_content($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _generate_url_for_post ( $self, $post ) {
|
||||||
|
my $url_tag = Mojo::DOM->new_tag('url');
|
||||||
|
my $date = $post->{date};
|
||||||
|
my $date_last_modification_post = $post->{last_modification_date};
|
||||||
|
my $final_date_last_modification_post =
|
||||||
|
_compare_dates_return_most_recent( $date, $date_last_modification_post );
|
||||||
|
my $base_url = $self->config('base_url');
|
||||||
|
my $url_resource = "$base_url/@{[$post->{slug}]}";
|
||||||
|
my $last_modification_tag =
|
||||||
|
Mojo::DOM->new_tag( lastmod => $final_date_last_modification_post );
|
||||||
|
my $location_tag = Mojo::DOM->new_tag( loc => $url_resource );
|
||||||
|
$url_tag->child_nodes->first->append_content($location_tag);
|
||||||
|
$url_tag->child_nodes->first->append_content($last_modification_tag);
|
||||||
|
return $url_tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $error_no_dates = "Undefined dates";
|
||||||
|
|
||||||
|
sub _get_dates_for_category ( $current_date_publish,
|
||||||
|
$current_date_modification, $post )
|
||||||
|
{
|
||||||
|
my @return_list;
|
||||||
|
@return_list = (
|
||||||
|
_compare_dates_return_most_recent(
|
||||||
|
$current_date_publish, $post->{date}
|
||||||
|
),
|
||||||
|
_compare_dates_return_most_recent(
|
||||||
|
$current_date_publish, $post->{last_modification_date}
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return @return_list;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _compare_dates_return_most_recent ( $date_a, $date_b ) {
|
||||||
|
if ( !defined $date_a && !defined $date_b ) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
if ( !defined $date_a ) {
|
||||||
|
return $date_b;
|
||||||
|
}
|
||||||
|
if ( !defined $date_b ) {
|
||||||
|
return $date_a;
|
||||||
|
}
|
||||||
|
my $date_a_dt = DateTime::Format::ISO8601->parse_datetime($date_a);
|
||||||
|
my $date_b_dt = DateTime::Format::ISO8601->parse_datetime($date_b);
|
||||||
|
if ( $date_a_dt >= $date_b_dt ) {
|
||||||
|
return $date_a;
|
||||||
|
}
|
||||||
|
return $date_b;
|
||||||
|
}
|
||||||
|
1;
|
@ -85,14 +85,22 @@ sub Retrieve {
|
|||||||
$image = $image_element->attr->{src};
|
$image = $image_element->attr->{src};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $last_modification_date_element =
|
||||||
|
$dom->at(':root > last_modification_date');
|
||||||
|
my $last_modification_date;
|
||||||
|
if ( defined $last_modification_date_element ) {
|
||||||
|
$last_modification_date = $last_modification_date_element->content;
|
||||||
|
}
|
||||||
|
|
||||||
my $post = {
|
my $post = {
|
||||||
title => $title,
|
title => $title,
|
||||||
author => $author,
|
author => $author,
|
||||||
date => $date,
|
date => $date,
|
||||||
ogdesc => $ogdesc,
|
ogdesc => $ogdesc,
|
||||||
category => $category,
|
category => $category,
|
||||||
slug => $slug,
|
slug => $slug,
|
||||||
content => $content,
|
content => $content,
|
||||||
|
( (defined $last_modification_date) ? (last_modification_date => $last_modification_date) : () ),
|
||||||
( ( defined $image ) ? ( image => $image ) : () ),
|
( ( defined $image ) ? ( image => $image ) : () ),
|
||||||
};
|
};
|
||||||
$cached_posts_by_category->{$category} //= [];
|
$cached_posts_by_category->{$category} //= [];
|
||||||
@ -136,7 +144,7 @@ sub PostPreviewOg {
|
|||||||
$self->_GenerateSVGPostPreview( $title, \@new_content, $post->{image} );
|
$self->_GenerateSVGPostPreview( $title, \@new_content, $post->{image} );
|
||||||
my ( $stdout, $stderr ) = capture {
|
my ( $stdout, $stderr ) = capture {
|
||||||
open my $fh, '|-', qw{convert /dev/stdin png:fd:1};
|
open my $fh, '|-', qw{convert /dev/stdin png:fd:1};
|
||||||
binmode $fh, 'utf8';
|
binmode $fh, 'utf8';
|
||||||
print $fh $svg;
|
print $fh $svg;
|
||||||
close $fh;
|
close $fh;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user