Adding some previews to attributes and categories.

This commit is contained in:
Sergiotarxz 2023-09-17 04:22:28 +02:00
parent a33ba784cd
commit 8dfd3d5197
13 changed files with 138 additions and 88 deletions

View File

@ -5,6 +5,7 @@
<p>¿Quieres que tu comercio aparezca aquí? Contacta con <a href="mailto:contact@owlcode.tech">contact@owlcode.tech</a></p> <p>¿Quieres que tu comercio aparezca aquí? Contacta con <a href="mailto:contact@owlcode.tech">contact@owlcode.tech</a></p>
</description> </description>
<priority>2</priority> <priority>2</priority>
<img src="/img/comercio.webp" bottom-preview="600"/>
<menu_text>Comercios</menu_text> <menu_text>Comercios</menu_text>
<slug>comercios</slug> <slug>comercios</slug>
<random>true</random> <random>true</random>

View File

@ -10,12 +10,14 @@
<priority>0</priority> <priority>0</priority>
<menu_text>Donde comer</menu_text> <menu_text>Donde comer</menu_text>
<slug>donde-comer</slug> <slug>donde-comer</slug>
<img src="/img/donde-comer.webp"/>
<attributes> <attributes>
<attribute> <attribute>
<title>Comida vegana en Burguillos.</title> <title>Comida vegana en Burguillos.</title>
<identifier>comida-vegana</identifier> <identifier>comida-vegana</identifier>
<priority>1</priority> <priority>1</priority>
<menu_text>Listado de sitios que tienen oferta de platos veganos.</menu_text> <menu_text>Listado de sitios que tienen oferta de platos veganos.</menu_text>
<img src="/img/vegano.webp" bottom-preview="400"/>
<description> <description>
<h2>Restaurantes y bares con comida vegana en Burguillos.</h2> <h2>Restaurantes y bares con comida vegana en Burguillos.</h2>
@ -31,6 +33,7 @@
<identifier>reparto-a-domicilio-comida</identifier> <identifier>reparto-a-domicilio-comida</identifier>
<priority>0</priority> <priority>0</priority>
<menu_text>Listado de sitios de comida con reparto a domicilio.</menu_text> <menu_text>Listado de sitios de comida con reparto a domicilio.</menu_text>
<img src="/img/comida-domicilio.webp" bottom-preview="400"/>
<description> <description>
<h2>Cartas y Menús de Pizzerías, Hamburgueserías, Kebab, Restaurantes, Bares, etc.</h2> <h2>Cartas y Menús de Pizzerías, Hamburgueserías, Kebab, Restaurantes, Bares, etc.</h2>
@ -43,6 +46,7 @@
<title>Comer hamburguesas en Burguillos - Cartas y Menús.</title> <title>Comer hamburguesas en Burguillos - Cartas y Menús.</title>
<identifier>hamburguesas</identifier> <identifier>hamburguesas</identifier>
<priority>0</priority> <priority>0</priority>
<img src="/img/hamburguesa.webp" bottom-preview="600"/>
<menu_text>Listado de sitios de comida que preparan hamburguesas.</menu_text> <menu_text>Listado de sitios de comida que preparan hamburguesas.</menu_text>
<description> <description>
<h2>Hamburgueserias y todo tipo de establecimientos que preparan hamburguesas.</h2> <h2>Hamburgueserias y todo tipo de establecimientos que preparan hamburguesas.</h2>

View File

@ -6,10 +6,11 @@
<img alt="The logo of Burguillos.info" src="/img/burguillos-new-logo.svg"/> <img alt="The logo of Burguillos.info" src="/img/burguillos-new-logo.svg"/>
</div> </div>
</div> </div>
<p>Burguillos.info no está afiliado con el Ayuntamiento de Burguillos.</p> <p>Descubre todo lo que Burguillos, Sevilla tiene para ofrecerte.</p>
<p>Esta página está destinada a informar de los sucesos y negocios de nuestro pueblo, cualquiera puede redactar una noticia para que aparezca en este medio mientras pase un proceso de revisión por parte del staff de Burguillos.info.</p> <p>Un mundo de posibilidades a tu alcance en Burguillos.</p>
</description> </description>
<img src="/img/rotonda.webp"/>
<priority>0</priority> <priority>0</priority>
<menu_text><img alt="Principio" class="index-image-menu" src="/img/burguillos-new-logo.svg?v=1"/></menu_text> <menu_text><img alt="Principio" class="index-image-menu" src="/img/burguillos-new-logo.svg?v=1"/></menu_text>
<slug>index</slug> <slug>index</slug>

View File

@ -23,7 +23,7 @@ sub new {
return bless {}, shift; return bless {}, shift;
} }
sub Retrieve($self) { sub Retrieve ($self) {
if ( defined $cached_categories ) { if ( defined $cached_categories ) {
return $cached_categories; return $cached_categories;
} }
@ -32,34 +32,44 @@ sub Retrieve($self) {
warn "Bad file $category_file, omiting...", next warn "Bad file $category_file, omiting...", next
if !-f $category_file || $category_file !~ /\.xml$/; if !-f $category_file || $category_file !~ /\.xml$/;
my $dom = Mojo::DOM->new( $category_file->slurp_utf8 ); my $dom = Mojo::DOM->new( $category_file->slurp_utf8 );
defined(my $title = $dom->at(':root > title')->text) defined( my $title = $dom->at(':root > title')->text )
or die "Missing title at $category_file."; or die "Missing title at $category_file.";
defined(my $description = $dom->at(':root > description')->content) defined( my $description = $dom->at(':root > description')->content )
or die "Missing description at $category_file"; or die "Missing description at $category_file";
defined(my $slug = $dom->at(':root > slug')->text) defined( my $slug = $dom->at(':root > slug')->text )
or die "Missing slug at $category_file"; or die "Missing slug at $category_file";
defined (my $menu_text = $dom->at(':root > menu_text')->content) defined( my $menu_text = $dom->at(':root > menu_text')->content )
or die "Missing menu_text at $category_file"; or die "Missing menu_text at $category_file";
defined (my $priority = $dom->at(':root > priority')->text) defined( my $priority = $dom->at(':root > priority')->text )
or die "Missing priority at $category_file"; or die "Missing priority at $category_file";
my $attributes = $self->_GetAttributes($dom, $category_file); my $attributes = $self->_GetAttributes( $dom, $category_file );
my $parent_tag = $dom->at(':root > parent'); my $parent_tag = $dom->at(':root > parent');
my $random_tag = $dom->at(':root > random'); my $random_tag = $dom->at(':root > random');
my $image_element = $dom->at(':root > img');
my $image;
my $image_bottom_preview;
my $random; my $random;
if (defined $random_tag) {{
if ( defined $random_tag ) {
{
$random = $random_tag->text; $random = $random_tag->text;
if ($random =~ /^true$/i || $random =~ /^yes$/ ) { if ( $random =~ /^true$/i || $random =~ /^yes$/ ) {
$random = 1; $random = 1;
next; next;
} }
if (int($random) != 0) { if ( int($random) != 0 ) {
$random = 1; $random = 1;
next; next;
} }
$random = 0; $random = 0;
}} }
}
if ( defined $image_element ) {
$image = $image_element->attr->{src};
$image_bottom_preview = $image_element->attr->{'bottom-preview'};
}
my $parent; my $parent;
if (defined $parent_tag) { if ( defined $parent_tag ) {
$parent = $parent_tag->content; $parent = $parent_tag->content;
} }
my $category = { my $category = {
@ -69,16 +79,16 @@ sub Retrieve($self) {
description => $description, description => $description,
priority => $priority, priority => $priority,
( (
(defined $parent) ? ( defined $parent ) ? ( parent => $parent )
(parent => $parent) : : ()
()
), ),
attributes => $attributes, attributes => $attributes,
( (
(defined $random) ? ( defined $random ) ? ( random => $random )
(random => $random): : ()
() ),
) image_bottom_preview => $image_bottom_preview,
image => $image,
}; };
$cached_categories->{$slug} = $category; $cached_categories->{$slug} = $category;
} }
@ -87,47 +97,64 @@ sub Retrieve($self) {
return $cached_categories; return $cached_categories;
} }
sub _GetAttributes($self, $dom, $category_file) { sub _GetAttributes ( $self, $dom, $category_file ) {
my $attributes_tag = $dom->at(':root > attributes'); my $attributes_tag = $dom->at(':root > attributes');
my %attributes; my %attributes;
if (defined $attributes_tag) { if ( defined $attributes_tag ) {
my @attribute_tag_list = $attributes_tag->find('attributes > attribute')->each; my @attribute_tag_list =
$attributes_tag->find('attributes > attribute')->each;
for my $attribute_tag (@attribute_tag_list) { for my $attribute_tag (@attribute_tag_list) {
defined (my $menu_text = $attribute_tag->at('attribute > menu_text')->content) defined( my $menu_text =
$attribute_tag->at('attribute > menu_text')->content )
or die "Missing attribute menu_text at $category_file"; or die "Missing attribute menu_text at $category_file";
defined (my $description = $attribute_tag->at('attribute > description')->content) defined( my $description =
$attribute_tag->at('attribute > description')->content )
or die "Missing attribute description at $category_file"; or die "Missing attribute description at $category_file";
defined (my $title = $attribute_tag->at('attribute > title')->text) defined( my $title = $attribute_tag->at('attribute > title')->text )
or die "Missing attribute title at $category_file"; or die "Missing attribute title at $category_file";
defined (my $identifier = $attribute_tag->at('attribute > identifier')->text) defined( my $identifier =
$attribute_tag->at('attribute > identifier')->text )
or die "Missing attribute identifier at $category_file"; or die "Missing attribute identifier at $category_file";
defined (my $priority = $attribute_tag->at('attribute > priority')->text) defined( my $priority =
$attribute_tag->at('attribute > priority')->text )
or die "Missing attribute priority at $category_file"; or die "Missing attribute priority at $category_file";
my $image_element = $attribute_tag->at('attribute > img');
my $image;
my $image_bottom_preview;
if ( defined $image_element ) {
$image = $image_element->attr->{src};
$image_bottom_preview =
$image_element->attr->{'bottom-preview'};
}
$attributes{$identifier} = { $attributes{$identifier} = {
title => $title, title => $title,
identifier => $identifier, identifier => $identifier,
priority => $priority, priority => $priority,
menu_text => $menu_text, menu_text => $menu_text,
description => $description, description => $description,
image => $image,
image_bottom_preview => $image_bottom_preview,
}; };
} }
} }
return \%attributes; return \%attributes;
} }
sub _PopulateChildrenField($self, $categories) { sub _PopulateChildrenField ( $self, $categories ) {
for my $category_name (keys %$categories) { for my $category_name ( keys %$categories ) {
my $category = $categories->{$category_name}; my $category = $categories->{$category_name};
$category->{children} //= []; $category->{children} //= [];
my $parent_name = $category->{parent}; my $parent_name = $category->{parent};
if (!defined $parent_name) { if ( !defined $parent_name ) {
next; next;
} }
my $parent = $categories->{$parent_name}; my $parent = $categories->{$parent_name};
if (!defined $parent) { if ( !defined $parent ) {
die "Category $parent_name not exists and it is the parent of $category_name."; die
"Category $parent_name not exists and it is the parent of $category_name.";
} }
if (!exists $category->{random} && exists $parent->{random}) { if ( !exists $category->{random} && exists $parent->{random} ) {
$category->{random} = $parent->{random}; $category->{random} = $parent->{random};
} }
$parent->{children} //= []; $parent->{children} //= [];
@ -135,19 +162,23 @@ sub _PopulateChildrenField($self, $categories) {
} }
} }
sub _AvoidGrandChildCategories($self, $categories) { sub _AvoidGrandChildCategories ( $self, $categories ) {
for my $category_slug (keys %$categories) { for my $category_slug ( keys %$categories ) {
my $category = $categories->{$category_slug}; my $category = $categories->{$category_slug};
my $parent = $category->{parent}; my $parent = $category->{parent};
if (defined $parent && defined $categories->{$parent}{parent}) { if ( defined $parent && defined $categories->{$parent}{parent} ) {
die "$category_slug category is grandchild of $categories->{$parent}{parent}) category and this is not allowed."; die
"$category_slug category is grandchild of $categories->{$parent}{parent}) category and this is not allowed.";
} }
} }
} }
sub PreviewOg($self, $category) { sub PreviewOg ( $self, $category ) {
my $title = $category->{title}; my $title = $category->{title};
my $description = $category->{description}; my $description = $category->{description};
return BurguillosInfo::Preview->Generate($title, $description, undef); my $image = $category->{image};
my $image_bottom_preview = $category->{image_bottom_preview};
return BurguillosInfo::Preview->Generate( $title, $description, $image,
$image_bottom_preview );
} }
1; 1;

View File

@ -50,15 +50,21 @@ sub _index_categories ( $self, $index, $categories ) {
->all_text; ->all_text;
my $title = $category->{title}; my $title = $category->{title};
my $attributes = $category->{attributes}; my $attributes = $category->{attributes};
my $image = $category->{image};
$self->_index_attributes( $index, $slug, $attributes ); $self->_index_attributes( $index, $slug, $attributes );
push @$index, push @$index, {
{
title => $title, title => $title,
titleNormalized => $index_utils->n($title), titleNormalized => $index_utils->n($title),
content => $content, content => $content,
contentNormalized => $index_utils->n( $content =~ s/\s+/ /gr ), contentNormalized => $index_utils->n( $content =~ s/\s+/ /gr ),
url => $url, url => $url,
urlNormalized => $index_utils->n($url), urlNormalized => $index_utils->n($url),
(
( defined $image )
? ( urlImage => $image )
: ()
)
}; };
} }
} }
@ -70,6 +76,7 @@ sub _index_attributes ( $self, $index, $category_slug, $attributes ) {
my $slug = $attribute->{identifier}; my $slug = $attribute->{identifier};
my $url = "/$category_slug/atributo/$slug"; my $url = "/$category_slug/atributo/$slug";
my $title = $attribute->{title}; my $title = $attribute->{title};
my $image = $attribute->{image};
my $content = my $content =
Mojo::DOM->new( '<html>' . $attribute->{description} . '</html>' ) Mojo::DOM->new( '<html>' . $attribute->{description} . '</html>' )
->all_text; ->all_text;
@ -81,6 +88,11 @@ sub _index_attributes ( $self, $index, $category_slug, $attributes ) {
content => $content =~ s/\s+/ /gr, content => $content =~ s/\s+/ /gr,
urlNormalized => $index_utils->n($url), urlNormalized => $index_utils->n($url),
url => $url, url => $url,
(
( defined $image )
? ( urlImage => $image )
: ()
)
}; };
} }
} }

View File

@ -28,7 +28,8 @@ sub get_attribute_preview ($self) {
$self->render( $self->render(
format => 'png', format => 'png',
data => BurguillosInfo::Preview->Generate( data => BurguillosInfo::Preview->Generate(
$attribute->{title}, $attribute->{description}, undef $attribute->{title}, $attribute->{description},
$attribute->{image}, $attribute->{image_bottom_preview}
), ),
); );
} }

View File

@ -23,7 +23,7 @@ const my $SVG_HEIGHT => 627;
const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1200; const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1200;
const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 400; const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 400;
sub Generate($self, $title, $content, $image_file, $image_bottom_preview) { sub Generate($self, $title, $content, $image_file = undef, $image_bottom_preview = undef) {
my $dom = Mojo::DOM->new($content); my $dom = Mojo::DOM->new($content);
$content = $dom->all_text; $content = $dom->all_text;

BIN
public/img/comercio.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
public/img/donde-comer.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
public/img/hamburguesa.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
public/img/rotonda.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 KiB

BIN
public/img/vegano.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB