Add a function add_autofiles().
[ikiwiki.git] / IkiWiki.pm
index ac01ea4180c25224892ba8a5cfa1d807df67c1af..115c512d3eba06395390dce71734b49e3eb94c37 100644 (file)
@@ -14,7 +14,7 @@ use open qw{:utf8 :std};
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
            %pagestate %wikistate %renderedfiles %oldrenderedfiles
            %pagesources %destsources %depends %depends_simple %hooks
-           %forcerebuild %loaded_plugins};
+           %forcerebuild %loaded_plugins @autofiles};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage deptype
@@ -743,7 +743,10 @@ sub srcfile_stat {
 }
 
 sub srcfile ($;$) {
-       return (srcfile_stat(@_))[0];
+       if (my @stat=srcfile_stat(@_)) {
+               return $stat[0];
+       }
+       return undef
 }
 
 sub add_underlay ($) {
@@ -881,7 +884,7 @@ sub bestlink ($$) {
                $l.="/" if length $l;
                $l.=$link;
 
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
@@ -891,7 +894,7 @@ sub bestlink ($$) {
 
        if (length $config{userdir}) {
                my $l = "$config{userdir}/".lc($link);
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
@@ -1081,11 +1084,10 @@ sub htmllink ($$$;@) {
        }
 
        my @attrs;
-       if (defined $opts{rel}) {
-               push @attrs, ' rel="'.$opts{rel}.'"';
-       }
-       if (defined $opts{class}) {
-               push @attrs, ' class="'.$opts{class}.'"';
+       foreach my $attr (qw{rel class title}) {
+               if (defined $opts{$attr}) {
+                       push @attrs, " $attr=\"$opts{$attr}\"";
+               }
        }
 
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
@@ -1408,7 +1410,7 @@ sub check_content (@) {
                my %old=map { $_ => 1 }
                        split("\n", readfile(srcfile($pagesources{$params{page}})));
                foreach my $line (split("\n", $params{content})) {
-                       push @diff, $line if ! exists $old{$_};
+                       push @diff, $line if ! exists $old{$line};
                }
                $params{diff}=join("\n", @diff);
        }
@@ -1896,6 +1898,14 @@ sub add_link ($$) {
                unless grep { $_ eq $link } @{$links{$page}};
 }
 
+sub add_autofile ($) {
+       my $addfile=shift;
+       my ($file,$page) = verify_src_file($addfile,$config{srcdir});
+       if ($page) {
+               push @autofiles, $file;
+       }
+}
+
 sub pagespec_translate ($) {
        my $spec=shift;
 
@@ -2120,10 +2130,7 @@ sub merge_influences {
        }
        else {
                # influence blocker
-               print STDERR "merging $this and $other; found influence blocker\n";
                $this->[1]={};
-               $this->[2]=1;
-               return;
        }
 }