Blio
view release on metacpan or search on metacpan
lib/Blio/Node.pm view on Meta::CPAN
my $site_url = $blio->site_url;
die "Cannot generate Atom Feed without site_url, use --site_url to set it" unless $site_url;
$site_url .= '/' unless $site_url =~m{/$};
my $children = $self->sorted_children(5);
return unless @$children;
my $rfc3339 = DateTime::Format::RFC3339->new();
my $feed = XML::Atom::SimpleFeed->new(
title=>$self->title || 'no title',
author=>$blio->site_author || $0,
link=>{
href=>$site_url.$self->feed_url,
rel=>'self',
},
id=>$site_url.$self->feed_url,
updated=>$rfc3339->format_datetime($children->[0]->date),
);
foreach my $child (@$children) {
next unless $child->parent;
eval {
my @entry = (
title=>$child->title || 'no title',
link=>$site_url.$child->url,
id=>$site_url.$child->url,
updated=>$rfc3339->format_datetime($child->date),
category=>$child->parent->id,
summary=>($child->teaser || ' '),
content=>$child->content,
);
push (@entry,author => $self->author) if $self->author;
if ($child->has_tags) {
foreach my $tag (@{$child->tags}) {
push (@entry, category => $tag->title);
}
}
$feed->add_entry( @entry );
};
if ($@) {
say "ERR $@";
}
}
my $feed_file = $blio->output_dir->file($self->feed_url);
open(my $fh,'>:encoding(UTF-8)',$feed_file->stringify) || die "Cannot write to Atom feed file $feed_file: $!";
$feed->print($fh);
close $fh;
my $utime = $children->[0]->date->epoch;
utime($utime,$utime,$feed_file->stringify);
}
sub register_tags {
my ($self, $blio, $tags ) = @_;
my @tags = split(/\s*,\s*/,$tags);
my $tagindex = $blio->tagindex;
my @tagnodes;
foreach my $tag (@tags) {
my $tagid = $tag;
$tagid=~s/\s/_/g;
$tagid=~s/\W/_/g;
my $tagnode = $blio->nodes_by_url->{"tags/$tagid.html"};
unless ($tagnode) {
$tagnode = Blio::Node->new(
base_dir => $blio->source_dir,
source_file => $0,
id=>$tagid,
url=>"tags/$tagid.html",
title=>$tag,
date=>DateTime->new(year=>1980),
content=>'',
stash=>{
is_tag=>1,
}
);
$blio->nodes_by_url->{$tagnode->url} = $tagnode;
$tagnode->parent($tagindex);
$tagindex->add_child($tagnode);
}
$tagnode->add_child($self);
if ($self->date > $tagnode->date) {
$tagnode->date($self->date);
}
push(@tagnodes,$tagnode);
}
$self->tags(\@tagnodes) if @tagnodes;
}
sub image_by_name {
my ($self, $name) = @_;
my @found = grep { $name eq $_->source_file->basename } @{$self->images};
return $found[0] if @found == 1;
return;
}
sub call_on_image_by_name {
my ($self, $name, $method) = @_;
$method ||= 'url';
my $img = $self->image_by_name($name);
return "cannnot_resolve_image_$name" unless $img;
return $self->relative_root . $img->$method;
}
sub image_by_index {
my ($self, $index) = @_;
return $self->images->[$index - 1];
}
sub call_on_image_by_index {
my ($self, $index, $method) = @_;
my $img = $self->image_by_index($index);
return "cannnot_resolve_image_$index" unless $img;
return $self->relative_root . $img->$method;
}
sub primary_image {
my $self = shift;
my $img;
if ($self->list_image) {
$img = $self->image_by_name( $self->list_image);
}
$img ||= $self->sorted_images->[0];
return $img;
}
sub prev_next_post {
my $self = shift;
( run in 1.328 second using v1.01-cache-2.11-cpan-5735350b133 )