<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;

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

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

	eval q{use CGI 'escapeHTML'};

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

	return "";
} # }}}

sub pagetemplate ($$) { #{{{
        my $page=shift;
        my $template=shift;

	$template-&gt;param(meta =&gt; $meta{$page}) if exists $meta{$page};
	$template-&gt;param(title =&gt; $title{$page}) if exists $title{$page};
} # }}}

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