Rebranding the code, still not made any frontend branding.

This commit is contained in:
sergiotarxz 2023-05-09 03:20:23 +02:00
parent b3e96df1f1
commit b69f3babb7
22 changed files with 194 additions and 166 deletions

View File

@ -1,12 +1,12 @@
package BurguillosInfo; package OwlcodeTech;
use BurguillosInfo::Controller::Metrics; use OwlcodeTech::Controller::Metrics;
use Mojo::Base 'Mojolicious', -signatures; use Mojo::Base 'Mojolicious', -signatures;
# This method will run once at server start # This method will run once at server start
sub startup ($self) { sub startup ($self) {
my $metrics = BurguillosInfo::Controller::Metrics->new; my $metrics = OwlcodeTech::Controller::Metrics->new;
$self->hook( $self->hook(
around_dispatch => sub { around_dispatch => sub {
my $next = shift; my $next = shift;

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Categories; package OwlcodeTech::Categories;
use v5.34.1; use v5.34.1;
@ -11,7 +11,7 @@ use Const::Fast;
use Mojo::DOM; use Mojo::DOM;
use Path::Tiny; use Path::Tiny;
use BurguillosInfo::Preview; use OwlcodeTech::Preview;
const my $CURRENT_FILE => __FILE__; const my $CURRENT_FILE => __FILE__;
const my $CATEGORIES_DIR => const my $CATEGORIES_DIR =>
@ -23,7 +23,7 @@ sub new {
return bless {}, shift; return bless {}, shift;
} }
sub Retrieve($self) { sub Retrieve ($self) {
if ( defined $cached_categories ) { if ( defined $cached_categories ) {
return $cached_categories; return $cached_categories;
} }
@ -31,21 +31,22 @@ sub Retrieve($self) {
for my $category_file ( $CATEGORIES_DIR->children ) { for my $category_file ( $CATEGORIES_DIR->children ) {
warn "Bad file $category_file, omiting...", next warn "Bad file $category_file, omiting...", next
if !-f $category_file || $category_file !~ /\.xml$/; if !-f $category_file || $category_file !~ /\.xml$/;
my $dom = Mojo::DOM->new( $category_file->slurp_utf8 ); my $dom = Mojo::DOM->new( $category_file->slurp_utf8 );
defined(my $title = $dom->at(':root > title')->text) defined( my $title = $dom->at(':root > title')->text )
or die "Missing title at $category_file."; 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"; 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"; 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"; 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"; or die "Missing priority at $category_file";
my $attributes = $self->_GetAttributes($dom, $category_file); my $attributes = $self->_GetAttributes( $dom, $category_file );
my $parent_tag = $dom->at(':root > parent'); my $parent_tag = $dom->at(':root > parent');
my $parent; my $parent;
if (defined $parent_tag) {
if ( defined $parent_tag ) {
$parent = $parent_tag->content; $parent = $parent_tag->content;
} }
my $category = { my $category = {
@ -55,9 +56,9 @@ sub Retrieve($self) {
description => $description, description => $description,
priority => $priority, priority => $priority,
( (
(defined $parent) ? ( defined $parent )
(parent => $parent) : ? ( parent => $parent )
() : ()
), ),
attributes => $attributes, attributes => $attributes,
}; };
@ -68,64 +69,73 @@ sub Retrieve($self) {
return $cached_categories; return $cached_categories;
} }
sub _GetAttributes($self, $dom, $category_file) { sub _GetAttributes ( $self, $dom, $category_file ) {
my $attributes_tag = $dom->at(':root > attributes'); my $attributes_tag = $dom->at(':root > attributes');
my %attributes; my %attributes;
if (defined $attributes_tag) { if ( defined $attributes_tag ) {
my @attribute_tag_list = $attributes_tag->find('attributes > attribute')->each; my @attribute_tag_list =
$attributes_tag->find('attributes > attribute')->each;
for my $attribute_tag (@attribute_tag_list) { 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"; 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"; 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"; 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"; 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"; or die "Missing attribute priority at $category_file";
$attributes{$identifier} = { $attributes{$identifier} = {
title => $title, title => $title,
identifier => $identifier, identifier => $identifier,
priority => $priority, priority => $priority,
menu_text => $menu_text, menu_text => $menu_text,
description => $description, description => $description,
}; };
} }
} }
return \%attributes; return \%attributes;
} }
sub _PopulateChildrenField($self, $categories) { sub _PopulateChildrenField ( $self, $categories ) {
for my $category_name (keys %$categories) { for my $category_name ( keys %$categories ) {
my $category = $categories->{$category_name}; my $category = $categories->{$category_name};
$category->{children} //= []; $category->{children} //= [];
my $parent_name = $category->{parent}; my $parent_name = $category->{parent};
if (!defined $parent_name) { if ( !defined $parent_name ) {
next; next;
} }
my $parent = $categories->{$parent_name}; my $parent = $categories->{$parent_name};
if (!defined $parent) { if ( !defined $parent ) {
die "Category $parent not exists and is the parent of $category_name."; die
"Category $parent not exists and is the parent of $category_name.";
} }
$parent->{children} //= []; $parent->{children} //= [];
push $parent->{children}->@*, $category; push $parent->{children}->@*, $category;
} }
} }
sub _AvoidGrandChildCategories($self, $categories) { sub _AvoidGrandChildCategories ( $self, $categories ) {
for my $category_slug (keys %$categories) { for my $category_slug ( keys %$categories ) {
my $category = $categories->{$category_slug}; my $category = $categories->{$category_slug};
my $parent = $category->{parent}; my $parent = $category->{parent};
if (defined $parent && defined $categories->{$parent}{parent}) { if ( defined $parent && defined $categories->{$parent}{parent} ) {
die "$category_slug category is grandchild of $categories->{$parent}{parent}) category and this is not allowed."; die
"$category_slug category is grandchild of $categories->{$parent}{parent}) category and this is not allowed.";
} }
} }
} }
sub PreviewOg($self, $category) { sub PreviewOg ( $self, $category ) {
my $title = $category->{title}; my $title = $category->{title};
my $description = $category->{description}; my $description = $category->{description};
return BurguillosInfo::Preview->Generate($title, $description, undef); my $site_name = $self->config('site_name');
return OwlcodeTech::Preview->Generate( $title, $description, undef,
$site_name );
} }
1; 1;

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Controller::Attribute; package OwlcodeTech::Controller::Attribute;
use v5.34.1; use v5.34.1;
use strict; use strict;
@ -6,17 +6,18 @@ use warnings;
use Data::Dumper; use Data::Dumper;
use BurguillosInfo::Categories; use OwlcodeTech::Categories;
use Mojo::Base 'Mojolicious::Controller', -signatures; use Mojo::Base 'Mojolicious::Controller', -signatures;
use BurguillosInfo::Preview; use OwlcodeTech::Preview;
sub get_attribute_preview ($self) { sub get_attribute_preview ($self) {
my $category_slug = $self->param('category_slug'); my $category_slug = $self->param('category_slug');
my $attribute_slug = $self->param('attribute_slug'); my $attribute_slug = $self->param('attribute_slug');
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category = $categories->{$category_slug}; my $category = $categories->{$category_slug};
my $site_name = $self->config('site_name');
if ( !defined $category ) { if ( !defined $category ) {
return $self->reply->not_found; return $self->reply->not_found;
} }
@ -27,8 +28,9 @@ sub get_attribute_preview ($self) {
$self->render( $self->render(
format => 'png', format => 'png',
data => BurguillosInfo::Preview->Generate( data => OwlcodeTech::Preview->Generate(
$attribute->{title}, $attribute->{description}, undef $attribute->{title}, $attribute->{description},
undef, $site_name
), ),
); );
} }
@ -37,7 +39,7 @@ sub get ($self) {
my $category_slug = $self->param('category_slug'); my $category_slug = $self->param('category_slug');
my $attribute_slug = $self->param('attribute_slug'); my $attribute_slug = $self->param('attribute_slug');
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category = $categories->{$category_slug}; my $category = $categories->{$category_slug};
if ( !defined $category ) { if ( !defined $category ) {
return $self->reply->not_found; return $self->reply->not_found;
@ -46,8 +48,8 @@ sub get ($self) {
if ( !defined $attribute ) { if ( !defined $attribute ) {
return $self->reply->not_found; return $self->reply->not_found;
} }
my $posts = BurguillosInfo::Posts->RetrieveDirectPostsForCategory( my $posts =
$category->{slug} ); OwlcodeTech::Posts->RetrieveDirectPostsForCategory( $category->{slug} );
$posts = [ grep { defined $_->{attributes}{$attribute_slug} } @$posts ]; $posts = [ grep { defined $_->{attributes}{$attribute_slug} } @$posts ];
my $base_url = $self->config('base_url'); my $base_url = $self->config('base_url');
$self->render( $self->render(

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Controller::Example; package OwlcodeTech::Controller::Example;
use Mojo::Base 'Mojolicious::Controller', -signatures; use Mojo::Base 'Mojolicious::Controller', -signatures;
# This action will render a template # This action will render a template

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Controller::Metrics; package OwlcodeTech::Controller::Metrics;
use v5.34.1; use v5.34.1;
@ -7,7 +7,7 @@ use warnings;
use Data::Dumper; use Data::Dumper;
use BurguillosInfo::Tracking; use OwlcodeTech::Tracking;
use Mojo::Base 'Mojolicious::Controller', '-signatures'; use Mojo::Base 'Mojolicious::Controller', '-signatures';
@ -22,10 +22,15 @@ sub request {
shift; shift;
my $c = shift; my $c = shift;
my $app = $c->app; my $app = $c->app;
if (!defined $tracking) { eval {
$tracking = BurguillosInfo::Tracking->new($app); if (!defined $tracking) {
} $tracking = OwlcodeTech::Tracking->new($app);
$tracking->register_request($c); }
$tracking->register_request($c);
};
if ($@) {
warn $@;
}
} }
sub stats { sub stats {

View File

@ -1,23 +1,23 @@
package BurguillosInfo::Controller::Page; package OwlcodeTech::Controller::Page;
use v5.34.1; use v5.34.1;
use strict; use strict;
use warnings; use warnings;
use BurguillosInfo::Categories; use OwlcodeTech::Categories;
use BurguillosInfo::Posts; use OwlcodeTech::Posts;
use Data::Dumper; use Data::Dumper;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller', '-signatures';
use DateTime::Format::ISO8601; use DateTime::Format::ISO8601;
use DateTime::Format::Mail; use DateTime::Format::Mail;
sub index { sub index {
my $self = shift; my $self = shift;
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $current_category = $categories->{'index'}; my $current_category = $categories->{'index'};
# Render template "example/welcome.html.ep" with message # Render template "example/welcome.html.ep" with message
@ -29,22 +29,24 @@ sub index {
sub category_rss { sub category_rss {
my $self = shift; my $self = shift;
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category_name = $self->param('category'); my $category_name = $self->param('category');
my $current_category = $categories->{$category_name}; my $current_category = $categories->{$category_name};
my ( $posts_categories, $posts_slug ) = my ( $posts_categories, $posts_slug ) =
BurguillosInfo::Posts->new->Retrieve; OwlcodeTech::Posts->new->Retrieve;
if ( !defined $current_category && $category_name ne 'all' ) { if ( !defined $current_category && $category_name ne 'all' ) {
$self->render( template => '404', status => 404 ); $self->render( template => '404', status => 404 );
return; return;
} }
my $dom = Mojo::DOM->new_tag( 'rss', version => '2.0', undef ); my $dom = Mojo::DOM->new_tag( 'rss', version => '2.0', undef );
my $channel_tag = Mojo::DOM->new_tag('channel'); my $channel_tag = Mojo::DOM->new_tag('channel');
my $base_url = $self->config('base_url');
my $site_name = $self->config('site_name');
if ( $category_name eq 'all' ) { if ( $category_name eq 'all' ) {
my $title_tag = Mojo::DOM->new_tag( 'title', 'Burguillos.info' ); my $title_tag = Mojo::DOM->new_tag( 'title', $site_name );
my $description_tag = Mojo::DOM->new_tag( 'description', my $description_tag = Mojo::DOM->new_tag( 'description',
'Todas las noticias de Burguillos.info.' ); "Todas las noticias de $site_name." );
my $link_tag = Mojo::DOM->new_tag( 'link', 'https://burguillos.info/' ); my $link_tag = Mojo::DOM->new_tag( 'link', $base_url );
$channel_tag->child_nodes->first->append_content($title_tag); $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($description_tag);
$channel_tag->child_nodes->first->append_content($link_tag); $channel_tag->child_nodes->first->append_content($link_tag);
@ -52,19 +54,19 @@ sub category_rss {
my $posts = $posts_categories->{$category}; my $posts = $posts_categories->{$category};
for my $post (@$posts) { for my $post (@$posts) {
$channel_tag->child_nodes->first->append_content( $channel_tag->child_nodes->first->append_content(
_post_to_rss($post) ); $self->_post_to_rss($post) );
} }
} }
} }
else { else {
my $category = $current_category; my $category = $current_category;
my $title_tag = Mojo::DOM->new_tag( 'title', my $title_tag = Mojo::DOM->new_tag( 'title',
"Burguillos.info - " . $category->{title} ); "$site_name - " . $category->{title} );
my $description_tag = Mojo::DOM->new_tag( 'description', my $description_tag = Mojo::DOM->new_tag( 'description',
'Todas las noticias de la categoria de Burguillos.info ' "Todas las noticias de la categoria de $site_name "
. $category->{title} ); . $category->{title} );
my $link_tag = Mojo::DOM->new_tag( 'link', my $link_tag = Mojo::DOM->new_tag( 'link',
'https://burguillos.info/' . $category->{slug} ); $base_url . '/' . $category->{slug} );
$channel_tag->child_nodes->first->append_content($title_tag); $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($description_tag);
$channel_tag->child_nodes->first->append_content($link_tag); $channel_tag->child_nodes->first->append_content($link_tag);
@ -72,7 +74,7 @@ sub category_rss {
for my $post (@$posts) { for my $post (@$posts) {
$channel_tag->child_nodes->first->append_content( $channel_tag->child_nodes->first->append_content(
_post_to_rss($post) ); $self->_post_to_rss($post) );
} }
} }
@ -83,12 +85,12 @@ sub category_rss {
); );
} }
sub _post_to_rss { sub _post_to_rss($self, $post) {
my $post = shift;
my $item_tag = Mojo::DOM->new_tag('item'); my $item_tag = Mojo::DOM->new_tag('item');
my $title_tag = Mojo::DOM->new_tag( 'title', $post->{title} ); my $title_tag = Mojo::DOM->new_tag( 'title', $post->{title} );
my $base_url = $self->config('base_url');
my $link = Mojo::DOM->new_tag( 'link', my $link = Mojo::DOM->new_tag( 'link',
'https://burguillos.info/posts/' . $post->{slug} ); "$base_url/posts/" . $post->{slug} );
my $description = Mojo::DOM->new_tag( 'description', my $description = Mojo::DOM->new_tag( 'description',
Mojo::DOM->new( $post->{content} )->all_text ); Mojo::DOM->new( $post->{content} )->all_text );
my $guid = Mojo::DOM->new_tag( 'guid', $post->{slug} ); my $guid = Mojo::DOM->new_tag( 'guid', $post->{slug} );
@ -112,8 +114,8 @@ sub post {
my $self = shift; my $self = shift;
my $slug = $self->param('slug'); my $slug = $self->param('slug');
my ( $posts_categories, $posts_slug ) = my ( $posts_categories, $posts_slug ) =
BurguillosInfo::Posts->new->Retrieve; OwlcodeTech::Posts->new->Retrieve;
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $post = $posts_slug->{$slug}; my $post = $posts_slug->{$slug};
if ( !defined $post ) { if ( !defined $post ) {
$self->render( template => '404', status => 404 ); $self->render( template => '404', status => 404 );
@ -129,7 +131,7 @@ sub post {
sub category { sub category {
my $self = shift; my $self = shift;
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category_name = $self->param('category'); my $category_name = $self->param('category');
my $current_category = $categories->{$category_name}; my $current_category = $categories->{$category_name};
my $base_url = $self->config('base_url'); my $base_url = $self->config('base_url');
@ -148,7 +150,7 @@ sub category {
sub get_category_preview { sub get_category_preview {
my $self = shift; my $self = shift;
my $category_slug = $self->param('category'); my $category_slug = $self->param('category');
my $category_model = BurguillosInfo::Categories->new; my $category_model = OwlcodeTech::Categories->new;
my $categories = $category_model->Retrieve; my $categories = $category_model->Retrieve;
if ( !defined $categories->{$category_slug} ) { if ( !defined $categories->{$category_slug} ) {
$self->render( template => '404', status => 404 ); $self->render( template => '404', status => 404 );
@ -164,7 +166,7 @@ sub get_category_preview {
sub get_post_preview { sub get_post_preview {
my $self = shift; my $self = shift;
my $slug = $self->param('slug'); my $slug = $self->param('slug');
my $post_model = BurguillosInfo::Posts->new; my $post_model = OwlcodeTech::Posts->new;
my ( $posts_categories, $posts_slug ) = $post_model->Retrieve; my ( $posts_categories, $posts_slug ) = $post_model->Retrieve;
if ( !defined $posts_slug->{$slug} ) { if ( !defined $posts_slug->{$slug} ) {
$self->render( template => '404', status => 404 ); $self->render( template => '404', status => 404 );

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Controller::Robots; package OwlcodeTech::Controller::Robots;
use Mojo::Base 'Mojolicious::Controller', '-signatures'; use Mojo::Base 'Mojolicious::Controller', '-signatures';
sub robots($self) { sub robots($self) {

View File

@ -1,12 +1,12 @@
package BurguillosInfo::Controller::Sitemap; package OwlcodeTech::Controller::Sitemap;
use v5.34.1; use v5.34.1;
use strict; use strict;
use warnings; use warnings;
use BurguillosInfo::Categories; use OwlcodeTech::Categories;
use BurguillosInfo::Posts; use OwlcodeTech::Posts;
use DateTime::Format::ISO8601; use DateTime::Format::ISO8601;
@ -15,7 +15,7 @@ use XML::Twig;
use Mojo::Base 'Mojolicious::Controller', '-signatures'; use Mojo::Base 'Mojolicious::Controller', '-signatures';
sub sitemap ($self) { sub sitemap ($self) {
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $dom = Mojo::DOM->new_tag( my $dom = Mojo::DOM->new_tag(
'urlset', 'urlset',
xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9', xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9',
@ -38,7 +38,7 @@ sub _append_category_dom ( $self, $dom, $category_key, $categories ) {
my $date_last_modification_category; my $date_last_modification_category;
my ( $posts_categories, $posts_slug ) = my ( $posts_categories, $posts_slug ) =
BurguillosInfo::Posts->new->Retrieve; OwlcodeTech::Posts->new->Retrieve;
for my $post ( $posts_categories->{$category_key}->@* ) { for my $post ( $posts_categories->{$category_key}->@* ) {
( $date_publish_category, $date_last_modification_category ) = ( $date_publish_category, $date_last_modification_category ) =
_get_dates_for_category( $date_publish_category, _get_dates_for_category( $date_publish_category,

View File

@ -1,4 +1,4 @@
package BurguillosInfo::DB; package OwlcodeTech::DB;
use v5.34.1; use v5.34.1;
@ -8,7 +8,7 @@ use warnings;
use DBI; use DBI;
use DBD::Pg; use DBD::Pg;
use BurguillosInfo::DB::Migrations; use OwlcodeTech::DB::Migrations;
use Data::Dumper; use Data::Dumper;
my $dbh; my $dbh;
@ -38,7 +38,7 @@ sub _migrate {
my $dbh = shift; my $dbh = shift;
local $dbh->{RaiseError} = 0; local $dbh->{RaiseError} = 0;
local $dbh->{PrintError} = 0; local $dbh->{PrintError} = 0;
my @migrations = BurguillosInfo::DB::Migrations::MIGRATIONS(); my @migrations = OwlcodeTech::DB::Migrations::MIGRATIONS();
if ( $class->get_current_migration($dbh) > @migrations ) { if ( $class->get_current_migration($dbh) > @migrations ) {
warn "Something happened there, wrong migration number."; warn "Something happened there, wrong migration number.";
} }

View File

@ -1,4 +1,4 @@
package BurguillosInfo::DB::Migrations; package OwlcodeTech::DB::Migrations;
use v5.34.1; use v5.34.1;

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Posts; package OwlcodeTech::Posts;
use v5.34.1; use v5.34.1;
@ -10,7 +10,7 @@ use feature 'signatures';
use Data::Dumper; use Data::Dumper;
use MIME::Base64; use MIME::Base64;
use BurguillosInfo::Categories; use OwlcodeTech::Categories;
use Const::Fast; use Const::Fast;
use Mojo::DOM; use Mojo::DOM;
@ -18,12 +18,12 @@ use Path::Tiny;
use DateTime::Format::ISO8601; use DateTime::Format::ISO8601;
use DateTime; use DateTime;
use BurguillosInfo::Preview; use OwlcodeTech::Preview;
const my $CURRENT_FILE => __FILE__; const my $CURRENT_FILE => __FILE__;
const my $ROOT_PROJECT => path($CURRENT_FILE)->parent->parent->parent; const my $ROOT_PROJECT => path($CURRENT_FILE)->parent->parent->parent;
const my $PUBLIC_DIR => $ROOT_PROJECT->child('public'); const my $PUBLIC_DIR => $ROOT_PROJECT->child('public');
const my $POSTS_DIR => $ROOT_PROJECT->child('content/posts'); const my $POSTS_DIR => $ROOT_PROJECT->child('content/posts');
my $cached_posts_by_category; my $cached_posts_by_category;
my $cached_posts_by_slug; my $cached_posts_by_slug;
@ -41,9 +41,7 @@ sub _ReturnCacheFilter {
for my $category ( keys %$cached_posts_by_category ) { for my $category ( keys %$cached_posts_by_category ) {
for my $post ( @{ $cached_posts_by_category->{$category} } ) { for my $post ( @{ $cached_posts_by_category->{$category} } ) {
my $date_post; my $date_post;
eval { eval { $date_post = $iso8601->parse_datetime( $post->{date} ); };
$date_post = $iso8601->parse_datetime( $post->{date} );
};
if ($@) { if ($@) {
print Data::Dumper::Dumper $post; print Data::Dumper::Dumper $post;
} }
@ -59,7 +57,7 @@ sub _ReturnCacheFilter {
} }
sub _GeneratePostFromFile ( $self, $post_file ) { sub _GeneratePostFromFile ( $self, $post_file ) {
warn "Bad file $post_file, omiting...", return warn "Bad file $post_file, omiting...", return
if !-f $post_file || $post_file !~ /\.xml$/; if !-f $post_file || $post_file !~ /\.xml$/;
my $dom = Mojo::DOM->new( $post_file->slurp_utf8 ); my $dom = Mojo::DOM->new( $post_file->slurp_utf8 );
my $title = $dom->at(':root > title')->text my $title = $dom->at(':root > title')->text
@ -78,7 +76,7 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
or die "Missing content at $post_file."; or die "Missing content at $post_file.";
my $image_element = $dom->at(':root > img'); my $image_element = $dom->at(':root > img');
my $image; my $image;
my $attributes = $self->_GetAttributes($post_file, $dom); my $attributes = $self->_GetAttributes( $post_file, $dom );
if ( defined $image_element ) { if ( defined $image_element ) {
$image = $image_element->attr->{src}; $image = $image_element->attr->{src};
@ -109,14 +107,15 @@ sub _GeneratePostFromFile ( $self, $post_file ) {
}; };
} }
sub _GetAttributes($self, $post_file, $dom) { sub _GetAttributes ( $self, $post_file, $dom ) {
my $attributes_tag = $dom->at(':root > attributes'); my $attributes_tag = $dom->at(':root > attributes');
my %attributes; my %attributes;
if (defined $attributes_tag) { if ( defined $attributes_tag ) {
my @attribute_list = $attributes_tag->find('attributes > attribute')->map('text')->each; my @attribute_list =
%attributes = map { $attributes_tag->find('attributes > attribute')->map('text')->each;
%attributes = map {
my $identifier = $_; my $identifier = $_;
($identifier => 1); ( $identifier => 1 );
} @attribute_list; } @attribute_list;
} }
return \%attributes; return \%attributes;
@ -128,10 +127,10 @@ sub _GeneratePostCache ($self) {
$cached_posts_by_slug = {}; $cached_posts_by_slug = {};
for my $post_file ( sort { $b cmp $a } $POSTS_DIR->children ) { for my $post_file ( sort { $b cmp $a } $POSTS_DIR->children ) {
my $post = $self->_GeneratePostFromFile($post_file); my $post = $self->_GeneratePostFromFile($post_file);
if (!defined $post) { if ( !defined $post ) {
next; next;
} }
my $category = $post->{category}; my $category = $post->{category};
$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};
@ -150,21 +149,22 @@ sub Retrieve {
} }
my $cache_all_post_categories = {}; my $cache_all_post_categories = {};
sub RetrieveAllPostsForCategory ( $self, $category_name ) { sub RetrieveAllPostsForCategory ( $self, $category_name ) {
if (defined $cache_all_post_categories->{$category_name}) { if ( defined $cache_all_post_categories->{$category_name} ) {
return $cache_all_post_categories->{$category_name}; return $cache_all_post_categories->{$category_name};
} }
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category = $categories->{$category_name}; my $category = $categories->{$category_name};
my $posts = $self->RetrieveDirectPostsForCategory($category_name); my $posts = $self->RetrieveDirectPostsForCategory($category_name);
for my $child_category ( $category->{children}->@* ) { for my $child_category ( $category->{children}->@* ) {
my $child_category_name = $child_category->{slug}; my $child_category_name = $child_category->{slug};
push @$posts, push @$posts,
@{$self->RetrieveDirectPostsForCategory($child_category_name)}; @{ $self->RetrieveDirectPostsForCategory($child_category_name) };
} }
@$posts = sort { @$posts = sort {
DateTime::Format::ISO8601->parse_datetime($b->{date}) <=> DateTime::Format::ISO8601->parse_datetime( $b->{date} )
DateTime::Format::ISO8601->parse_datetime($a->{date}) <=> DateTime::Format::ISO8601->parse_datetime( $a->{date} )
} @$posts; } @$posts;
$cache_all_post_categories->{$category_name} = $posts; $cache_all_post_categories->{$category_name} = $posts;
return $posts; return $posts;
@ -172,7 +172,7 @@ sub RetrieveAllPostsForCategory ( $self, $category_name ) {
sub RetrieveDirectPostsForCategory ( $self, $category_name ) { sub RetrieveDirectPostsForCategory ( $self, $category_name ) {
my ($post_by_category) = $self->Retrieve; my ($post_by_category) = $self->Retrieve;
my $categories = BurguillosInfo::Categories->new->Retrieve; my $categories = OwlcodeTech::Categories->new->Retrieve;
my $category = $categories->{$category_name}; my $category = $categories->{$category_name};
if ( !defined $category ) { if ( !defined $category ) {
die "$category_name category does not exists"; die "$category_name category does not exists";
@ -183,14 +183,14 @@ 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 $site_name = $self->config('site_name');
my $content = $post->{content}; my $title = $post->{title};
my $content = $post->{content};
my $image_file = $post->{image}; my $image_file = $post->{image};
return BurguillosInfo::Preview->Generate($title, $content, $image_file); return OwlcodeTech::Preview->Generate( $title, $content, $image_file,
$site_name );
} }
1; 1;

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Preview; package OwlcodeTech::Preview;
use v5.36.0; use v5.36.0;
@ -23,21 +23,22 @@ const my $SVG_HEIGHT => 627;
const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1000; const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1000;
const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 200; const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 200;
sub Generate($self, $title, $content, $image_file) { sub Generate ( $self, $title, $content, $image_file, $site_name ) {
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, $site_name );
return $self->_SVGToPNG($svg); return $self->_SVGToPNG($svg);
} }
sub _ToPng($self, $image) { sub _ToPng ( $self, $image ) {
if ($image =~ /\.\w+$/) { if ( $image =~ /\.\w+$/ ) {
my $new_image = $image =~ s/\.\w+$/.generated.png/r; my $new_image = $image =~ s/\.\w+$/.generated.png/r;
say $new_image; say $new_image;
if (!-e $new_image) { if ( !-e $new_image ) {
system 'convert', "$image", "$new_image"; system 'convert', "$image", "$new_image";
} }
$image = $new_image; $image = $new_image;
@ -45,7 +46,7 @@ sub _ToPng($self, $image) {
return path($image); return path($image);
} }
sub _GenerateSVGPreviewHeaderBar($self, $svg, $group) { sub _GenerateSVGPreviewHeaderBar ( $self, $svg, $group, $site_name ) {
$group->rect( $group->rect(
x => 0, x => 0,
y => 0, y => 0,
@ -61,10 +62,9 @@ sub _GenerateSVGPreviewHeaderBar($self, $svg, $group) {
style => { fill => '#F8F8FF' } style => { fill => '#F8F8FF' }
); );
my $burguillos_logo_png = path( $self->_ToPng($BURGUILLOS_LOGO) );
my $burguillos_logo_png = path($self->_ToPng($BURGUILLOS_LOGO));
say $burguillos_logo_png; say $burguillos_logo_png;
say ''.$burguillos_logo_png; say '' . $burguillos_logo_png;
$group->image( $group->image(
x => 10, x => 10,
y => 5, y => 5,
@ -77,10 +77,10 @@ sub _GenerateSVGPreviewHeaderBar($self, $svg, $group) {
x => 60, x => 60,
y => 40, y => 40,
style => { 'font-size' => 50, fill => '#f2eb8c' } style => { 'font-size' => 50, fill => '#f2eb8c' }
)->cdata('Burguillos.info'); )->cdata($site_name);
} }
sub _GenerateSVGPreview($self, $title, $content, $image_file) { sub _GenerateSVGPreview ( $self, $title, $content, $image_file, $site_name ) {
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 );
@ -92,7 +92,7 @@ sub _GenerateSVGPreview($self, $title, $content, $image_file) {
} }
); );
$self->_GenerateSVGPreviewHeaderBar($svg, $group); $self->_GenerateSVGPreviewHeaderBar( $svg, $group, $site_name );
my $new_y; my $new_y;
@ -119,7 +119,7 @@ sub _GenerateSVGPreview($self, $title, $content, $image_file) {
return $svg->xmlify; return $svg->xmlify;
} }
sub _SVGToPNG($self, $svg) { sub _SVGToPNG ( $self, $svg ) {
my ( $stdout, $stderr ) = capture { my ( $stdout, $stderr ) = capture {
open my $fh, '|-', qw{convert /dev/stdin png:fd:1}; open my $fh, '|-', qw{convert /dev/stdin png:fd:1};
binmode $fh, 'utf8'; binmode $fh, 'utf8';
@ -130,7 +130,7 @@ sub _SVGToPNG($self, $svg) {
return $stdout; return $stdout;
} }
sub _DivideTextContentInLines($self, $content) { sub _DivideTextContentInLines ( $self, $content ) {
my @content_divided_in_lines = split /\n/, $content; my @content_divided_in_lines = split /\n/, $content;
my @new_content; my @new_content;
my $n_chars_per_line = 70; my $n_chars_per_line = 70;
@ -153,9 +153,10 @@ sub _DivideTextContentInLines($self, $content) {
} }
return \@new_content; return \@new_content;
} }
sub _AttachImageSVG($self, $svg, $image_file) {
sub _AttachImageSVG ( $self, $svg, $image_file ) {
$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 {
system qw/identify -format "%wx%h"/, $image_file; system qw/identify -format "%wx%h"/, $image_file;
}; };

View File

@ -1,4 +1,4 @@
package BurguillosInfo::Tracking; package OwlcodeTech::Tracking;
use v5.34.1; use v5.34.1;
@ -10,7 +10,7 @@ use feature 'signatures';
use JSON; use JSON;
use Const::Fast; use Const::Fast;
use BurguillosInfo::DB; use OwlcodeTech::DB;
my $app; my $app;
@ -22,12 +22,12 @@ EOF
sub new { sub new {
my $class = shift; my $class = shift;
$app = shift; $app = shift;
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
return bless {}, $class; return bless {}, $class;
} }
sub _add_path ( $self, $url ) { sub _add_path ( $self, $url ) {
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
$dbh->do( <<'EOF', undef, $url ); $dbh->do( <<'EOF', undef, $url );
INSERT INTO paths (path) VALUES($1) INSERT INTO paths (path) VALUES($1)
ON CONFLICT (path) DO ON CONFLICT (path) DO
@ -36,7 +36,7 @@ EOF
} }
sub _update_null_last_seen_paths_if_any ($self) { sub _update_null_last_seen_paths_if_any ($self) {
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
$dbh->do( <<'EOF', undef ); $dbh->do( <<'EOF', undef );
UPDATE paths UPDATE paths
@ -53,7 +53,7 @@ EOF
sub _register_request_query ( $self, $remote_address, $user_agent, sub _register_request_query ( $self, $remote_address, $user_agent,
$params_json, $path, $referer ) $params_json, $path, $referer )
{ {
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
$dbh->do( $dbh->do(
<<'EOF', undef, $remote_address, $user_agent, $params_json, $path, $referer ); <<'EOF', undef, $remote_address, $user_agent, $params_json, $path, $referer );
INSERT INTO requests(remote_address, user_agent, params, path, referer) INSERT INTO requests(remote_address, user_agent, params, path, referer)
@ -65,7 +65,7 @@ sub register_request {
my $self = shift; my $self = shift;
my $c = shift; my $c = shift;
my $path = $c->req->url->path; my $path = $c->req->url->path;
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
$self->_add_path($path); $self->_add_path($path);
$self->_update_null_last_seen_paths_if_any(); $self->_update_null_last_seen_paths_if_any();
my $remote_address = $c->tx->remote_address; my $remote_address = $c->tx->remote_address;
@ -82,7 +82,7 @@ sub get_global_data {
my $self = shift; my $self = shift;
my $c = shift; my $c = shift;
my $app = $c->app; my $app = $c->app;
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
my $data = $dbh->selectrow_hashref( <<"EOF", undef ); my $data = $dbh->selectrow_hashref( <<"EOF", undef );
SELECT SELECT
( (
@ -112,7 +112,7 @@ sub get_google_data {
my $self = shift; my $self = shift;
my $c = shift; my $c = shift;
my $app = $c->app; my $app = $c->app;
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
my $data = $dbh->selectall_arrayref(<<"EOF", { Slice => {} } ); my $data = $dbh->selectall_arrayref(<<"EOF", { Slice => {} } );
SELECT paths.path, SELECT paths.path,
( (
@ -150,7 +150,7 @@ sub get_data_for_urls {
my $self = shift; my $self = shift;
my $c = shift; my $c = shift;
my $app = $c->app; my $app = $c->app;
my $dbh = BurguillosInfo::DB->connect($app); my $dbh = OwlcodeTech::DB->connect($app);
my $data = $dbh->selectall_arrayref( <<"EOF", { Slice => {} } ); my $data = $dbh->selectall_arrayref( <<"EOF", { Slice => {} } );
SELECT paths.path, SELECT paths.path,
( (

View File

@ -4,6 +4,6 @@
"db": { "db": {
"database": "example" "database": "example"
}, },
"base_url": "https://burguillos.info", "base_url": "https://owlcode.tech",
"listen": "https:localhost:3555" "listen": "https://localhost:3000"
} }

View File

@ -219,6 +219,7 @@ body {
body div.page-contents nav.mobile-foldable, body div.page-contents nav.mobile-foldable.show { body div.page-contents nav.mobile-foldable, body div.page-contents nav.mobile-foldable.show {
display: none; } display: none; }
body div.page-contents div.description { body div.page-contents div.description {
margin-top: auto;
margin-left: 10%; margin-left: 10%;
margin-right: 10%; } margin-right: 10%; }
body div.page-contents nav.desktop { body div.page-contents nav.desktop {

View File

@ -357,6 +357,7 @@ body {
} }
div.description { div.description {
margin-top: auto;
margin-left: 10%; margin-left: 10%;
margin-right: 10%; margin-right: 10%;
} }

View File

@ -8,4 +8,4 @@ use lib curfile->dirname->sibling('lib')->to_string;
use Mojolicious::Commands; use Mojolicious::Commands;
# Start command line interface for application # Start command line interface for application
Mojolicious::Commands->start_app('BurguillosInfo'); Mojolicious::Commands->start_app('OwlcodeTech');

View File

@ -1,6 +1,6 @@
% use Mojo::Util; % use Mojo::Util;
% use BurguillosInfo::Categories; % use OwlcodeTech::Categories;
% layout 'default', current_category_slug => undef, categories => BurguillosInfo::Categories->new->Retrieve; % layout 'default', current_category_slug => undef, categories => OwlcodeTech::Categories->new->Retrieve;
<div class="description"> <div class="description">
<h2>Esta página no existe.</h2> <h2>Esta página no existe.</h2>
<p>Si un enlace te ha llevado aquí, reporta el error a <a href="mailto:contact@owlcode.tech">los administradores</a>.</p> <p>Si un enlace te ha llevado aquí, reporta el error a <a href="mailto:contact@owlcode.tech">los administradores</a>.</p>

View File

@ -1 +0,0 @@
404.html.ep

View File

@ -0,0 +1,7 @@
% use Mojo::Util;
% use OwlcodeTech::Categories;
% layout 'default', current_category_slug => undef, categories => OwlcodeTech::Categories->new->Retrieve;
<div class="description">
<h2>Esta página no existe.</h2>
<p>Si un enlace te ha llevado aquí, reporta el error a <a href="mailto:contact@owlcode.tech">los administradores</a>.</p>
</div>

View File

@ -4,7 +4,7 @@
% use Mojo::DOM; % use Mojo::DOM;
% use Mojo::Util; % use Mojo::Util;
% %
% use BurguillosInfo::Posts; % use OwlcodeTech::Posts;
% %
% my $category = stash 'category'; % my $category = stash 'category';
% my $attribute = stash 'attribute'; % my $attribute = stash 'attribute';

View File

@ -5,7 +5,7 @@
% use Mojo::DOM; % use Mojo::DOM;
% use Mojo::Util; % use Mojo::Util;
% %
% use BurguillosInfo::Posts; % use OwlcodeTech::Posts;
% %
% my $description_og = '<div>'.$current_category->{description}.'</div>'; % my $description_og = '<div>'.$current_category->{description}.'</div>';
% $description_og = Mojo::DOM->new($description_og)->all_text; % $description_og = Mojo::DOM->new($description_og)->all_text;
@ -26,7 +26,7 @@
<p><a href="<%="/$current_category->{slug}/atributo/$attribute->{identifier}"%>"><%==$attribute->{menu_text}%></a></p> <p><a href="<%="/$current_category->{slug}/atributo/$attribute->{identifier}"%>"><%==$attribute->{menu_text}%></a></p>
% } % }
% } % }
% my ($category_posts) = BurguillosInfo::Posts->new->RetrieveAllPostsForCategory($current_category->{slug}); % my ($category_posts) = OwlcodeTech::Posts->new->RetrieveAllPostsForCategory($current_category->{slug});
%= include 'page/_list_posts', posts => $category_posts; %= include 'page/_list_posts', posts => $category_posts;
<h2>Suscribete a esta categoría.</h2> <h2>Suscribete a esta categoría.</h2>

View File

@ -3,9 +3,9 @@
% use Mojo::DOM; % use Mojo::DOM;
% use Mojo::Util; % use Mojo::Util;
% %
% use BurguillosInfo::Posts; % use OwlcodeTech::Posts;
% use BurguillosInfo::Categories; % use OwlcodeTech::Categories;
% my $categories = BurguillosInfo::Categories->new->Retrieve; % my $categories = OwlcodeTech::Categories->new->Retrieve;
% my $description_og = '<div>'.$post->{content}.'</div>'; % my $description_og = '<div>'.$post->{content}.'</div>';
% $description_og = Mojo::DOM->new($description_og)->all_text; % $description_og = Mojo::DOM->new($description_og)->all_text;
% my $base_url = config 'base_url'; % my $base_url = config 'base_url';