Fixing previews for duran and beluche.
This commit is contained in:
parent
081f5d87dd
commit
751730868c
@ -3,7 +3,7 @@
|
|||||||
<date>2023-05-05T22:21+00:00</date>
|
<date>2023-05-05T22:21+00:00</date>
|
||||||
<title>Carta y Menú del Bar - Restaurante Durán - Centro de día en Burguillos.</title>
|
<title>Carta y Menú del Bar - Restaurante Durán - Centro de día en Burguillos.</title>
|
||||||
<ogdesc>Carta y Menú del Bar - Restaurante Durán - Centro de día en Burguillos.</ogdesc>
|
<ogdesc>Carta y Menú del Bar - Restaurante Durán - Centro de día en Burguillos.</ogdesc>
|
||||||
<img src="/img/duran.webp"/>
|
<img src="/img/duran.webp" bottom-preview="600"/>
|
||||||
<category>donde-comer</category>
|
<category>donde-comer</category>
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute>hamburguesas</attribute>
|
<attribute>hamburguesas</attribute>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<title>Carta y Menú del Café - Bar Beluche en Burguillos.</title>
|
<title>Carta y Menú del Café - Bar Beluche en Burguillos.</title>
|
||||||
<last_modification_date>2023-09-13T16:03+00:00</last_modification_date>
|
<last_modification_date>2023-09-13T16:03+00:00</last_modification_date>
|
||||||
<ogdesc>Carta y Menú del Café - Bar Beluche en Burguillos.</ogdesc>
|
<ogdesc>Carta y Menú del Café - Bar Beluche en Burguillos.</ogdesc>
|
||||||
<img src="/img/beluche.webp"/>
|
<img src="/img/beluche.webp" bottom-preview="500"/>
|
||||||
<pinned>2</pinned>
|
<pinned>2</pinned>
|
||||||
<category>donde-comer</category>
|
<category>donde-comer</category>
|
||||||
<attributes>
|
<attributes>
|
||||||
|
@ -77,6 +77,7 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
|||||||
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');
|
||||||
my $image;
|
my $image;
|
||||||
|
my $image_bottom_preview;
|
||||||
my $attributes = $self->_GetAttributes( $post_file, $dom );
|
my $attributes = $self->_GetAttributes( $post_file, $dom );
|
||||||
|
|
||||||
my $pinned;
|
my $pinned;
|
||||||
@ -84,7 +85,8 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
|||||||
$pinned = int( $pinned_node->text );
|
$pinned = int( $pinned_node->text );
|
||||||
}
|
}
|
||||||
if ( defined $image_element ) {
|
if ( defined $image_element ) {
|
||||||
$image = $image_element->attr->{src};
|
$image = $image_element->attr->{src};
|
||||||
|
$image_bottom_preview = $image_element->attr->{'bottom-preview'};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $last_modification_date_element =
|
my $last_modification_date_element =
|
||||||
@ -95,14 +97,15 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title => $title,
|
title => $title,
|
||||||
author => $author,
|
author => $author,
|
||||||
date => $date,
|
date => $date,
|
||||||
ogdesc => $ogdesc,
|
ogdesc => $ogdesc,
|
||||||
category => $category,
|
category => $category,
|
||||||
slug => $slug,
|
slug => $slug,
|
||||||
content => $content,
|
content => $content,
|
||||||
attributes => $attributes,
|
attributes => $attributes,
|
||||||
|
image_bottom_preview => $image_bottom_preview,
|
||||||
(
|
(
|
||||||
( defined $last_modification_date )
|
( defined $last_modification_date )
|
||||||
? ( last_modification_date => $last_modification_date )
|
? ( last_modification_date => $last_modification_date )
|
||||||
@ -181,8 +184,10 @@ sub RetrieveAllPostsForCategory ( $self, $category_name ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub shufflePostsIfRequired ( $self, $category, $posts ) {
|
sub shufflePostsIfRequired ( $self, $category, $posts ) {
|
||||||
my $pinned_posts = [ sort { $b->{pinned} <=> $b->{pinned} }
|
my $pinned_posts = [
|
||||||
grep { exists $_->{pinned} } @$posts ];
|
sort { $b->{pinned} <=> $b->{pinned} }
|
||||||
|
grep { exists $_->{pinned} } @$posts
|
||||||
|
];
|
||||||
$posts = [ grep { !exists $_->{pinned} } @$posts ];
|
$posts = [ grep { !exists $_->{pinned} } @$posts ];
|
||||||
$pinned_posts = [ sort { $b <=> $a } @$pinned_posts ];
|
$pinned_posts = [ sort { $b <=> $a } @$pinned_posts ];
|
||||||
if ( exists $category->{random} && $category->{random} ) {
|
if ( exists $category->{random} && $category->{random} ) {
|
||||||
@ -205,11 +210,13 @@ sub RetrieveDirectPostsForCategory ( $self, $category_name ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub PreviewOg {
|
sub PreviewOg {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $post = shift;
|
my $post = shift;
|
||||||
my $title = $post->{title};
|
my $title = $post->{title};
|
||||||
my $content = $post->{content};
|
my $content = $post->{content};
|
||||||
my $image_file = $post->{image};
|
my $image_file = $post->{image};
|
||||||
return BurguillosInfo::Preview->Generate( $title, $content, $image_file );
|
my $image_bottom_preview = $post->{image_bottom_preview};
|
||||||
|
return BurguillosInfo::Preview->Generate( $title, $content, $image_file,
|
||||||
|
$image_bottom_preview );
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
@ -23,13 +23,13 @@ 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) {
|
sub Generate($self, $title, $content, $image_file, $image_bottom_preview) {
|
||||||
my $dom = Mojo::DOM->new($content);
|
my $dom = Mojo::DOM->new($content);
|
||||||
$content = $dom->all_text;
|
$content = $dom->all_text;
|
||||||
|
|
||||||
|
|
||||||
my $svg =
|
my $svg =
|
||||||
$self->_GenerateSVGPreview( $title, $self->_DivideTextContentInLines($content), $image_file );
|
$self->_GenerateSVGPreview( $title, $self->_DivideTextContentInLines($content), $image_file, $image_bottom_preview );
|
||||||
return $self->_SVGToPNG($svg);
|
return $self->_SVGToPNG($svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ sub _GenerateSVGPreviewHeaderBar($self, $svg, $group) {
|
|||||||
)->cdata('Burguillos.info');
|
)->cdata('Burguillos.info');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _GenerateSVGPreview($self, $title, $content, $image_file) {
|
sub _GenerateSVGPreview($self, $title, $content, $image_file, $image_bottom_preview) {
|
||||||
my @content = @$content;
|
my @content = @$content;
|
||||||
my $svg = SVG->new( width => $SVG_WIDTH, height => $SVG_HEIGHT );
|
my $svg = SVG->new( width => $SVG_WIDTH, height => $SVG_HEIGHT );
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ sub _GenerateSVGPreview($self, $title, $content, $image_file) {
|
|||||||
my $new_y;
|
my $new_y;
|
||||||
|
|
||||||
if ( defined $image_file ) {
|
if ( defined $image_file ) {
|
||||||
$new_y = $self->_AttachImageSVG( $svg, $group, $image_file );
|
$new_y = $self->_AttachImageSVG( $svg, $group, $image_file, $image_bottom_preview );
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_y //= 100;
|
$new_y //= 100;
|
||||||
@ -155,7 +155,7 @@ sub _DivideTextContentInLines($self, $content) {
|
|||||||
return \@new_content;
|
return \@new_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _AttachImageSVG($self, $svg, $group, $image_file) {
|
sub _AttachImageSVG($self, $svg, $group, $image_file, $image_bottom_preview) {
|
||||||
$image_file = $PUBLIC_DIR->child( './' . $image_file );
|
$image_file = $PUBLIC_DIR->child( './' . $image_file );
|
||||||
$image_file = path($self->_ToPng($image_file));
|
$image_file = path($self->_ToPng($image_file));
|
||||||
my ( $stdout, $stderr, $error ) = capture {
|
my ( $stdout, $stderr, $error ) = capture {
|
||||||
@ -187,7 +187,10 @@ sub _AttachImageSVG($self, $svg, $group, $image_file) {
|
|||||||
$clip_path->rect(x => 0, y => 50, width => 1200, height => $height);
|
$clip_path->rect(x => 0, y => 50, width => 1200, height => $height);
|
||||||
|
|
||||||
my $x = 0;
|
my $x = 0;
|
||||||
my $y_image = 50 - $height_complete_image + $height;
|
my $y_image = 50 - $height_complete_image + $height;
|
||||||
|
if (defined $image_bottom_preview && $height_complete_image > $SVG_EMBEDDED_IMAGE_MAX_HEIGHT) {
|
||||||
|
$y_image += $height_complete_image - $image_bottom_preview;
|
||||||
|
}
|
||||||
my $y = 50;
|
my $y = 50;
|
||||||
my ($output) = capture {
|
my ($output) = capture {
|
||||||
system qw/file --mime-type/, $image_file;
|
system qw/file --mime-type/, $image_file;
|
||||||
|
Loading…
Reference in New Issue
Block a user