9 \[\[(!?) # directive open; 2: optional prefix
11 ( # 4: the parameters (including initial whitespace)
14 (?:[-\w]+=)? # named parameter key?
16 """.*?""" # triple-quoted value
18 "[^"]+" # single-quoted value
20 [^\s\]]+ # unquoted value
22 \s* # whitespace or end
25 *) # 0 or more parameters
26 \]\] # directive closed
29 sub handle_directive {
32 my $directive = shift;
36 return "${escape}[[${prefix}${directive}${args}]]"
38 if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
39 $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
41 return "[[!${directive}${args}]]"
44 sub prefix_directives {
45 $/=undef; # process whole files at once
48 s{$regex}{handle_directive($1, $2, $3, $4)}eg;
54 $config{wikistatedir}=shift()."/.ikiwiki";
56 if (! defined $config{wikistatedir}) {
60 if (! IkiWiki::oldloadindex()) {
61 die "failed to load index\n";
63 if (! IkiWiki::saveindex()) {
64 die "failed to save indexdb\n"
66 if (! IkiWiki::loadindex()) {
67 die "transition failed, cannot load new indexdb\n";
69 if (! unlink("$config{wikistatedir}/index")) {
70 die "unlink failed: $!\n";
75 print STDERR "Usage: ikiwiki-transition type ...\n";
76 print STDERR "Currently supported transition subcommands:\n";
77 print STDERR " prefix_directives file\n";
78 print STDERR " indexdb srcdir\n";
85 if ($mode eq 'prefix_directives') {
86 prefix_directives(@ARGV);
88 elsif ($mode eq 'indexdb') {
97 # A slightly modified version of the old loadindex function.
99 %oldrenderedfiles=%pagectime=();
100 if (! $config{rebuild}) {
101 %pagesources=%pagemtime=%oldlinks=%links=%depends=
102 %destsources=%renderedfiles=%pagecase=%pagestate=();
104 open (my $in, "<", "$config{wikistatedir}/index") || return;
110 foreach my $i (split(/ /, $_)) {
111 my ($item, $val)=split(/=/, $i, 2);
112 push @{$items{$item}}, decode_entities($val);
115 next unless exists $items{src}; # skip bad lines for now
117 my $page=pagename($items{src}[0]);
118 if (! $config{rebuild}) {
119 $pagesources{$page}=$items{src}[0];
120 $pagemtime{$page}=$items{mtime}[0];
121 $oldlinks{$page}=[@{$items{link}}];
122 $links{$page}=[@{$items{link}}];
123 $depends{$page}=$items{depends}[0] if exists $items{depends};
124 $destsources{$_}=$page foreach @{$items{dest}};
125 $renderedfiles{$page}=[@{$items{dest}}];
126 $pagecase{lc $page}=$page;
127 foreach my $k (grep /_/, keys %items) {
128 my ($id, $key)=split(/_/, $k, 2);
129 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
132 $oldrenderedfiles{$page}=[@{$items{dest}}];
133 $pagectime{$page}=$items{ctime}[0];
136 # saveindex relies on %hooks being populated, else it won't save
137 # the page state owned by a given hook. But no plugins are loaded
138 # by this program, so populate %hooks with all hook ids that
139 # currently have page state.
140 foreach my $page (keys %pagemtime) {
141 foreach my $id (keys %{$pagestate{$page}}) {
142 $hooks{_dummy}{$id}=1;