App-pod2wp
view release on metacpan or search on metacpan
lib/App/pod2wp.pm view on Meta::CPAN
package App::pod2wp;
our $DATE = '2021-05-25'; # DATE
our $VERSION = '0.005'; # VERSION
use 5.010001;
use strict;
use warnings;
use Log::ger;
use POSIX qw(strftime);
our %SPEC;
sub _pod2html {
require Capture::Tiny;
require File::Temp;
require Pod::Html;
my ($infile) = @_;
my $cachedir = File::Temp::tempdir(CLEANUP => 1);
my ($stdout, $stderr, $exit) = Capture::Tiny::capture(
sub {
Pod::Html::pod2html(
"--infile=$infile",
"--cachedir=$cachedir",
);
}
);
$stdout =~ m!<body>(.+)</body>! and $stdout = $1;
$stdout;
}
$SPEC{'pod2wp'} = {
v => 1.1,
summary => 'Publish POD document to WordPress as blog post',
description => <<'_',
This is like <prog:org2wp> except that instead of Org as the document format,
this program uses POD.
To use this program, first create `~/pod2wp.conf` containing the API
credentials, e.g.:
proxy=https://YOURBLOGNAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
You can also put multiple credentials in the configuration file using profile
sections, e.g.:
[profile=blog1]
proxy=https://YOURBLOG1NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
[profile=blog2]
proxy=https://YOURBLOG2NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
and specify which profile you want using command-line option e.g.
`--config-profile blog1`.
To create a blog post, write your POD document (e.g. in `post1.pod`) using this
format:
=for pod2wp TITLE: Blog post title
=for pod2wp CATEGORY: cat1, cat2
=for pod2wp TAGS: tag1,tag2,tag3
=head1 Some header
Text of your post ...
...
then:
% pod2wp post1.pod
this will create a draft post. To publish directly:
% pod2wp --publish post1.pod
Note that this will also modify your POD file and insert this paragraph at the
top:
=for pod2wp POSTID: 1234
where 1234 is the post ID retrieved from the server when creating the post.
After the post is created, you can update using the same command:
% pod2wp post1.pod
You can use `--publish` to publish the post, or `--no-publish` to revert it to
draft.
To set more attributes:
% pod2wp post1.pod --comment-status open \
--extra-attr ping_status=closed --extra-attr sticky=1
Another example, to schedule a post in the future:
% pod2wp post1.pod --schedule 20301225T00:00:00
lib/App/pod2wp.pm view on Meta::CPAN
comment_status => $args{comment_status},
%{ $args{extra_attrs} // {} },
};
push @xmlrpc_args, $content;
}
if ($dry_run) {
log_info("(DRY_RUN) [api] Create/edit post, content: %s", $content);
return [304, "Dry-run"];
}
log_info("[api] Creating/editing post ...");
log_trace("[api] xmlrpc method=%s, args=%s", $meth, \@xmlrpc_args);
$call = XMLRPC::Lite->proxy($args{proxy})->call($meth, @xmlrpc_args);
return [$call->fault->{faultCode}, "Can't create/edit post: ".$call->fault->{faultString}]
if $call->fault && $call->fault->{faultCode};
}
# insert POSTID to POD document
unless ($postid) {
$postid = $call->result;
$pod =~ s/^/=for pod2wp POSTID: $postid\n\n/;
log_info("[api] Inserting POSTID to %s ...", $filename);
File::Slurper::write_text($filename, $pod);
}
[200, "OK"];
}
1;
# ABSTRACT: Publish POD document to WordPress as blog post
__END__
=pod
=encoding UTF-8
=head1 NAME
App::pod2wp - Publish POD document to WordPress as blog post
=head1 VERSION
This document describes version 0.005 of App::pod2wp (from Perl distribution App-pod2wp), released on 2021-05-25.
=head1 FUNCTIONS
=head2 pod2wp
Usage:
pod2wp(%args) -> [$status_code, $reason, $payload, \%result_meta]
Publish POD document to WordPress as blog post.
This is like L<org2wp> except that instead of Org as the document format,
this program uses POD.
To use this program, first create C<~/pod2wp.conf> containing the API
credentials, e.g.:
proxy=https://YOURBLOGNAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
You can also put multiple credentials in the configuration file using profile
sections, e.g.:
[profile=blog1]
proxy=https://YOURBLOG1NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
[profile=blog2]
proxy=https://YOURBLOG2NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
and specify which profile you want using command-line option e.g.
C<--config-profile blog1>.
To create a blog post, write your POD document (e.g. in C<post1.pod>) using this
format:
=for pod2wp TITLE: Blog post title
=for pod2wp CATEGORY: cat1, cat2
=for pod2wp TAGS: tag1,tag2,tag3
=head1 Some header
Text of your post ...
...
then:
% pod2wp post1.pod
this will create a draft post. To publish directly:
% pod2wp --publish post1.pod
Note that this will also modify your POD file and insert this paragraph at the
top:
=for pod2wp POSTID: 1234
where 1234 is the post ID retrieved from the server when creating the post.
After the post is created, you can update using the same command:
% pod2wp post1.pod
You can use C<--publish> to publish the post, or C<--no-publish> to revert it to
draft.
To set more attributes:
% pod2wp post1.pod --comment-status open \
--extra-attr ping_status=closed --extra-attr sticky=1
Another example, to schedule a post in the future:
% pod2wp post1.pod --schedule 20301225T00:00:00
( run in 0.473 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )