#!/usr/bin/perl
# Automatically extract title metadata from the first # title
package IkiWiki::Plugin::autotitle;

use warnings;
use strict;
use IkiWiki 2.00;

sub import { #{{{
	hook(type => "scan", id => "autotitle", call => \&autotitle);
} # }}}

sub autotitle (@) { #{{{
        my %params=@_;
        my $page=$params{page};
        my $content=$params{content};

	return if defined $pagestate{$page}{meta}{title};
	$pagestate{$page}{meta}{title}=HTML::Entities::encode_numeric($1)
		if $content =~ /^\s*#\s+(.+?)\s*$/om;
} #}}}

1

