From 45a3f849871206f7668cb6520c5b52b8e753e252 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Wed, 3 May 2023 05:30:29 +0200 Subject: [PATCH] Adding the attribute reparto a domicilio to better SEO. --- content/categories/donde-comer.xml | 17 +++++++++ content/posts/0000012-bar-el-bocaton.xml | 3 ++ content/posts/0000015-meson-bar-cristobal.xml | 3 ++ .../posts/0000021-pizzeria-los-naranjos.xml | 5 ++- lib/BurguillosInfo.pm | 7 +++- lib/BurguillosInfo/Categories.pm | 30 +++++++++++++++ lib/BurguillosInfo/Controller/Attribute.pm | 37 +++++++++++++++++++ lib/BurguillosInfo/Controller/Sitemap.pm | 12 ++++++ lib/BurguillosInfo/Posts.pm | 16 ++++++++ templates/layouts/default.html.ep | 2 +- templates/page/index.html.ep | 33 ++++------------- 11 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 lib/BurguillosInfo/Controller/Attribute.pm diff --git a/content/categories/donde-comer.xml b/content/categories/donde-comer.xml index ee1d7a4..58556d0 100644 --- a/content/categories/donde-comer.xml +++ b/content/categories/donde-comer.xml @@ -9,4 +9,21 @@ 0 Donde comer donde-comer + + + Pedir comida a domicilio en Burguillos. + reparto-a-domicilio-comida + 0 + Listado de sitios de comida con reparto a domicilio. + +

Cartas y Menús de Pizzerías, Hamburgueserías, Kebab, Restaurantes, Bares, etc.

+ +

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.)

+ +

¿Conoces algún negocio que debería estar listado aquí? Contacta con contact@owlcode.tech y lo añadiremos a este registro.

+
+
+
diff --git a/content/posts/0000012-bar-el-bocaton.xml b/content/posts/0000012-bar-el-bocaton.xml index 8f2e239..22b0ec5 100644 --- a/content/posts/0000012-bar-el-bocaton.xml +++ b/content/posts/0000012-bar-el-bocaton.xml @@ -7,6 +7,9 @@ donde-comer el-bocaton + + reparto-a-domicilio-comida +

Café - Bar - Pastelería - Pizzeria - Hamburguesería

Exterior del Bar Bocatón. diff --git a/content/posts/0000015-meson-bar-cristobal.xml b/content/posts/0000015-meson-bar-cristobal.xml index e3d88b6..3de8f21 100644 --- a/content/posts/0000015-meson-bar-cristobal.xml +++ b/content/posts/0000015-meson-bar-cristobal.xml @@ -6,6 +6,9 @@ 2023-05-03T02:34+02:00 donde-comer bar-cristobal + + reparto-a-domicilio-comida + Entrada al Mesón - Bar Cristobal. diff --git a/content/posts/0000021-pizzeria-los-naranjos.xml b/content/posts/0000021-pizzeria-los-naranjos.xml index 3d422f7..a5bc9c5 100644 --- a/content/posts/0000021-pizzeria-los-naranjos.xml +++ b/content/posts/0000021-pizzeria-los-naranjos.xml @@ -7,8 +7,11 @@ donde-comer pizzeria-los-naranjos + + reparto-a-domicilio-comida + -

Pizzería, Hamburguesería, Kebab, Cartes, Pescado, Aliños.

+

Pizzería, Hamburguesería, Kebab, Pescado, Aliños.

The front door of the pizzeria

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.

diff --git a/lib/BurguillosInfo.pm b/lib/BurguillosInfo.pm index f9f4c06..720c647 100644 --- a/lib/BurguillosInfo.pm +++ b/lib/BurguillosInfo.pm @@ -20,8 +20,8 @@ sub startup ($self) { my $config = $self->plugin('JSONConfig'); $self->config( hypnotoad => { proxy => 1, listen => ['http://localhost:3000'] } ); - $self->config(css_version => int(rand(10000))); - $self->secrets($self->config->{secrets}); + $self->config( css_version => int( rand(10000) ) ); + $self->secrets( $self->config->{secrets} ); # Router my $r = $self->routes; @@ -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'); } diff --git a/lib/BurguillosInfo/Categories.pm b/lib/BurguillosInfo/Categories.pm index 8f976cc..e1715d7 100644 --- a/lib/BurguillosInfo/Categories.pm +++ b/lib/BurguillosInfo/Categories.pm @@ -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}; diff --git a/lib/BurguillosInfo/Controller/Attribute.pm b/lib/BurguillosInfo/Controller/Attribute.pm new file mode 100644 index 0000000..8948d31 --- /dev/null +++ b/lib/BurguillosInfo/Controller/Attribute.pm @@ -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; diff --git a/lib/BurguillosInfo/Controller/Sitemap.pm b/lib/BurguillosInfo/Controller/Sitemap.pm index 65888e8..569b19d 100644 --- a/lib/BurguillosInfo/Controller/Sitemap.pm +++ b/lib/BurguillosInfo/Controller/Sitemap.pm @@ -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}; diff --git a/lib/BurguillosInfo/Posts.pm b/lib/BurguillosInfo/Posts.pm index 713a45b..3de5b3c 100644 --- a/lib/BurguillosInfo/Posts.pm +++ b/lib/BurguillosInfo/Posts.pm @@ -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 = {}; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 933a05e..2fe172b 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -28,7 +28,7 @@ <%= content %>