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>
</description>
<priority>2</priority>
<img src="/img/comercio.webp" bottom-preview="600"/>
<menu_text>Comercios</menu_text>
<slug>comercios</slug>
<random>true</random>

View File

@ -1,21 +1,23 @@
<category>
<title>Donde comer en Burguillos. - Cartas y Menús.</title>
<description>
<title>Donde comer en Burguillos. - Cartas y Menús.</title>
<description>
<h2>Descubre los bares y restaurantes de Burguillos con sus cartas, menús y datos de contacto.</h2>
<p>Aquí puedes encontrar información acerca de los negocios de hostelería de Burguillos.</p>
<p>Aquí puedes encontrar información acerca de los negocios de hostelería de Burguillos.</p>
<p>Disfruta tu comida.</p>
<p>¿Quieres que tu comercio aparezca aquí? Contacta con <a href="mailto:contact@owlcode.tech">contact@owlcode.tech</a></p>
</description>
<p>¿Quieres que tu comercio aparezca aquí? Contacta con <a href="mailto:contact@owlcode.tech">contact@owlcode.tech</a></p>
</description>
<parent>comercios</parent>
<priority>0</priority>
<menu_text>Donde comer</menu_text>
<slug>donde-comer</slug>
<priority>0</priority>
<menu_text>Donde comer</menu_text>
<slug>donde-comer</slug>
<img src="/img/donde-comer.webp"/>
<attributes>
<attribute>
<title>Comida vegana en Burguillos.</title>
<identifier>comida-vegana</identifier>
<priority>1</priority>
<menu_text>Listado de sitios que tienen oferta de platos veganos.</menu_text>
<img src="/img/vegano.webp" bottom-preview="400"/>
<description>
<h2>Restaurantes y bares con comida vegana en Burguillos.</h2>
@ -31,6 +33,7 @@
<identifier>reparto-a-domicilio-comida</identifier>
<priority>0</priority>
<menu_text>Listado de sitios de comida con reparto a domicilio.</menu_text>
<img src="/img/comida-domicilio.webp" bottom-preview="400"/>
<description>
<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>
<identifier>hamburguesas</identifier>
<priority>0</priority>
<img src="/img/hamburguesa.webp" bottom-preview="600"/>
<menu_text>Listado de sitios de comida que preparan hamburguesas.</menu_text>
<description>
<h2>Hamburgueserias y todo tipo de establecimientos que preparan hamburguesas.</h2>

View File

@ -1,16 +1,17 @@
<category>
<title>Información de Burguillos.</title>
<description>
<div class="easter-egg">
<div class="burguillos-logo-container">
<img alt="The logo of Burguillos.info" src="/img/burguillos-new-logo.svg"/>
</div>
</div>
<p>Burguillos.info no está afiliado con el Ayuntamiento de Burguillos.</p>
<description>
<div class="easter-egg">
<div class="burguillos-logo-container">
<img alt="The logo of Burguillos.info" src="/img/burguillos-new-logo.svg"/>
</div>
</div>
<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>
</description>
<priority>0</priority>
<menu_text><img alt="Principio" class="index-image-menu" src="/img/burguillos-new-logo.svg?v=1"/></menu_text>
<slug>index</slug>
<p>Un mundo de posibilidades a tu alcance en Burguillos.</p>
</description>
<img src="/img/rotonda.webp"/>
<priority>0</priority>
<menu_text><img alt="Principio" class="index-image-menu" src="/img/burguillos-new-logo.svg?v=1"/></menu_text>
<slug>index</slug>
</category>

View File

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

View File

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

View File

@ -28,7 +28,8 @@ sub get_attribute_preview ($self) {
$self->render(
format => 'png',
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_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);
$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