Created
October 3, 2014 14:19
-
-
Save skx/ae316bf8edf674019ee2 to your computer and use it in GitHub Desktop.
Revisions
-
skx created this gist
Oct 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,118 @@ package Chronicle::Plugin::Generate::StaticPages; use strict; use warnings; =begin doc Create a table for the static-pages. =end doc =cut sub on_db_create { my ( $self, %args ) = (@_); # # Create the "pages" table # my $dbh = $args{'dbh'}; $dbh->do( "CREATE TABLE pages (id INTEGER PRIMARY KEY, filename, title, content) " ); } =begin doc Don't generate a blog/tag/archive entry if we have a "page: 1" header, instead insert the post into the static-page table. =end doc =cut sub on_insert { my ( $self, %args ) = (@_); # # The post data and DB-handle. # my $data = $args{ 'data' }; my $dbh = $args{ 'dbh' }; # # Is this a page? # my $page = $data->{ 'page' }; if ( $page ) { print "Treating page as static $data->{'file'}\n"; # # Insert into the static-pages # my $sql = $dbh->prepare( "INSERT INTO pages (title,filename,content) VALUES( ?, ? , ? )" ) or die "Failed to prepare"; $sql->execute( $data->{'title'}, $data->{'output'}, $data->{'body'} ) or die "Failed to insert"; $sql->finish(); # # Don't allow this to be treated as normal. # return undef; } else { # # Allow proceeding as normal # return ($data); } } sub on_generate { my ( $self, %args ) = (@_); my $dbh = $args{ 'dbh' }; my $config = $args{ 'config' }; my $pages = $dbh->prepare("SELECT filename,content,title FROM pages" ) or die "Failed to find static-pages"; $pages->execute() or die "Failed to execute query"; my( $filename,$content,$title); $pages->bind_columns( undef, \$filename, \$content, \$title ); while( $pages->fetch() ) { # # TODO: Load a template and populate it. # # # TODO: Write to disk. # print "Writing Title:$title -> $config->{'output'}/$filename\n"; } $pages->finish(); } 1; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ Subject: About Steve Output: about.html Page: 1 Date: 7th March 2012 This is my static /about.html page.