App-PFT
view release on metacpan or search on metacpan
bin/pft-init view on Meta::CPAN
#!/usr/bin/perl
#
# Copyright 2014-2019 - Giovanni Simoni
#
# This file is part of PFT.
#
# PFT is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# PFT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with PFT. If not, see <http://www.gnu.org/licenses/>.
=encoding utf8
=head1 NAME
pft init - Initialize a PFT Site
=head1 SYNOPSIS
B<pft init> [I<options>]
=head1 DESCRIPTION
This command initializes a PFT site in the current directory. It generates a
configuration file named C<pft.yaml> and it creates the following filesystem
structure (see L<pft(1)>).
A generic configuration skeleton is provided by default, and can be modified
by editing the C<pft.yaml> configuration file. Each option explained in
this manual page corresponds to an equally named setting in the C<pft.yaml>
file.
=cut
# NOTE: Documentation continues with auto-generated options from PFT::Conf
# at the end of this file (from "=head1 OPTIONS" to the subsequent
# "# END # AUTOGEN" comment).
#
# Generate again if needed with:
#
# perl -CO -MPFT::Conf=pod_autogen -wE 'say pod_autogen'
#
use strict;
use warnings;
use utf8;
use v5.16;
use feature 'say';
use PFT::Conf;
use PFT::Tree;
use PFT::Header;
use Encode;
use Encode::Locale;
use File::Spec;
use File::Copy;
use File::ShareDir;
use File::Basename qw/basename/;
use Cwd;
use Getopt::Long;
Getopt::Long::Configure qw/bundling/;
use Pod::Usage;
use App::PFT;
my %opts = (home => 1);
GetOptions(
PFT::Conf::wire_getopt(\my %conf_opts),
'help|h!' => sub {
pod2usage
-exitval => 0,
-verbose => 2,
-input => App::PFT::help_of 'init',
},
) or exit 1;
if (my $root = PFT::Conf::locate) {
say STDERR 'Configuration exists: ', $root;
exit 1;
}
my $conf = PFT::Conf->new_getopt(\%conf_opts);
$conf->save_to(my $root = Cwd::cwd);
my $tree = PFT::Tree->new($root, {create => 1});
my $home = $tree->content->new_entry(PFT::Header->new(
title => $conf->{site}{home},
author => $conf->{site}{author},
));
$home->open('a') unless $home->exists;
my $glob = File::Spec->catdir(
File::ShareDir::module_dir('App::PFT'),
'templates',
'*',
);
foreach (glob encode(locale_fs => $glob)) {
my $outfn = File::Spec->catfile(
encode(locale_fs => $tree->dir_templates),
basename($_)
);
open my $in, '< :encoding(UTF-8)', $_ or do {
say STDERR 'Cannot open ', decode(locale_fs => $_), ": $!";
exit 1;
};
open my $out, '> :encoding(locale_fs)', $outfn or do {
say STDERR 'Cannot open ', decode(locale_fs => $outfn), ": $!";
exit 1;
};
print $out (<$in>);
close $in;
close $out;
};
=head1 CONFIGURATION OPTIONS
=over
=item B<--publish-host>=I<HOST>
Remote host where to publish (see L<pft-pub(1)>).
Defaults to C<example.org>.
=item B<--publish-method>=I<NAME>
Method used for publishing (see L<pft-pub(1)>).
Defaults to C<rsync+ssh>.
=item B<--publish-path>=I<PATH>
Remote path on publishing host (see L<pft-pub(1)>).
Defaults to C</home/$USER/public_html>, as by tradition.
=item B<--publish-port>=I<PORT>
Port for connection on publishing host (see L<pft-pub(1)>).
Defaults to C<22>.
=item B<--publish-user>=I<USER>
User login on publishing host (see L<pft-pub(1)>).
Defaults to $USER (environment variable).
=item B<--site-author>=I<USER>
Global Author, can be overriden by individual entries.
Defaults to C<$USER> (environment variable).
=item B<--site-encoding>=I<ENC>
Charset of the generated web pages.
Defaults to what is defined by L<locale(1)>.
=item B<--site-feed-description>=I<DESC>
Description of the channel (C<E<lt>descriptionE<gt>> in the XML).
Defaults to C<News from a PFT website>.
=item B<--site-feed-length>=I<N>
Number of most recent blog entries to list in the RSS feed.
Defaults to C<10>.
=item B<--site-feed-path>=I<PATH>
( run in 0.352 second using v1.01-cache-2.11-cpan-a1f116cd669 )