Improving ogimages.

This commit is contained in:
Sergiotarxz 2023-09-19 17:21:43 +02:00
parent 6de7c91676
commit 13f38ac67e
4 changed files with 31 additions and 22 deletions

View File

@ -21,9 +21,12 @@ sub index {
my $current_category = $categories->{'index'};
# Render template "example/welcome.html.ep" with message
my $base_url = $self->config('base_url');
$self->stash( ogimage =>
( $base_url . '/' . $current_category->{slug} . '-preview.png' ) );
$self->render(
categories => $categories,
current_category => $current_category
current_category => $current_category,
);
}
@ -73,8 +76,8 @@ sub category_rss {
my $description_tag = Mojo::DOM->new_tag( 'description',
'Todas las noticias de la categoria de Burguillos.info '
. $category->{title} );
my $link_tag = Mojo::DOM->new_tag( 'link',
$base_url . '/' . $category->{slug} );
my $link_tag =
Mojo::DOM->new_tag( 'link', $base_url . '/' . $category->{slug} );
$channel_tag->child_nodes->first->append_content($title_tag);
$channel_tag->child_nodes->first->append_content($description_tag);
$channel_tag->child_nodes->first->append_content($link_tag);
@ -99,8 +102,8 @@ sub _post_to_rss {
my $item_tag = Mojo::DOM->new_tag('item');
my $title_tag = Mojo::DOM->new_tag( 'title', $post->{title} );
my $base_url = BurguillosInfo->new->config->{base_url};
my $link = Mojo::DOM->new_tag( 'link',
$base_url = '/posts/' . $post->{slug} );
my $link =
Mojo::DOM->new_tag( 'link', $base_url = '/posts/' . $post->{slug} );
my $description = Mojo::DOM->new_tag( 'description',
Mojo::DOM->new( $post->{content} )->all_text );
my $guid = Mojo::DOM->new_tag( 'guid', $post->{slug} );
@ -149,10 +152,11 @@ sub category {
$self->render( template => '404', status => 404 );
return;
}
$self->stash( ogimage =>
( $base_url . '/' . $current_category->{slug} . '-preview.png' ) );
$self->render(
template => 'page/index',
categories => $categories,
ogimage => $base_url . '/' . $current_category->{slug} . '-preview.png',
current_category => $current_category
);
}

View File

@ -16,12 +16,17 @@
<meta charset="UTF-8"/>
<meta name="description" content="<%=defined $description_og ? $description_og : 'Lee más sobre: ' . title %>" />
<meta property="og:title" content="<%= title %>"/>
<meta property="og:site_name" content="burguillos.info" />
<meta property="og:site_name" content="Burguillos Info" />
<meta property="og:type" content="website" />
% my $ogimage = stash 'ogimage';
% say STDERR $ogimage;
% my $user_agent = stash 'useragent';
% if (defined $ogimage) {
% my $url_for = url_for || '';
<meta itemprop="image" property="og:image" content="<%= $ogimage %>"/>
<meta name="image" property="og:image" content="<%= $ogimage %>"/>
<meta property="og:url" content="<%=$base_url%><%= url_for %>"/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="630"/>
<meta name="twitter:image" content="<%=$ogimage%>" />

View File

@ -9,7 +9,7 @@
%
% my $description_og = '<div>'.$current_category->{description}.'</div>';
% $description_og = Mojo::DOM->new($description_og)->all_text;
% layout 'default', current_category_slug => $current_category->{slug}, description_og => $description_og, , ogimage => "/$current_category->{slug}-preview.png?v=4";
% layout 'default', current_category_slug => $current_category->{slug}, description_og => $description_og;
% title $current_category->{title};
<div class="description">
<h1><%= $current_category->{title} %></h1>

View File

@ -9,7 +9,7 @@
% my $description_og = '<div>'.$post->{content}.'</div>';
% $description_og = Mojo::DOM->new($description_og)->all_text;
% my $base_url = config 'base_url';
% layout 'default', current_category_slug => $current_category->{slug}, categories => $categories, description_og => $description_og, ogimage => "$base_url/posts/$post->{slug}-preview.png?v=4";
% layout 'default', current_category_slug => $current_category->{slug}, categories => $categories, description_og => $description_og;
% title $post->{title};
<div class="description">
<h1><%= $post->{title} %></h1>