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>
|
||||
<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>
|
||||
<img src="/img/duran.webp"/>
|
||||
<img src="/img/duran.webp" bottom-preview="600"/>
|
||||
<category>donde-comer</category>
|
||||
<attributes>
|
||||
<attribute>hamburguesas</attribute>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<title>Carta y Menú del Café - Bar Beluche en Burguillos.</title>
|
||||
<last_modification_date>2023-09-13T16:03+00:00</last_modification_date>
|
||||
<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>
|
||||
<category>donde-comer</category>
|
||||
<attributes>
|
||||
|
@ -77,6 +77,7 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
||||
my $pinned_node = $dom->at(':root > pinned');
|
||||
my $image_element = $dom->at(':root > img');
|
||||
my $image;
|
||||
my $image_bottom_preview;
|
||||
my $attributes = $self->_GetAttributes( $post_file, $dom );
|
||||
|
||||
my $pinned;
|
||||
@ -84,7 +85,8 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
||||
$pinned = int( $pinned_node->text );
|
||||
}
|
||||
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 =
|
||||
@ -95,14 +97,15 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
|
||||
}
|
||||
|
||||
return {
|
||||
title => $title,
|
||||
author => $author,
|
||||
date => $date,
|
||||
ogdesc => $ogdesc,
|
||||
category => $category,
|
||||
slug => $slug,
|
||||
content => $content,
|
||||
attributes => $attributes,
|
||||
title => $title,
|
||||
author => $author,
|
||||
date => $date,
|
||||
ogdesc => $ogdesc,
|
||||
category => $category,
|
||||
slug => $slug,
|
||||
content => $content,
|
||||
attributes => $attributes,
|
||||
image_bottom_preview => $image_bottom_preview,
|
||||
(
|
||||
( defined $last_modification_date )
|
||||
? ( last_modification_date => $last_modification_date )
|
||||
@ -181,8 +184,10 @@ sub RetrieveAllPostsForCategory ( $self, $category_name ) {
|
||||
}
|
||||
|
||||
sub shufflePostsIfRequired ( $self, $category, $posts ) {
|
||||
my $pinned_posts = [ sort { $b->{pinned} <=> $b->{pinned} }
|
||||
grep { exists $_->{pinned} } @$posts ];
|
||||
my $pinned_posts = [
|
||||
sort { $b->{pinned} <=> $b->{pinned} }
|
||||
grep { exists $_->{pinned} } @$posts
|
||||
];
|
||||
$posts = [ grep { !exists $_->{pinned} } @$posts ];
|
||||
$pinned_posts = [ sort { $b <=> $a } @$pinned_posts ];
|
||||
if ( exists $category->{random} && $category->{random} ) {
|
||||
@ -205,11 +210,13 @@ sub RetrieveDirectPostsForCategory ( $self, $category_name ) {
|
||||
}
|
||||
|
||||
sub PreviewOg {
|
||||
my $self = shift;
|
||||
my $post = shift;
|
||||
my $title = $post->{title};
|
||||
my $content = $post->{content};
|
||||
my $image_file = $post->{image};
|
||||
return BurguillosInfo::Preview->Generate( $title, $content, $image_file );
|
||||
my $self = shift;
|
||||
my $post = shift;
|
||||
my $title = $post->{title};
|
||||
my $content = $post->{content};
|
||||
my $image_file = $post->{image};
|
||||
my $image_bottom_preview = $post->{image_bottom_preview};
|
||||
return BurguillosInfo::Preview->Generate( $title, $content, $image_file,
|
||||
$image_bottom_preview );
|
||||
}
|
||||
1;
|
||||
|
@ -23,13 +23,13 @@ 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) {
|
||||
sub Generate($self, $title, $content, $image_file, $image_bottom_preview) {
|
||||
my $dom = Mojo::DOM->new($content);
|
||||
$content = $dom->all_text;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ sub _GenerateSVGPreviewHeaderBar($self, $svg, $group) {
|
||||
)->cdata('Burguillos.info');
|
||||
}
|
||||
|
||||
sub _GenerateSVGPreview($self, $title, $content, $image_file) {
|
||||
sub _GenerateSVGPreview($self, $title, $content, $image_file, $image_bottom_preview) {
|
||||
my @content = @$content;
|
||||
my $svg = SVG->new( width => $SVG_WIDTH, height => $SVG_HEIGHT );
|
||||
|
||||
@ -97,7 +97,7 @@ sub _GenerateSVGPreview($self, $title, $content, $image_file) {
|
||||
my $new_y;
|
||||
|
||||
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;
|
||||
@ -155,7 +155,7 @@ sub _DivideTextContentInLines($self, $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 = path($self->_ToPng($image_file));
|
||||
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);
|
||||
|
||||
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 ($output) = capture {
|
||||
system qw/file --mime-type/, $image_file;
|
||||
|
Loading…
Reference in New Issue
Block a user