From a02c3f46ea79313a4e0f6df924efac067b0fd177 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 29 Jul 2008 15:39:01 -0400 Subject: initial draft --- IkiWiki/Plugin/autoindex.pm | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 IkiWiki/Plugin/autoindex.pm (limited to 'IkiWiki/Plugin/autoindex.pm') diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm new file mode 100644 index 000000000..0a8d90701 --- /dev/null +++ b/IkiWiki/Plugin/autoindex.pm @@ -0,0 +1,55 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::autoindex; + +use warnings; +use strict; +use IkiWiki 2.00; +use Encode; + +sub import { #{{{ + hook(type => "refresh", id => "autoindex", call => \&refresh); +} # }}} + +sub genindex ($) { #{{{ + my $page=shift; + my $file=$page.".".$config{default_pageext}; + my $template=template("autoindex.tmpl"); + $template->param(page => $page); + writefile($file, $config{srcdir}, $template->output); +} #}}} + +sub refresh () { #{{{ + eval q{use File::Find}; + error($@) if $@; + + my (%pages, %dirs); + find({ + no_chdir => 1, + wanted => sub { + $_=decode_utf8($_); + if (IkiWiki::file_pruned($_, $config{srcdir})) { + $File::Find::prune=1; + } + elsif (! -l $_) { + my ($f)=/$config{wiki_file_regexp}/; # untaint + return unless defined $f; + $f=~s/^\Q$config{srcdir}\E\/?//; + return unless length $f; + if (! -d _) { + $pages{pagename($f)}=1; + } + else { + $dirs{$f}=1; + } + } + } + }, $config{srcdir}); + + foreach my $dir (keys %dirs) { + if (! exists $pages{$dir}) { + genindex($dir); + } + } +} #}}} + +1 -- cgit v1.2.3 From f0090d8c5781682eb0e4a59cb92438c0b7baafa1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 29 Jul 2008 15:51:25 -0400 Subject: check generated pages in I considered not checking them in, or making the checkin configurable. However, then they would remain not checked in if edited by a user, which is probably not desired. Note that passing undef as the username/ip to rcs_commit_staged may not result in ideal behavior; the commit may seem to come from "anonymous" with some revision control systems. Most of them handle it a bit better and just have it come from whatever user is running the build. --- IkiWiki/Plugin/autoindex.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/autoindex.pm') diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index 0a8d90701..8179ee1e7 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -16,6 +16,9 @@ sub genindex ($) { #{{{ my $template=template("autoindex.tmpl"); $template->param(page => $page); writefile($file, $config{srcdir}, $template->output); + if ($config{rcs}) { + IkiWiki::rcs_add($file); + } } #}}} sub refresh () { #{{{ @@ -45,9 +48,23 @@ sub refresh () { #{{{ } }, $config{srcdir}); + my @needed; foreach my $dir (keys %dirs) { if (! exists $pages{$dir}) { - genindex($dir); + push @needed, $dir; + } + } + + if (@needed) { + if ($config{rcs}) { + IkiWiki::disable_commit_hook(); + } + genindex($_) foreach @needed; + if ($config{rcs}) { + IkiWiki::rcs_commit_staged( + gettext("automatic index generation"), + undef, undef); + IkiWiki::enable_commit_hook(); } } } #}}} -- cgit v1.2.3