+ if (exists $pagestate{$page}{meta}{enclosure}) {
+ $template->param(enclosure => HTML::Entities::encode_entities(IkiWiki::urlabs($pagestate{$page}{meta}{enclosure}, $config{url})));
+ }
+
+ foreach my $field (qw{authorurl}) {
+ eval q{use HTML::Entities};
+ $template->param($field => HTML::Entities::encode_entities($pagestate{$page}{meta}{$field}))
+ if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
+ }
+
+ foreach my $field (qw{permalink}) {
+ if (exists $pagestate{$page}{meta}{$field} && $template->query(name => $field)) {
+ eval q{use HTML::Entities};
+ $template->param($field => HTML::Entities::encode_entities(IkiWiki::urlabs($pagestate{$page}{meta}{$field}, $config{url})));
+ }
+ }
+
+ foreach my $field (qw{description author}) {
+ eval q{use HTML::Entities};
+ $template->param($field => HTML::Entities::encode_numeric($pagestate{$page}{meta}{$field}))
+ if exists $pagestate{$page}{meta}{$field} && $template->query(name => $field);
+ }
+
+ foreach my $field (qw{license copyright}) {
+ if (exists $pagestate{$page}{meta}{$field} && $template->query(name => $field) &&
+ ($page eq $destpage || ! exists $pagestate{$destpage}{meta}{$field} ||
+ $pagestate{$page}{meta}{$field} ne $pagestate{$destpage}{meta}{$field})) {
+ $template->param($field => htmlize($page, $destpage, $pagestate{$page}{meta}{$field}));
+ }
+ }
+}
+
+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;
+
+ # turn glob into a safe regexp
+ my $re=IkiWiki::glob2re(shift);
+
+ my $val;
+ if (exists $pagestate{$page}{meta}{$field}) {
+ $val=$pagestate{$page}{meta}{$field};