summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/meta.pm62
-rw-r--r--IkiWiki/Plugin/po.pm4
-rw-r--r--IkiWiki/Plugin/sortnaturally.pm32
-rw-r--r--IkiWiki/Plugin/tag.pm25
-rw-r--r--IkiWiki/Render.pm33
5 files changed, 140 insertions, 16 deletions
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 9906c3f57..128a6342c 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -89,6 +89,12 @@ sub preprocess (@) {
# Metadata collection that needs to happen during the scan pass.
if ($key eq 'title') {
$pagestate{$page}{meta}{title}=$value;
+ if (exists $params{sortas}) {
+ $pagestate{$page}{meta}{titlesort}=$params{sortas};
+ }
+ else {
+ delete $pagestate{$page}{meta}{titlesort};
+ }
return "";
}
elsif ($key eq 'description') {
@@ -116,6 +122,12 @@ sub preprocess (@) {
}
elsif ($key eq 'author') {
$pagestate{$page}{meta}{author}=$value;
+ if (exists $params{sortas}) {
+ $pagestate{$page}{meta}{authorsort}=$params{sortas};
+ }
+ else {
+ delete $pagestate{$page}{meta}{authorsort};
+ }
# fallthorough
}
elsif ($key eq 'authorurl') {
@@ -287,6 +299,33 @@ sub pagetemplate (@) {
}
}
+sub get_sort_key {
+ my $page = shift;
+ my $meta = shift;
+
+ # e.g. titlesort (also makes sense for author)
+ my $key = $pagestate{$page}{meta}{$meta . "sort"};
+ return $key if defined $key;
+
+ # e.g. title
+ $key = $pagestate{$page}{meta}{$meta};
+ return $key if defined $key;
+
+ # fall back to closer-to-core things
+ if ($meta eq 'title') {
+ return pagetitle(IkiWiki::basename($page));
+ }
+ elsif ($meta eq 'date') {
+ return $IkiWiki::pagectime{$page};
+ }
+ elsif ($meta eq 'updated') {
+ return $IkiWiki::pagemtime{$page};
+ }
+ else {
+ return '';
+ }
+}
+
sub match {
my $field=shift;
my $page=shift;
@@ -337,4 +376,27 @@ sub match_copyright ($$;@) {
IkiWiki::Plugin::meta::match("copyright", @_);
}
+package IkiWiki::SortSpec;
+
+sub cmp_meta {
+ my $meta = shift;
+ error(gettext("sort=meta requires a parameter")) unless defined $meta;
+
+ if ($meta eq 'updated' || $meta eq 'date') {
+ return IkiWiki::Plugin::meta::get_sort_key($a, $meta)
+ <=>
+ IkiWiki::Plugin::meta::get_sort_key($b, $meta);
+ }
+
+ return IkiWiki::Plugin::meta::get_sort_key($a, $meta)
+ cmp
+ IkiWiki::Plugin::meta::get_sort_key($b, $meta);
+}
+
+# A prototype of how sort=title could behave in 4.0 or something
+sub cmp_meta_title {
+ $_[0] = 'title';
+ return cmp_meta(@_);
+}
+
1
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 2250a7f9f..00c58fbe5 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -174,7 +174,9 @@ sub checkconfig () {
if ($config{po_master_language}{code} ne 'en') {
# Add underlay containing translated source files
# for the master language.
- add_underlay("locale/$config{po_master_language}{code}/$underlay");
+print STDERR "added underlay locale/$config{po_master_language}{code}/$underlay\n";
+ add_underlay("locale/$config{po_master_language}{code}/$underlay")
+ if -d "$config{underlaydirbase}/locale/$config{po_master_language}{code}/$underlay";
}
}
}
diff --git a/IkiWiki/Plugin/sortnaturally.pm b/IkiWiki/Plugin/sortnaturally.pm
new file mode 100644
index 000000000..62e42767c
--- /dev/null
+++ b/IkiWiki/Plugin/sortnaturally.pm
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+# Sort::Naturally-powered title_natural sort order for IkiWiki
+package IkiWiki::Plugin::sortnaturally;
+
+use IkiWiki 3.00;
+no warnings;
+
+sub import {
+ hook(type => "getsetup", id => "sortnaturally", call => \&getsetup);
+}
+
+sub getsetup {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => undef,
+ },
+}
+
+sub checkconfig () {
+ eval q{use Sort::Naturally};
+ error $@ if $@;
+}
+
+package IkiWiki::SortSpec;
+
+sub cmp_title_natural {
+ Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($a)),
+ IkiWiki::pagetitle(IkiWiki::basename($b)))
+}
+
+1;
diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm
index cdcfaf536..7a85874f6 100644
--- a/IkiWiki/Plugin/tag.pm
+++ b/IkiWiki/Plugin/tag.pm
@@ -6,8 +6,6 @@ use warnings;
use strict;
use IkiWiki 3.00;
-my %tags;
-
sub import {
hook(type => "getopt", id => "tag", call => \&getopt);
hook(type => "getsetup", id => "tag", call => \&getsetup);
@@ -71,9 +69,8 @@ sub preprocess_tag (@) {
foreach my $tag (keys %params) {
$tag=linkpage($tag);
- $tags{$page}{$tag}=1;
# hidden WikiLink
- add_link($page, tagpage($tag));
+ add_link($page, tagpage($tag), 'tag');
}
return "";
@@ -87,15 +84,13 @@ sub preprocess_taglink (@) {
return join(" ", map {
if (/(.*)\|(.*)/) {
my $tag=linkpage($2);
- $tags{$params{page}}{$tag}=1;
- add_link($params{page}, tagpage($tag));
+ add_link($params{page}, tagpage($tag), 'tag');
return taglink($params{page}, $params{destpage}, $tag,
linktext => pagetitle($1));
}
else {
my $tag=linkpage($_);
- $tags{$params{page}}{$tag}=1;
- add_link($params{page}, tagpage($tag));
+ add_link($params{page}, tagpage($tag), 'tag');
return taglink($params{page}, $params{destpage}, $tag);
}
}
@@ -110,17 +105,19 @@ sub pagetemplate (@) {
my $destpage=$params{destpage};
my $template=$params{template};
+ my $tags = $typedlinks{$page}{tag};
+
$template->param(tags => [
map {
link => taglink($page, $destpage, $_, rel => "tag")
- }, sort keys %{$tags{$page}}
- ]) if exists $tags{$page} && %{$tags{$page}} && $template->query(name => "tags");
+ }, sort keys %$tags
+ ]) if defined $tags && %$tags && $template->query(name => "tags");
if ($template->query(name => "categories")) {
# It's an rss/atom template. Add any categories.
- if (exists $tags{$page} && %{$tags{$page}}) {
+ if (defined $tags && %$tags) {
$template->param(categories => [map { category => $_ },
- sort keys %{$tags{$page}}]);
+ sort keys %$tags]);
}
}
}
@@ -128,9 +125,7 @@ sub pagetemplate (@) {
package IkiWiki::PageSpec;
sub match_tagged ($$;@) {
- my $page = shift;
- my $glob = shift;
- return match_link($page, IkiWiki::Plugin::tag::tagpage($glob));
+ return match_link($_[0], IkiWiki::Plugin::tag::tagpage($_[1]), linktype => 'tag');
}
1
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index abafb0887..e98888d76 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -167,6 +167,7 @@ sub scan ($) {
else {
$links{$page}=[];
}
+ delete $typedlinks{$page};
run_hooks(scan => sub {
shift->(
@@ -398,6 +399,7 @@ sub find_del_files ($) {
push @del, $pagesources{$page};
}
$links{$page}=[];
+ delete $typedlinks{$page};
$renderedfiles{$page}=[];
$pagemtime{$page}=0;
}
@@ -499,6 +501,29 @@ sub remove_unrendered () {
}
}
+sub link_types_changed ($$) {
+ # each is of the form { type => { link => 1 } }
+ my $new = shift;
+ my $old = shift;
+
+ return 0 if !defined $new && !defined $old;
+ return 1 if !defined $new || !defined $old;
+
+ while (my ($type, $links) = each %$new) {
+ foreach my $link (keys %$links) {
+ return 1 unless exists $old->{$type}{$link};
+ }
+ }
+
+ while (my ($type, $links) = each %$old) {
+ foreach my $link (keys %$links) {
+ return 1 unless exists $new->{$type}{$link};
+ }
+ }
+
+ return 0;
+}
+
sub calculate_changed_links ($$$) {
my ($changed, $del, $oldlink_targets)=@_;
@@ -525,6 +550,14 @@ sub calculate_changed_links ($$$) {
}
$linkchangers{lc($page)}=1;
}
+
+ # we currently assume that changing the type of a link doesn't
+ # change backlinks
+ if (!exists $linkchangers{lc($page)}) {
+ if (link_types_changed($typedlinks{$page}, $oldtypedlinks{$page})) {
+ $linkchangers{lc($page)}=1;
+ }
+ }
}
return \%backlinkchanged, \%linkchangers;