<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Ikiwiki metadata plugin.
package IkiWiki::Plugin::meta;

use warnings;
use strict;
use IkiWiki;

my %meta;
my %title;
my %permalink;
my %author;
my %authorurl;

sub import { #{{{
	IkiWiki::hook(type =&gt; "preprocess", id =&gt; "meta", 
		call =&gt; \&amp;preprocess);
	IkiWiki::hook(type =&gt; "filter", id =&gt; "meta", 
		call =&gt; \&amp;filter);
	IkiWiki::hook(type =&gt; "pagetemplate", id =&gt; "meta", 
		call =&gt; \&amp;pagetemplate);
} # }}}

sub filter (@) { #{{{
	my %params=@_;
	
	$meta{$params{page}}='';

	return $params{content};
} # }}}

sub preprocess (@) { #{{{
	if (! @_) {
		return "";
	}
	my %params=@_;
	my $key=shift;
	my $value=$params{$key};
	delete $params{$key};
	my $page=$params{page};
	delete $params{page};
	delete $params{destpage};

	eval q{use HTML::Entities};
	# Always dencode, even if encoding later, since it might not be
	# fully encoded.
	$value=decode_entities($value);

	if ($key eq 'link') {
		if (%params) {
			$meta{$page}.="&lt;link href=\"".encode_entities($value)."\" ".
				join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
				" /&gt;\n";
		}
		else {
			# hidden WikiLink
			push @{$IkiWiki::links{$page}}, $value;
		}
	}
	elsif ($key eq 'title') {
		$title{$page}=$value;
	}
	elsif ($key eq 'permalink') {
		$permalink{$page}=$value;
		$meta{$page}.="&lt;link rel=\"bookmark\" href=\"".encode_entities($value)."\" /&gt;\n";
	}
	else {
		$meta{$page}.="&lt;meta name=\"".encode_entities($key).
			"\" content=\"".encode_entities($value)."\" /&gt;\n";
		if ($key eq 'author') {
			$author{$page}=$value;
		}
		elsif ($key eq 'authorurl') {
			$authorurl{$page}=$value;
		}
	}

	return "";
} # }}}

sub pagetemplate (@) { #{{{
	my %params=@_;
        my $page=$params{page};
        my $template=$params{template};

	$template-&gt;param(meta =&gt; $meta{$page})
		if exists $meta{$page} &amp;&amp; $template-&gt;query(name =&gt; "meta");
	if (exists $title{$page} &amp;&amp; $template-&gt;query(name =&gt; "title")) {
		$template-&gt;param(title =&gt; $title{$page});
		$template-&gt;param(title_overridden =&gt; 1);
	}
	$template-&gt;param(permalink =&gt; $permalink{$page})
		if exists $permalink{$page} &amp;&amp; $template-&gt;query(name =&gt; "permalink");
	$template-&gt;param(author =&gt; $author{$page})
		if exists $author{$page} &amp;&amp; $template-&gt;query(name =&gt; "author");
	$template-&gt;param(authorurl =&gt; $authorurl{$page})
		if exists $authorurl{$page} &amp;&amp; $template-&gt;query(name =&gt; "authorurl");
	
} # }}}

1
</pre></body></html>