App-html2wp
view release on metacpan or search on metacpan
lib/App/html2wp.pm view on Meta::CPAN
package App::html2wp;
our $DATE = '2020-05-01'; # DATE
our $VERSION = '0.004'; # VERSION
use 5.010001;
use strict;
use warnings;
use Log::ger;
use POSIX qw(strftime);
our %SPEC;
$SPEC{'html2wp'} = {
v => 1.1,
summary => 'Publish HTML document to WordPress as blog post',
description => <<'_',
To use this program, first create `~/html2wp.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`.
then:
% html2wp post1.html
(You should provide blog post title in your HTML in the `<title>` or `<meta
name="title" content="...">`. You can also put categories in `<meta
name="categories" content="cat1,cat2,...">` and tags in `<meta name="tags"
content="tag1,tag2,...">`.)
The above command will create a draft post. To publish directly:
% html2wp post1.html ... --publish
Note that this will also modify your HTML file and insert this element at the
beginning of the document:
<meta name="postid" content="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:
% html2wp post1.html
You can use `--publish` to publish the post, or `--no-publish` to revert it to
draft.
To set more attributes:
% html2wp post1.html ... --comment-status open \ --extra-attr
ping_status=closed --extra-attr sticky=1
Another example, to schedule a post in the future:
% html2wp post1.html --schedule 20301225T00:00:00
_
args => {
proxy => {
schema => 'str*', # XXX url
req => 1,
description => <<'_',
Example: `https://YOURBLOGNAME.wordpress.com/xmlrpc.php`.
lib/App/html2wp.pm view on Meta::CPAN
category => [map {$cat_ids->{$_}} @$post_cats],
post_tag => [map {$tag_ids->{$_}} @$post_tags],
},
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 HTML document
unless ($postid) {
$postid = $call->result;
$html =~ s/^/<meta name="postid" content="$postid">/;
log_info("[api] Inserting POSTID to %s ...", $filename);
File::Slurper::write_text($filename, $html);
}
[200, "OK"];
}
1;
# ABSTRACT: Publish HTML document to WordPress as blog post
__END__
=pod
=encoding UTF-8
=head1 NAME
App::html2wp - Publish HTML document to WordPress as blog post
=head1 VERSION
This document describes version 0.004 of App::html2wp (from Perl distribution App-html2wp), released on 2020-05-01.
=head1 FUNCTIONS
=head2 html2wp
Usage:
html2wp(%args) -> [status, msg, payload, meta]
Publish HTML document to WordPress as blog post.
To use this program, first create C<~/html2wp.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>.
then:
% html2wp post1.html
(You should provide blog post title in your HTML in the C<< E<lt>titleE<gt> >> or C<< E<lt>meta
name="title" content="..."E<gt> >>. You can also put categories in C<< E<lt>meta
name="categories" content="cat1,cat2,..."E<gt> >> and tags in C<< E<lt>meta name="tags"
content="tag1,tag2,..."E<gt> >>.)
The above command will create a draft post. To publish directly:
% html2wp post1.html ... --publish
Note that this will also modify your HTML file and insert this element at the
beginning of the document:
<meta name="postid" content="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:
% html2wp post1.html
You can use C<--publish> to publish the post, or C<--no-publish> to revert it to
draft.
To set more attributes:
% html2wp post1.html ... --comment-status open \ --extra-attr
ping_status=closed --extra-attr sticky=1
Another example, to schedule a post in the future:
% html2wp post1.html --schedule 20301225T00:00:00
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
=over 4
( run in 1.221 second using v1.01-cache-2.11-cpan-39bf76dae61 )