Improving the relevance of promoted content.

This commit is contained in:
sergiotarxz 2023-09-29 14:36:19 +02:00
parent 0a7e75fe9d
commit a475de52f5
6 changed files with 32 additions and 23 deletions

View File

@ -5,6 +5,7 @@
<ogdesc>Mesón - Bar - Cristóbal - Carta y Menú.</ogdesc> <ogdesc>Mesón - Bar - Cristóbal - Carta y Menú.</ogdesc>
<last_modification_date>2023-09-06T11:16+00:00</last_modification_date> <last_modification_date>2023-09-06T11:16+00:00</last_modification_date>
<category>donde-comer</category> <category>donde-comer</category>
<category>index</category>
<slug>bar-cristobal</slug> <slug>bar-cristobal</slug>
<attributes> <attributes>
<attribute>hamburguesas</attribute> <attribute>hamburguesas</attribute>

View File

@ -7,6 +7,7 @@
<img src="/img/beluche.webp" bottom-preview="500"/> <img src="/img/beluche.webp" bottom-preview="500"/>
<pinned>2</pinned> <pinned>2</pinned>
<category>donde-comer</category> <category>donde-comer</category>
<category>index</category>
<attributes> <attributes>
<attribute>hamburguesas</attribute> <attribute>hamburguesas</attribute>
<attribute>reparto-a-domicilio-comida</attribute> <attribute>reparto-a-domicilio-comida</attribute>

View File

@ -8,6 +8,7 @@
contacto.</ogdesc> contacto.</ogdesc>
<img src="/img/yo-to-lo-guiso.webp" /> <img src="/img/yo-to-lo-guiso.webp" />
<category>donde-comer</category> <category>donde-comer</category>
<category>index</category>
<attributes> <attributes>
<attribute>hamburguesas</attribute> <attribute>hamburguesas</attribute>
<attribute>comida-vegana</attribute> <attribute>comida-vegana</attribute>

View File

@ -6,7 +6,7 @@
<img src="/img/farmacia.webp"/> <img src="/img/farmacia.webp"/>
<category>index</category> <category>index</category>
<slug>farmacia-guardia</slug> <slug>farmacia-guardia</slug>
<pinned>1</pinned> <pinned>100</pinned>
<content> <content>
<img alt="Imagen de cruz de Farmacia" src="/img/farmacia.webp"/> <img alt="Imagen de cruz de Farmacia" src="/img/farmacia.webp"/>

View File

@ -6,7 +6,7 @@
<img src="/img/ayuntamiento.webp"/> <img src="/img/ayuntamiento.webp"/>
<category>index</category> <category>index</category>
<slug>telefono-interes-burguillos</slug> <slug>telefono-interes-burguillos</slug>
<pinned>1</pinned> <pinned>100</pinned>
<content> <content>
<img alt="Imagen del ayuntamiento" src="/img/ayuntamiento.webp"/> <img alt="Imagen del ayuntamiento" src="/img/ayuntamiento.webp"/>

View File

@ -50,8 +50,8 @@ sub _ReturnCacheFilter($self, $filters = 1) {
} }
} }
$posts_by_slug_filtered{ $post->{slug} } = $post; $posts_by_slug_filtered{ $post->{slug} } = $post;
$posts_by_category_filtered{ $post->{category} } //= []; $posts_by_category_filtered{ $category } //= [];
push @{ $posts_by_category_filtered{ $post->{category} } }, $post; push @{ $posts_by_category_filtered{ $category } }, $post;
} }
} }
return ( \%posts_by_category_filtered, \%posts_by_slug_filtered ); return ( \%posts_by_category_filtered, \%posts_by_slug_filtered );
@ -69,15 +69,18 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
or die "Missing date at $post_file."; or die "Missing date at $post_file.";
my $ogdesc = $dom->at(':root > ogdesc')->text my $ogdesc = $dom->at(':root > ogdesc')->text
or die "Missing ogdesc at $post_file"; or die "Missing ogdesc at $post_file";
my $category = $dom->at(':root > category')->text my @categories = $dom->find(':root > category')->map('text')->each;
or die "Missing category at $post_file.";
my $slug = $dom->at(':root > slug')->text my $slug = $dom->at(':root > slug')->text
or die "Missing slug at $post_file."; or die "Missing slug at $post_file.";
my $content_tag = $dom->at(':root > content') my $content_tag = $dom->at(':root > content')
or die "Missing content at $post_file."; or die "Missing content at $post_file.";
for my $tag ( $content_tag->children->each ) { for my $tag ( $content_tag->children->each ) {
$tag->content( $tag->content =~ s/\n//gr ); $tag->content( $tag->content =~ s/\n//gr );
} }
if ( !scalar @categories ) {
die 'Missing category';
}
my $content = $content_tag->content; my $content = $content_tag->content;
my $pinned_node = $dom->at(':root > pinned'); my $pinned_node = $dom->at(':root > pinned');
my $image_element = $dom->at(':root > img'); my $image_element = $dom->at(':root > img');
@ -106,7 +109,8 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
author => $author, author => $author,
date => $date, date => $date,
ogdesc => $ogdesc, ogdesc => $ogdesc,
category => $category, categories => [@categories],
category => $categories[0],
slug => $slug, slug => $slug,
content => $content, content => $content,
attributes => $attributes, attributes => $attributes,
@ -147,7 +151,8 @@ sub _GeneratePostCache ($self) {
if ( !defined $post ) { if ( !defined $post ) {
next; next;
} }
my $category = $post->{category}; my $categories = $post->{categories};
for my $category ($post->{categories}->@*) {
$cached_posts_by_category->{$category} //= []; $cached_posts_by_category->{$category} //= [];
my $slug = $post->{slug}; my $slug = $post->{slug};
my $category_posts = $cached_posts_by_category->{$category}; my $category_posts = $cached_posts_by_category->{$category};
@ -155,6 +160,7 @@ sub _GeneratePostCache ($self) {
push @$category_posts, $post; push @$category_posts, $post;
} }
} }
}
sub Retrieve ( $self, $filters = 1 ) { sub Retrieve ( $self, $filters = 1 ) {
if ( defined $cached_posts_by_category && defined $cached_posts_by_slug ) { if ( defined $cached_posts_by_category && defined $cached_posts_by_slug ) {
@ -226,8 +232,8 @@ sub PreviewOg($self, $post, $isWhatsApp) {
my $image_file = $post->{image}; my $image_file = $post->{image};
my $image_bottom_preview = $post->{image_bottom_preview}; my $image_bottom_preview = $post->{image_bottom_preview};
if ($isWhatsApp) { if ($isWhatsApp) {
return BurguillosInfo::Preview->WhatsappAlternativeGenerate( $title, $content, $image_file, return BurguillosInfo::Preview->WhatsappAlternativeGenerate( $title,
$image_bottom_preview ); $content, $image_file, $image_bottom_preview );
} }
return BurguillosInfo::Preview->Generate( $title, $content, $image_file, return BurguillosInfo::Preview->Generate( $title, $content, $image_file,
$image_bottom_preview ); $image_bottom_preview );