# Album Plugin:	format/favicon
# For info:	'album -plugin_info format/favicon'
# For usage:	'album -plugin_usage format/favicon'

use strict;

my $DESCRIPTION = << 'DESCRIPTION';
Plugin: format/favicon

Adds favicon tags to the <head> section of album pages.

You need to specify your favicon url:

% album -favicon:url "//DavePics.com/Icons/favicon.jpg"

Would add this to head:

  <link rel="SHORTCUT ICON" href="//DavePics.com/Icons/favicon.jpg" />

DESCRIPTION

sub start_plugin {
	my ($opt) = @_;

	# Setup the options
	album::add_option(1, 'url', album::OPTION_STR,
		usage=>"URL for favicon\n\n".$DESCRIPTION);

	# Setup the hooks
	album::hook($opt, 'do_album', \&setup_head);

	return {
		author => 'David Ljung Madison',
		href => 'http://MarginalHacks.com/',
		version => '1.0',
		description => $DESCRIPTION,
	};
}

sub setup_head {
	my ($opt,$data, undef,  $dir, $album) = @_;

	my $url = album::option($opt, 'url');

	album::usage($opt,"Plugin favicon needs you to specify:\n  -favicon:url")
		unless $url;

	# Add it to the head
	$data->{head} .= <<ANALYTICS;
    <link rel="SHORTCUT ICON" href="$url" />
ANALYTICS

	# Still do the album!
	return 0;
}

# Plugins always end with:
1;
