Adding the attribute reparto a domicilio to better SEO.

This commit is contained in:
sergiotarxz 2023-05-03 05:30:29 +02:00
parent 6526664dc4
commit 45a3f84987
11 changed files with 135 additions and 30 deletions

View File

@ -9,4 +9,21 @@
<priority>0</priority>
<menu_text>Donde comer</menu_text>
<slug>donde-comer</slug>
<attributes>
<attribute>
<title>Pedir comida a domicilio en Burguillos.</title>
<identifier>reparto-a-domicilio-comida</identifier>
<priority>0</priority>
<menu_text>Listado de sitios de comida con reparto a domicilio.</menu_text>
<description>
<h2>Cartas y Menús de Pizzerías, Hamburgueserías, Kebab, Restaurantes, Bares, etc.</h2>
<p>Te filtramos todos los sitios según si puedes pedir a domicilio en Burguillos, todos
los negocios listados incluyen carta, menú y teléfono de contacto. (O el medio
de contacto pertinente para el negocio en caso de no ser el teléfono.)</p>
<p>¿Conoces algún negocio que debería estar listado aquí? Contacta con <a href="mailto:contact@owlcode.tech">contact@owlcode.tech</a> y lo añadiremos a este registro.</p>
</description>
</attribute>
</attributes>
</category>

View File

@ -7,6 +7,9 @@
<category>donde-comer</category>
<img src="/img/bocaton-preview.png"/>
<slug>el-bocaton</slug>
<attributes>
<attribute>reparto-a-domicilio-comida</attribute>
</attributes>
<content>
<h2>Café - Bar - Pastelería - Pizzeria - Hamburguesería</h2>
<img alt="Exterior del Bar Bocatón." src="/img/bocaton-4.jpg"/>

View File

@ -6,6 +6,9 @@
<last_modification_date>2023-05-03T02:34+02:00</last_modification_date>
<category>donde-comer</category>
<slug>bar-cristobal</slug>
<attributes>
<attribute>reparto-a-domicilio-comida</attribute>
</attributes>
<img src="/img/cristobal-preview.png"/>
<content>
<img alt="Entrada al Mesón - Bar Cristobal." src="/img/cristobal.jpg"/>

View File

@ -7,8 +7,11 @@
<img src="/img/pizzeria-los-naranjos-preview.png"/>
<category>donde-comer</category>
<slug>pizzeria-los-naranjos</slug>
<attributes>
<attribute>reparto-a-domicilio-comida</attribute>
</attributes>
<content>
<h2>Pizzería, Hamburguesería, Kebab, Cartes, Pescado, Aliños.</h2>
<h2>Pizzería, Hamburguesería, Kebab, Pescado, Aliños.</h2>
<img style="border: 1px black solid;" src="/img/pizzeria-los-naranjos.jpg" alt="The front door of the pizzeria"/>
<p>Hoy añadimos a este directorio un clásico en las cenas de los fines
de semana de los habitantes de Burguillos, la Pizzería los Naranjos.</p>

View File

@ -34,9 +34,12 @@ sub startup ($self) {
# $r->get('/:post')->to('Page#post');
$r->get('/stats')->to('Metrics#stats');
$r->get('/<:category>.rss')->to('Page#category_rss');
$r->get('/:category_slug/atributo/:attribute_slug')->to('Attribute#get');
$r->get('/:category')->to('Page#category');
$r->get('/posts/<:slug>-preview.png')->to('Page#get_post_preview');
$r->get('/posts/:slug')->to('Page#post');
$r->get('/filtros')->to('Filter#list');
$r->get('/filtros/:slug')->to('Filter#get');
$r->get('/stats/login')->to('Metrics#login');
$r->post('/stats/login')->to('Metrics#submit_login');
}

View File

@ -40,6 +40,7 @@ sub Retrieve($self) {
or die "Missing menu_text at $category_file";
defined (my $priority = $dom->at(':root > priority')->text)
or die "Missing priority at $category_file";
my $attributes = $self->_GetAttributes($dom, $category_file);
my $parent_tag = $dom->at(':root > parent');
my $parent;
if (defined $parent_tag) {
@ -56,6 +57,7 @@ sub Retrieve($self) {
(parent => $parent) :
()
),
attributes => $attributes,
};
$cached_categories->{$slug} = $category;
}
@ -64,6 +66,34 @@ sub Retrieve($self) {
return $cached_categories;
}
sub _GetAttributes($self, $dom, $category_file) {
my $attributes_tag = $dom->at(':root > attributes');
my %attributes;
if (defined $attributes_tag) {
my @attribute_tag_list = $attributes_tag->find('attributes > attribute')->each;
for my $attribute_tag (@attribute_tag_list) {
defined (my $menu_text = $attribute_tag->at('attribute > menu_text')->content)
or die "Missing attribute menu_text at $category_file";
defined (my $description = $attribute_tag->at('attribute > description')->content)
or die "Missing attribute description at $category_file";
defined (my $title = $attribute_tag->at('attribute > title')->text)
or die "Missing attribute title at $category_file";
defined (my $identifier = $attribute_tag->at('attribute > identifier')->text)
or die "Missing attribute identifier at $category_file";
defined (my $priority = $attribute_tag->at('attribute > priority')->text)
or die "Missing attribute priority at $category_file";
$attributes{$identifier} = {
title => $title,
identifier => $identifier,
priority => $priority,
menu_text => $menu_text,
description => $description,
};
}
}
return \%attributes;
}
sub _PopulateChildrenField($self, $categories) {
for my $category_name (keys %$categories) {
my $category = $categories->{$category_name};

View File

@ -0,0 +1,37 @@
package BurguillosInfo::Controller::Attribute;
use v5.34.1;
use strict;
use warnings;
use Data::Dumper;
use BurguillosInfo::Categories;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub get ($self) {
my $category_slug = $self->param('category_slug');
my $attribute_slug = $self->param('attribute_slug');
my $categories = BurguillosInfo::Categories->new->Retrieve;
my $category = $categories->{$category_slug};
if ( !defined $category ) {
return $self->reply->not_found;
}
my $attribute = $category->{attributes}{$attribute_slug};
if ( !defined $attribute ) {
return $self->reply->not_found;
}
my $posts = BurguillosInfo::Posts->RetrieveDirectPostsForCategory(
$category->{slug} );
$posts = [ grep { defined $_->{attributes}{$attribute_slug} } @$posts ];
$self->render(
template => 'page/attribute',
category => $category,
attribute => $attribute,
categories => $categories,
posts => $posts,
);
}
1;

View File

@ -57,6 +57,7 @@ sub _append_category_dom ( $self, $dom, $category_key, $categories ) {
Mojo::DOM->new_tag( lastmod => $final_date_last_modification_category );
$url->child_nodes->first->append_content($last_modification_tag);
}
$self->_append_attributes_category_sitemap($dom, $category_key, $categories);
my $priority_tag = Mojo::DOM->new_tag( priority => 0.6 );
$url->child_nodes->first->append_content($location_tag);
$url->child_nodes->first->append_content($priority_tag);
@ -64,6 +65,17 @@ sub _append_category_dom ( $self, $dom, $category_key, $categories ) {
$dom->child_nodes->first->append_content($url);
}
sub _append_attributes_category_sitemap($self, $dom, $category_key, $categories) {
my $base_url = $self->config('base_url');
my $category = $categories->{$category_key};
for my $attribute (keys $category->{attributes}->%*) {
my $url = Mojo::DOM->new_tag('url');
my $location_tag = Mojo::DOM->new_tag( loc => "$base_url/$category_key/atributo/$attribute" );
$url->child_nodes->first->append_content($location_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};

View File

@ -83,6 +83,7 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
or die "Missing content at $post_file.";
my $image_element = $dom->at(':root > img');
my $image;
my $attributes = $self->_GetAttributes($post_file, $dom);
if ( defined $image_element ) {
$image = $image_element->attr->{src};
@ -109,9 +110,24 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
: ()
),
( ( defined $image ) ? ( image => $image ) : () ),
attributes => $attributes,
};
}
sub _GetAttributes($self, $post_file, $dom) {
my $attributes_tag = $dom->at(':root > attributes');
my %attributes;
if (defined $attributes_tag) {
my @attribute_list = $attributes_tag->find('attributes > attribute')->map('text')->each;
%attributes = map {
my $identifier = $_;
($identifier => 1);
} @attribute_list;
}
return \%attributes;
}
sub _GeneratePostCache ($self) {
$cached_posts_by_category = {};
$cached_posts_by_slug = {};

View File

@ -28,7 +28,7 @@
<%= content %></body>
<hr/>
<div class="footer description">
<p>©2022 Sergio Iglesias</p>
<p>©2022-2023 Sergio Iglesias</p>
<p>Enterate de todas las novedades de Burguillos.info:</p>
<a class="suscribe-category-rss" href="/all.rss">
<img src="/img/rss.svg" alt="Icono de suscripción rss"/>

View File

@ -12,38 +12,19 @@
<h1><%= $current_category->{title} %></h1>
<%== $current_category->{description} %>
% my $children_categories = $current_category->{children};
% if (@$children_categories) {
% my $attributes = $current_category->{attributes};
% if (@$children_categories || %$attributes) {
<h2>Quizás te interese.</h2>
% for my $child_category (@$children_categories) {
<p><a href="/<%=$child_category->{slug}%>"><%==$child_category->{title}%></a></p>
% }
% for my $attribute_slug (keys %$attributes) {
% my $attribute = $attributes->{$attribute_slug};
<p><a href="<%="/$current_category->{slug}/atributo/$attribute->{identifier}"%>"><%==$attribute->{menu_text}%></a></p>
% }
% }
<h2>Artículos</h2>
<div class="articles">
% my ($category_posts) = BurguillosInfo::Posts->new->RetrieveAllPostsForCategory($current_category->{slug});
% unless (@$category_posts) {
<p>Parece que aun no hay artículos.</p>
% }
% for my $post (@$category_posts) {
<a href="/posts/<%=$post->{slug}%>">
<article><%
my $date_article = DateTime::Format::ISO8601->parse_datetime($post->{date});
$date_article->set_time_zone('Europe/Madrid');
%><p class="date"><%= ''.$date_article %></p><%
if (defined $post->{image}) {
%><img alt="Portada de <%=$post->{title}%>" src="<%=$post->{image}%>"/><%
}
%><h4><%=$post->{title}%></h4><%
my $xml = Mojo::DOM->new($post->{content});
my $text = $xml->all_text;
if (length($text) > 120) {
$text = substr($text, 0, 100).'...';
}
%><p><%=$text%></p><p class="author">Escrito por <%=$post->{author}%></p></article>
</a>
% }
</div>
%= include 'page/_list_posts', posts => $category_posts;
<h2>Suscribete a esta categoría.</h2>
<a class="suscribe-category-rss" href="/<%=$current_category->{slug}%>.rss">