App-PFT

 view release on metacpan or  search on metacpan

bin/pft-make  view on Meta::CPAN

        nodes_to_anchors($cur_node, $map->tags)
    },
    backlog => sub {
        # param is the number of recent entries depend on template.
        my $n = shift;
        if (!defined $n) {
            $map->blog_exists
        }
        elsif ($n > 0) {
            nodes_to_anchors($cur_node, $map->blog_recent($n))
        }
        else {
            ()
        }
    },
    months_backlog => sub {
        # param is the number of recent months depend on template.
        my $n = shift;
        if (!defined $n) {
            $map->blog_exists
        }
        elsif ($n > 0) {
            nodes_to_anchors($cur_node, $map->months_recent($n))
        }
        else {
            ()
        }
    },
}

my $home_node_slug = PFT::Header::slugify($conf->{site}{home});
my $home_node;

for my $node ($map->nodes) {
    my $content = $node->content;

    if ($content->isa('PFT::Content::Entry')) {
        compile_entry($node, $content)
    }
    elsif ($content->isa('PFT::Content::Blob')) {
        install_blob($node, $content)
    }
}

sub write_file {
    my($data, $path) = @_;

    my $dirname = dirname $path;
    my $enc = $conf->{site}{encoding};
    my $fh;

    make_path $dirname;

    my $temp = File::Spec->catfile($dirname, "." . basename $path);

    open($fh, ">:encoding($enc)", $temp) or croak "Opening $temp: $!";
    print $fh $data;
    close $fh;

    if (-e "$path") {
        # This branch enables an upload-time optimization: if the file
        # created file is exactly the same as the previous compilation (same
        # checksum) we keep the old one.  Rsync will not upload it again.
        my $md5 = Digest::MD5->new;
        $md5->add(encode($enc, $data));
        my $digest_new = $md5->hexdigest;

        open($fh, "<:raw", $path)
            or croak "Opening $path: $!";
        $md5->addfile($fh);
        close $fh;

        if ($digest_new eq $md5->hexdigest) {
            # Unchanged! Leave the old one.
            unlink $temp;
            return;
        }
    }

    rename $temp => $path;
}

sub compile_entry {
    my($node, $content) = @_;

    my $hdr = $node->header;
    my $first = 1;
    foreach ($node->symbols_unres) {
        if ($first) {
            say STDERR "Unresolved links in $node:"
        }

        my($symbol, $reason) = @$_;
        say STDERR "- link: $symbol";
        say STDERR "  reason: $reason";

        undef $first;
    }

    my $is_home;
    if (!$node->virtual && $hdr->slug eq $home_node_slug) {
        die "There should be no doubles" if defined $home_node;
        $home_node = $node;
        $is_home ++;
    }

    if ($hdr->opts->{hide}) {
        print "Node $node will be hidden\n";
        return;
    }

    my %entry_info = (
        site => {
            root => join('/', node_to_root($node)),
            %{$conf->{site}},
        },
        content => {
            title       => $node->title,
            html        => $node->html(sub { node_to_href($node, shift) }),
            tags        => nodes_to_anchors($node, $node->tags),
            date        => sub { node_to_date($node, @_) },
            is_home     => $is_home,
            author      => $node->author,



( run in 1.284 second using v1.01-cache-2.11-cpan-b16cb0d3907 )