WriteMakefile(
NAME => 'Gruntmaster::Page',
VERSION_FROM => 'lib/Gruntmaster/Page.pm',
- EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-contest gruntmaster-problem gruntmaster-job/ ],
+ EXE_FILES => [ qw/gruntmaster-genarticle gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-contest gruntmaster-problem gruntmaster-job/ ],
ABSTRACT_FROM => 'lib/Gruntmaster/Page.pm',
AUTHOR => 'Marius Gavrilescu <marius@ieval.ro>',
MIN_PERL_VERSION => '5.14.0',
dynsub "set_${name}_$key", sub ($$) { HSET cp . "$name.$_[0]", $key, $_[1] };
}
+ dynsub "edit_$name", sub {
+ my ($key, %values) = @_;
+ HMSET cp . "$name.$key", %values;
+ };
+
dynsub "insert_$name", sub {
my ($key, %values) = @_;
SADD cp . $name, $key or return;
use Fcntl qw/:flock/;
use File::Basename qw/fileparse/;
use File::Path qw/make_path/;
-use File::Slurp qw/write_file/;
+use File::Slurp qw/read_file write_file/;
use IO::Compress::Gzip qw/gzip/;
use IO::File;
use Gruntmaster::Data;
}
sub generate{
- my ($path) = @_;
+ my ($path, $topic) = @_;
my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/;
my ($basename, $directories) = fileparse $path_noext;
make_path $directories;
flock my $lockfh = IO::File->new("<$path_noext.var"), LOCK_EX;
open my $typemap, ">$path_noext.var.new";
say $typemap "URI: $basename\n";
- for my $gen (@generators) {
- my ($regex, $generator) = @$gen;
- next unless $path_noext =~ $regex;
+
+ my $fill_typemap = sub {
for my $lang (@{LANGUAGES()}) {
- my $page = $generator->generate($path, $lang);
+ my $page = $_[0]->($lang);
write_file "$path_noext.$lang.$ext.new", $page;
say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
gzip \$page => "$path_noext.$lang.gz.$ext.new", Minimal => 1;
say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
}
- last
+ };
+
+ if ($topic eq 'genpage') {
+ for my $gen (@generators) {
+ my ($regex, $generator) = @$gen;
+ next unless $path_noext =~ $regex;
+ $fill_typemap->(sub { $generator->generate($path, $_[0]) });
+ last
+ }
+ } else {
+ my $get_article = sub {
+ my $article = read_file "$ENV{GRUNTMASTER_ARTICLE_ROOT}/$basename.$_[0]";
+ my $title = read_file "$ENV{GRUNTMASTER_ARTICLE_ROOT}/$basename.$_[0].title";
+ Gruntmaster::Page::Base::header($_[0], $title) . $article . Gruntmaster::Page::Base::footer($_[0])
+ };
+
+ $fill_typemap->($get_article);
}
for my $lang (@{LANGUAGES()}) {
write_file "log/src/$job.$ext", job_inmeta($job)->{files}{prog}{content};
}
-sub genarticle{
-
-}
-
1;
__END__
# Below is stub documentation for your module. You'd better edit it!