Guest User

blaze-add

a guest
Jan 28th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.31 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # blaze-add - adds a blog post or a page to the BlazeBlogger repository
  4. # Copyright (C) 2008-2011 Jaromir Hradilek
  5.  
  6. # This program is free software: you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation, version 3 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA-
  12. # BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  13. # License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. use strict;
  19. use warnings;
  20. use Digest::MD5;
  21. use File::Basename;
  22. use File::Copy;
  23. use File::Path;
  24. use File::Spec::Functions;
  25. use Getopt::Long;
  26.  
  27. use charnames ':full';
  28. use Unicode::Normalize qw(decompose);
  29.  
  30. # General script information:
  31. use constant NAME => basename($0, '.pl'); # Script name.
  32. use constant VERSION => '1.2.0'; # Script version.
  33.  
  34. # General script settings:
  35. our $blogdir = '.'; # Repository location.
  36. our $editor = ''; # Editor to use.
  37. our $process = 1; # Use processor?
  38. our $verbose = 1; # Verbosity level.
  39.  
  40. # Global variables:
  41. our $chosen = 1; # Available ID guess.
  42. our $reserved = undef; # Reserved ID list.
  43. our $conf = {}; # Configuration.
  44.  
  45. # Command line options:
  46. my $type = 'post'; # Type: post or page.
  47. my $added = ''; # List of added IDs.
  48. my $data = {}; # Post/page meta data.
  49.  
  50. # Set up the __WARN__ signal handler:
  51. $SIG{__WARN__} = sub {
  52. print STDERR NAME . ": " . (shift);
  53. };
  54.  
  55. # Display an error message, and terminate the script:
  56. sub exit_with_error {
  57. my $message = shift || 'An error has occurred.';
  58. my $return_value = shift || 1;
  59.  
  60. # Display the error message:
  61. print STDERR NAME . ": $message\n";
  62.  
  63. # Terminate the script:
  64. exit $return_value;
  65. }
  66.  
  67. # Display a warning message:
  68. sub display_warning {
  69. my $message = shift || 'A warning was requested.';
  70.  
  71. # Display the warning message:
  72. print STDERR "$message\n";
  73.  
  74. # Return success:
  75. return 1;
  76. }
  77.  
  78. # Display usage information:
  79. sub display_help {
  80. my $NAME = NAME;
  81.  
  82. # Display the usage:
  83. print << "END_HELP";
  84. Usage: $NAME [-pqCPV] [-b DIRECTORY] [-E EDITOR] [-a AUTHOR] [-d DATE]
  85. [-t TITLE] [-k KEYWORDS] [-T TAGS] [-u URL] [FILE...]
  86. $NAME -h|-v
  87.  
  88. -b, --blogdir DIRECTORY specify a directory in which the BlazeBlogger
  89. repository is placed
  90. -E, --editor EDITOR specify an external text editor
  91. -t, --title TITLE specify a title
  92. -a, --author AUTHOR specify an author
  93. -d, --date DATE specify a date of publishing
  94. -k, --keywords KEYWORDS specify a comma-separated list of keywords
  95. -T, --tags TAGS specify a comma-separated list of tags
  96. -u, --url URL specify a URL
  97. -p, --page add a page or pages
  98. -P, --post add a blog post or blog posts
  99. -C, --no-processor disable processing the blog post or page with
  100. an external application
  101. -q, --quiet do not display unnecessary messages
  102. -V, --verbose display all messages
  103. -h, --help display this help and exit
  104. -v, --version display version information and exit
  105. END_HELP
  106.  
  107. # Return success:
  108. return 1;
  109. }
  110.  
  111. # Display version information:
  112. sub display_version {
  113. my ($NAME, $VERSION) = (NAME, VERSION);
  114.  
  115. # Display the version:
  116. print << "END_VERSION";
  117. $NAME $VERSION
  118.  
  119. Copyright (C) 2008-2011 Jaromir Hradilek
  120. This program is free software; see the source for copying conditions. It is
  121. distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  122. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PAR-
  123. TICULAR PURPOSE.
  124. END_VERSION
  125.  
  126. # Return success:
  127. return 1;
  128. }
  129.  
  130. # Translate a date to the YYYY-MM-DD form:
  131. sub date_to_string {
  132. my @date = localtime(shift);
  133. return sprintf("%d-%02d-%02d", ($date[5] + 1900), ++$date[4], $date[3]);
  134. }
  135.  
  136. # Read data from the INI file:
  137. sub read_ini {
  138. my $file = shift || die 'Missing argument';
  139.  
  140. # Initialize required variables:
  141. my $hash = {};
  142. my $section = 'default';
  143.  
  144. # Open the file for reading:
  145. open(INI, "$file") or return 0;
  146.  
  147. # Process each line:
  148. while (my $line = <INI>) {
  149. # Parse the line:
  150. if ($line =~ /^\s*\[([^\]]+)\]\s*$/) {
  151. # Change the section:
  152. $section = $1;
  153. }
  154. elsif ($line =~ /^\s*(\S+)\s*=\s*(\S.*)$/) {
  155. # Add the option to the hash:
  156. $hash->{$section}->{$1} = $2;
  157. }
  158. }
  159.  
  160. # Close the file:
  161. close(INI);
  162.  
  163. # Return the result:
  164. return $hash;
  165. }
  166.  
  167. # Vyhodi diakritiku
  168. sub undiacritic {
  169. my $characters = shift;
  170. if ( !$characters ) { return $characters; }
  171.  
  172. my $undiacritics = q{};
  173.  
  174. $characters = decompose($characters);
  175. $characters =~ s/\p{NonspacingMark}//gxms;
  176.  
  177. for my $character ( split //xms, $characters ) {
  178. my $name = charnames::viacode( ord $character );
  179. $name =~ s/\s WITH \s .+ \z//xms;
  180. $undiacritics .= chr charnames::vianame( $name );
  181. }
  182. return $undiacritics;
  183.  
  184. }
  185.  
  186. # Write data to the INI file:
  187. sub write_ini {
  188. my $file = shift || 'Missing argument';
  189. my $hash = shift || 'Missing argument';
  190.  
  191. # Open the file for writing:
  192. open(INI, ">$file") or return 0;
  193.  
  194. # Process each section:
  195. foreach my $section (sort(keys(%$hash))) {
  196. # Write the section header to the file::
  197. print INI "[$section]\n";
  198.  
  199. # Process each option in the section:
  200. foreach my $option (sort(keys(%{$hash->{$section}}))) {
  201. # Write the option and its value to the file:
  202. print INI " $option = $hash->{$section}->{$option}\n";
  203. }
  204. }
  205.  
  206. # Close the file:
  207. close(INI);
  208.  
  209. # Return success:
  210. return 1;
  211. }
  212.  
  213. # Read the content of the configuration file:
  214. sub read_conf {
  215. # Prepare the file name:
  216. my $file = catfile($blogdir, '.blaze', 'config');
  217.  
  218. # Parse the file:
  219. if (my $conf = read_ini($file)) {
  220. # Return the result:
  221. return $conf;
  222. }
  223. else {
  224. # Report failure:
  225. display_warning("Unable to read the configuration.");
  226.  
  227. # Return an empty configuration:
  228. return {};
  229. }
  230. }
  231.  
  232. # Make proper URL from the string while stripping all forbidden characters:
  233. sub make_url {
  234. my $url = shift || return '';
  235.  
  236. # Strip forbidden characters:
  237. $url =~ s/[^\w\s\-]//g;
  238.  
  239. # Strip trailing spaces:
  240. $url =~ s/\s+$//;
  241.  
  242. # Substitute spaces:
  243. $url =~ s/\s+/-/g;
  244.  
  245. # Return the result:
  246. return $url;
  247. }
  248.  
  249.  
  250.  
  251. # Look for erroneous or missing header data:
  252. sub check_header {
  253. my $data = shift || die 'Missing argument';
  254. my $id = shift || die 'Missing argument';
  255. my $type = shift || die 'Missing argument';
  256.  
  257. # Check whether the title is specified:
  258. unless ($data->{header}->{title}) {
  259. # Display the appropriate warning:
  260. display_warning("Missing title in the $type with ID $id.");
  261. }
  262.  
  263. # Check whether the author is specified:
  264. unless ($data->{header}->{author}) {
  265. # Report the missing author:
  266. display_warning("Missing author in the $type with ID $id.");
  267. }
  268.  
  269. # Check whether the date is specified:
  270. if (my $date = $data->{header}->{date}) {
  271. # Check whether the format is valid:
  272. unless ($date =~ /\d{4}-[01]\d-[0-3]\d/) {
  273. # Report the invalid date:
  274. display_warning("Invalid date in the $type with ID $id.");
  275. }
  276. }
  277. else {
  278. # Report the missing date:
  279. display_warning("Missing date in the $type with ID $id.");
  280. }
  281.  
  282. # Check whether the tags are specified:
  283. if (my $tags = $data->{header}->{tags}) {
  284. # Make all tags lower case:
  285. $tags = lc($tags);
  286.  
  287. # Strip superfluous characters:
  288. $tags =~ s/\s{2,}/ /g;
  289. $tags =~ s/\s+$//;
  290. $tags =~ s/^,+|,+$//g;
  291.  
  292. # Remove duplicates:
  293. my %temp = map { $_, 1 } split(/,+\s*/, $tags);
  294.  
  295. # Make sure none of the tags will have an empty URL:
  296. foreach my $tag (keys %temp) {
  297. # Derive the URL from the tag name:
  298. my $tag_url = make_url($tag);
  299.  
  300. # Make sure the result is not empty:
  301. unless ($tag_url) {
  302. # Report the missing tag URL:
  303. display_warning("Unable to derive the URL from the tag `$tag'. " .
  304. "Please use ASCII characters only.");
  305. }
  306. }
  307. }
  308.  
  309. # Check whether the URL is specified:
  310. if (my $url = $data->{header}->{url}) {
  311. # Check whether it contains forbidden characters:
  312. if ($url =~ /[^\w\-]/) {
  313. # Report the invalid URL:
  314. display_warning("Invalid URL in the $type with ID $id." .
  315. ($url ? "" : " It will be derived from the title."));
  316. }
  317. }
  318.  
  319. # Make sure the URL can be derived from the title if necessary:
  320. unless ($data->{header}->{url}) {
  321. # Derive the URL from the post or page title:
  322. my $title = $data->{header}->{title} || '';
  323. my $url = make_url(lc($title));
  324.  
  325. # Check whether the URL is not empty:
  326. unless ($url) {
  327. # Report the missing URL:
  328. display_warning("Unable to derive the URL in the $type with ID $id. " .
  329. "Please specify it yourself.");
  330. }
  331. }
  332.  
  333. # Return success:
  334. return 1;
  335. }
  336.  
  337. # Create a record from a single file:
  338. sub save_record {
  339. my $file = shift || die 'Missing argument';
  340. my $id = shift || die 'Missing argument';
  341. my $type = shift || 'post';
  342. my $data = shift || {};
  343.  
  344. # Initialize required variables:
  345. my $line = '';
  346.  
  347. # Prepare the record directory names:
  348. my $head_dir = catdir($blogdir, '.blaze', "${type}s", 'head');
  349. my $body_dir = catdir($blogdir, '.blaze', "${type}s", 'body');
  350. my $raw_dir = catdir($blogdir, '.blaze', "${type}s", 'raw');
  351.  
  352. # Prepare the record file names:
  353. my $head = catfile($head_dir, $id);
  354. my $body = catfile($body_dir, $id);
  355. my $raw = catfile($raw_dir, $id);
  356.  
  357. # Prepare the temporary file names:
  358. my $temp_head = catfile($blogdir, '.blaze', 'temp.head');
  359. my $temp_body = catfile($blogdir, '.blaze', 'temp.body');
  360. my $temp_raw = catfile($blogdir, '.blaze', 'temp.raw');
  361.  
  362. # Read required data from the configuration:
  363. my $processor = $conf->{core}->{processor};
  364.  
  365. # Check whether the processor is enabled:
  366. if ($process) {
  367. # Substitute placeholders with actual file names:
  368. $processor =~ s/%in%/$temp_raw/ig;
  369. $processor =~ s/%out%/$temp_body/ig;
  370. }
  371.  
  372. # Open the input file for reading:
  373. open(FIN, "$file") or return 0;
  374.  
  375. # Parse the file header:
  376. while ($line = <FIN>) {
  377. # The header ends with the first line not beginning with "#":
  378. last unless $line =~ /^#/;
  379.  
  380. # Collect data for the record header:
  381. if ($line =~ /(title|author|date|keywords|tags|url):\s*(\S.*)$/) {
  382. $data->{header}->{$1} = $2;
  383. }
  384. }
  385.  
  386. # Look for erroneous or missing header data:
  387. check_header($data, $id, $type);
  388.  
  389. # Write the record header to the temporary file:
  390. write_ini($temp_head, $data) or return 0;
  391.  
  392. # Open the proper output file:
  393. open(FOUT, '>' . ($process ? $temp_raw : $temp_body)) or return 0;
  394.  
  395. # Write the last read line to the output file:
  396. print FOUT $line if $line;
  397.  
  398. # Add the rest of the file content to the output file:
  399. while ($line = <FIN>) {
  400. print FOUT $line;
  401. }
  402.  
  403. # Close all opened files:
  404. close(FIN);
  405. close(FOUT);
  406.  
  407. # Check whether the processor is enabled:
  408. if ($process) {
  409. # Process the raw input file:
  410. unless (system("$processor") == 0) {
  411. # Report failure and exit:
  412. exit_with_error("Unable to run `$processor'.", 1);
  413. }
  414.  
  415. # Make sure the raw record directory exists:
  416. unless (-d $raw_dir) {
  417. # Create the target directory tree:
  418. eval { mkpath($raw_dir, 0); };
  419.  
  420. # Make sure the directory creation was successful:
  421. exit_with_error("Creating the directory tree: $@", 13) if $@;
  422. }
  423.  
  424. # Create the raw record file:
  425. move($temp_raw, $raw) or return 0;
  426. }
  427.  
  428. # Make sure the record body and header directories exist:
  429. unless (-d $head_dir && -d $body_dir) {
  430. # Create the target directory tree:
  431. eval { mkpath([$head_dir, $body_dir], 0); };
  432.  
  433. # Make sure the directory creation was successful:
  434. exit_with_error("Creating the directory tree: $@", 13) if $@;
  435. }
  436.  
  437. # Create the record body and header files:
  438. move($temp_body, $body) or return 0;
  439. move($temp_head, $head) or return 0;
  440.  
  441. # Return success:
  442. return 1;
  443. }
  444.  
  445. # Collect reserved post or page IDs:
  446. sub collect_ids {
  447. my $type = shift || 'post';
  448.  
  449. # Prepare the post or page directory name:
  450. my $head = catdir($blogdir, '.blaze', "${type}s", 'head');
  451.  
  452. # Open the header directory:
  453. opendir(HEADS, $head) or return 0;
  454.  
  455. # Build a list of used IDs:
  456. my @used = grep {! /^\.\.?$/ } readdir(HEADS);
  457.  
  458. # Close the directory:
  459. closedir(HEADS);
  460.  
  461. # Return the sorted result:
  462. return sort {$a <=> $b} @used;
  463. }
  464.  
  465. # Return the first unused ID:
  466. sub choose_id {
  467. my $type = shift || 'post';
  468.  
  469. # Get the list of reserved IDs unless already done:
  470. @$reserved = collect_ids($type) unless defined $reserved;
  471.  
  472. # Iterate through the used IDs:
  473. while (my $used = shift(@$reserved)) {
  474. # Check whether the candidate ID is really free:
  475. if ($chosen == $used) {
  476. # Try the next ID:
  477. $chosen++;
  478. }
  479. else {
  480. # Push the last checked ID back to the list:
  481. unshift(@$reserved, $used);
  482.  
  483. # Exit the loop:
  484. last;
  485. }
  486. }
  487.  
  488. # Return the result, and increase the next candidate number:
  489. return $chosen++;
  490. }
  491.  
  492. # Add given files to the repository:
  493. sub add_files {
  494. my $type = shift || 'post';
  495. my $data = shift || {};
  496. my $files = shift || die 'Missing argument';
  497.  
  498. # Initialize required variables:
  499. my @list = ();
  500.  
  501. # Process each file:
  502. foreach my $file (@{$files}) {
  503. # Get the first available ID:
  504. my $id = choose_id($type);
  505.  
  506. # Save the record:
  507. save_record($file, $id, $type, $data)
  508. and push(@list, $id)
  509. or display_warning("Unable to add $file.");
  510. }
  511.  
  512. # Return the list of added IDs:
  513. return @list;
  514. }
  515.  
  516. # Add a new record to the repository:
  517. sub add_new {
  518. my $type = shift || 'post';
  519. my $data = shift || {};
  520.  
  521. # Decide which editor to use:
  522. my $edit = $editor || $conf->{core}->{editor} || $ENV{EDITOR} || 'vi';
  523.  
  524. # Prepare the data for the temporary file header:
  525. my $title = $data->{header}->{title} || '';
  526. my $author = $data->{header}->{author} || $conf->{user}->{nickname}
  527. || $conf->{user}->{name}
  528. || 'admin';
  529. my $date = $data->{header}->{date} || date_to_string(time);
  530. my $keywords = $data->{header}->{keywords} || '';
  531. my $tags = $data->{header}->{tags} || '';
  532. my $url = $data->{header}->{url} || '';
  533.  
  534. # Declare other necessary variables:
  535. my $head;
  536.  
  537. # Prepare the temporary file header:
  538. if ($type eq 'post') {
  539. # Use the variant for a blog post:
  540. $head = << "END_POST_HEADER";
  541. # This and the following lines beginning with '#' are the blog post header.
  542. # Please take your time and replace these options with desired values. Just
  543. # remember that the date has to be in the YYYY-MM-DD form, tags are a comma
  544. # separated list of categories the post (pages ignore these) belong to, and
  545. # the url, if provided, should consist of alphanumeric characters, hyphens
  546. # and underscores only. Specifying your own url is especially recommended
  547. # in case you use non-ASCII characters in your blog post title.
  548. #
  549. # title: $title
  550. # author: $author
  551. # date: $date
  552. # keywords: $keywords
  553. # tags: $tags
  554. # url: $url
  555. #
  556. # The header ends here. The rest is the content of your blog post.
  557.  
  558. END_POST_HEADER
  559. }
  560. else {
  561. # Use the variant for a page:
  562. $head = << "END_PAGE_HEADER";
  563. # This and the following lines beginning with '#' are the page header. Ple-
  564. # ase take your time and replace these options with desired values. Just
  565. # remember that the date has to be in the YYYY-MM-DD form, and the url, if
  566. # provided, should consist of alphanumeric characters, hyphens and under-
  567. # scores only. Specifying your own url is especially recommended in case
  568. # you use non-ASCII characters in your page title.
  569. #
  570. # title: $title
  571. # date: $date
  572. # keywords: $keywords
  573. # url: $url
  574. #
  575. # The header ends here. The rest is the content of your page.
  576.  
  577. END_PAGE_HEADER
  578. }
  579.  
  580. # Prepare the temporary file name:
  581. my $temp = catfile($blogdir, '.blaze', 'temp');
  582.  
  583. # Open the file for writing:
  584. if (open(FILE, ">$temp")) {
  585. # Write the temporary file:
  586. print FILE $head;
  587.  
  588. # Close the file:
  589. close(FILE);
  590. }
  591. else {
  592. # Report failure:
  593. display_warning("Unable to create the temporary file.");
  594.  
  595. # Return failure:
  596. return 0;
  597. }
  598.  
  599. # Open the temporary file in the external editor:
  600. unless (system("$edit $temp") == 0) {
  601. # Report failure and exit:
  602. exit_with_error("Unable to run `$edit'.", 1);
  603. }
  604.  
  605. # Open the file for reading:
  606. if (open(FILE, "$temp")) {
  607. # Set the input/output handler to "binmode":
  608. binmode(FILE);
  609.  
  610. # Count the checksums:
  611. my $before = Digest::MD5->new->add($head)->hexdigest;
  612. my $after = Digest::MD5->new->addfile(*FILE)->hexdigest;
  613.  
  614. # Close the file:
  615. close(FILE);
  616.  
  617. # Compare the checksums:
  618. if ($before eq $after) {
  619. # Report abortion:
  620. display_warning("The file has not been changed: aborting.");
  621.  
  622. # Return success:
  623. exit 0;
  624. }
  625. }
  626.  
  627. # Add the file to the repository:
  628. my @list = add_files($type, $data, [ $temp ]);
  629.  
  630. # Remove the temporary file:
  631. unlink $temp;
  632.  
  633. # Return the record ID:
  634. return shift(@list);
  635. }
  636.  
  637. # Add the event to the log:
  638. sub add_to_log {
  639. my $text = shift || 'Something miraculous has just happened!';
  640.  
  641. # Prepare the log file name:
  642. my $file = catfile($blogdir, '.blaze', 'log');
  643.  
  644. # Open the log file for appending:
  645. open(LOG, ">>$file") or return 0;
  646.  
  647. # Write the event to the file:
  648. print LOG localtime(time) . " - $text\n";
  649.  
  650. # Close the file:
  651. close(LOG);
  652.  
  653. # Return success:
  654. return 1;
  655. }
  656.  
  657. # Set up the option parser:
  658. Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case', 'bundling');
  659.  
  660. # Process command line options:
  661. GetOptions(
  662. 'help|h' => sub { display_help(); exit 0; },
  663. 'version|v' => sub { display_version(); exit 0; },
  664. 'page|pages|p' => sub { $type = 'page'; },
  665. 'post|posts|P' => sub { $type = 'post'; },
  666. 'no-processor|C' => sub { $process = 0; },
  667. 'quiet|q' => sub { $verbose = 0; },
  668. 'verbose|V' => sub { $verbose = 1; },
  669. 'blogdir|b=s' => sub { $blogdir = $_[1]; },
  670. 'editor|E=s' => sub { $editor = $_[1]; },
  671. 'title|t=s' => sub { $data->{header}->{title} = $_[1]; },
  672. 'author|a=s' => sub { $data->{header}->{author} = $_[1]; },
  673. 'date|d=s' => sub { $data->{header}->{date} = $_[1]; },
  674. 'keywords|k=s' => sub { $data->{header}->{keywords} = $_[1]; },
  675. 'tags|tag|T=s' => sub { $data->{header}->{tags} = $_[1]; },
  676. 'url|u=s' => sub { $data->{header}->{url} = $_[1]; },
  677. );
  678.  
  679. # Check whether the repository is present, no matter how naive this method
  680. # actually is:
  681. exit_with_error("Not a BlazeBlogger repository! Try `blaze-init' first.",1)
  682. unless (-d catdir($blogdir, '.blaze'));
  683.  
  684. # Read the configuration file:
  685. $conf = read_conf();
  686.  
  687. # Check whether the processor is enabled in the configuration:
  688. if ($process && (my $processor = $conf->{core}->{processor})) {
  689. # Make sure the processor specification is valid:
  690. exit_with_error("Invalid core.processor option.", 1)
  691. unless ($processor =~ /%in%/i && $processor =~ /%out%/i);
  692. }
  693. else {
  694. # Disable the processor:
  695. $process = 0;
  696. }
  697.  
  698. # Check whether a file is supplied:
  699. if (scalar(@ARGV) == 0) {
  700. # Add a new record to the repository:
  701. $added = add_new($type, $data)
  702. or exit_with_error("Cannot add the $type to the repository.", 13);
  703. }
  704. else {
  705. # Add given files to the repository:
  706. my @list = add_files($type, $data, \@ARGV)
  707. or exit_with_error("Cannot add the ${type}s to the repository.", 13);
  708.  
  709. # Prepare the list of successfully added IDs:
  710. $added = join(', ', sort(@list));
  711. $added =~ s/, ([^,]+)$/ and $1/;
  712. }
  713.  
  714. # Log the event:
  715. add_to_log("Added the $type with ID $added.")
  716. or display_warning("Unable to log the event.");
  717.  
  718. # Report success:
  719. print "Successfully added the $type with ID $added.\n" if $verbose;
  720.  
  721. # Return success:
  722. exit 0;
  723.  
  724. __END__
  725.  
  726. =head1 NAME
  727.  
  728. blaze-add - adds a blog post or a page to the BlazeBlogger repository
  729.  
  730. =head1 SYNOPSIS
  731.  
  732. B<blaze-add> [B<-pqCPV>] [B<-b> I<directory>] [B<-E> I<editor>]
  733. [B<-a> I<author>] [B<-d> I<date>] [B<-t> I<title>] [B<-k> I<keywords>]
  734. [B<-T> I<tags>] [B<-u> I<url>] [I<file>...]
  735.  
  736. B<blaze-add> B<-h>|B<-v>
  737.  
  738. =head1 DESCRIPTION
  739.  
  740. B<blaze-add> adds a blog post or a page to the BlazeBlogger repository. If
  741. a I<file> is supplied, it adds the content of that file, otherwise an
  742. external text editor is opened for you. Note that there are several special
  743. forms and placeholders that can be used in the text, and that will be
  744. replaced with a proper data when the blog is generated.
  745.  
  746. =head2 Special Forms
  747.  
  748. =over
  749.  
  750. =item B<< <!-- break --> >>
  751.  
  752. A mark to delimit a blog post synopsis.
  753.  
  754. =back
  755.  
  756. =head2 Placeholders
  757.  
  758. =over
  759.  
  760. =item B<%root%>
  761.  
  762. A relative path to the root directory of the blog.
  763.  
  764. =item B<%home%>
  765.  
  766. A relative path to the index page of the blog.
  767.  
  768. =item B<%page[>I<id>B<]%>
  769.  
  770. A relative path to a page with the supplied I<id>.
  771.  
  772. =item B<%post[>I<id>B<]%>
  773.  
  774. A relative path to a blog post with the supplied I<id>.
  775.  
  776. =item B<%tag[>I<name>B<]%>
  777.  
  778. A relative path to a tag with the supplied I<name>.
  779.  
  780. =back
  781.  
  782. =head1 OPTIONS
  783.  
  784. =over
  785.  
  786. =item B<-b> I<directory>, B<--blogdir> I<directory>
  787.  
  788. Allows you to specify a I<directory> in which the BlazeBlogger repository
  789. is placed. The default option is a current working directory.
  790.  
  791. =item B<-E> I<editor>, B<--editor> I<editor>
  792.  
  793. Allows you to specify an external text I<editor>. When supplied, this
  794. option overrides the relevant configuration option.
  795.  
  796. =item B<-t> I<title>, B<--title> I<title>
  797.  
  798. Allows you to specify the I<title> of a blog post or page.
  799.  
  800. =item B<-a> I<author>, B<--author> I<author>
  801.  
  802. Allows you to specify the I<author> of a blog post or page.
  803.  
  804. =item B<-d> I<date>, B<--date> I<date>
  805.  
  806. Allows you to specify the I<date> of publishing of a blog post or page.
  807.  
  808. =item B<-k> I<keywords>, B<--keywords> I<keywords>
  809.  
  810. Allows you to specify a comma-separated list of I<keywords> attached to
  811. a blog post or page.
  812.  
  813. =item B<-T> I<tags>, B<--tags> I<tags>
  814.  
  815. Allows you to supply a comma-separated list of I<tags> attached to a blog
  816. post.
  817.  
  818. =item B<-u> I<url>, B<--url> I<url>
  819.  
  820. Allows you to specify the I<url> of a blog post or page. Allowed characters
  821. are letters, numbers, hyphens, and underscores.
  822.  
  823. =item B<-p>, B<--page>, B<--pages>
  824.  
  825. Tells B<blaze-add> to add a page or pages.
  826.  
  827. =item B<-P>, B<--post>, B<--posts>
  828.  
  829. Tells B<blaze-add> to add a blog post or blog posts. This is the default
  830. option.
  831.  
  832. =item B<-C>, B<--no-processor>
  833.  
  834. Disables processing a blog post or page with an external application. For
  835. example, if you use Markdown to convert the lightweight markup language to
  836. the valid HTML output, this will enable you to write this particular post
  837. in plain HTML directly.
  838.  
  839. =item B<-q>, B<--quiet>
  840.  
  841. Disables displaying of unnecessary messages.
  842.  
  843. =item B<-V>, B<--verbose>
  844.  
  845. Enables displaying of all messages. This is the default option.
  846.  
  847. =item B<-h>, B<--help>
  848.  
  849. Displays usage information and exits.
  850.  
  851. =item B<-v>, B<--version>
  852.  
  853. Displays version information and exits.
  854.  
  855. =back
  856.  
  857. =head1 ENVIRONMENT
  858.  
  859. =over
  860.  
  861. =item B<EDITOR>
  862.  
  863. Unless the B<core.editor> option is set, BlazeBlogger tries to use
  864. system-wide settings to decide which editor to use.
  865.  
  866. =back
  867.  
  868. =head1 EXAMPLE USAGE
  869.  
  870. Write a new blog post in an external text editor:
  871.  
  872. ~]$ blaze-add
  873.  
  874. Add a new blog post from a file:
  875.  
  876. ~]$ blaze-add new_packages.txt
  877. Successfully added the post with ID 10.
  878.  
  879. Write a new page in an external text editor:
  880.  
  881. ~]$ blaze-add -p
  882.  
  883. Write a new page in B<nano>:
  884.  
  885. ~]$ blaze-add -p -E nano
  886.  
  887. =head1 SEE ALSO
  888.  
  889. B<blaze-init>(1), B<blaze-config>(1), B<blaze-edit>(1), B<blaze-remove>(1),
  890. B<blaze-make>(1)
  891.  
  892. =head1 BUGS
  893.  
  894. To report a bug or to send a patch, please, add a new issue to the bug
  895. tracker at <http://code.google.com/p/blazeblogger/issues/>, or visit the
  896. discussion group at <http://groups.google.com/group/blazeblogger/>.
  897.  
  898. =head1 COPYRIGHT
  899.  
  900. Copyright (C) 2008-2011 Jaromir Hradilek
  901.  
  902. This program is free software; see the source for copying conditions. It is
  903. distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  904. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  905. PARTICULAR PURPOSE.
  906.  
  907. =cut
Advertisement
Add Comment
Please, Sign In to add comment