I have added opengraph data on the HTML of all pages using a plugin:
#!/usr/bin/perl
package IkiWiki::Plugin::opengraph;
use warnings;
use strict;
use IkiWiki 3.00;
our $VERSION = '0.1.4';
sub import {
hook(type => "pagetemplate", id => "opengraph", call => \&opengraph_tags);
}
sub opengraph_tags {
my %args = @_;
${args}{template}->param('OPENGRAPH' => 1);
my ${title} = pagetitle(${args}{destpage});
my ${url} = urlto(${args}{destpage}, 'index', '1');
my ${image} = urlto('logo.png', 'index', '1');
my ${type} = pagetype(${args}{destpage});
my ${opengraph_title} = ${title} || ${config}{'opengraph_title'} || "ikiwiki";
my ${opengraph_description} = ${config}{'opengraph_description'} || "ikiwiki";
my ${opengraph_type} = ${type} || ${config}{'opengraph_type'} || "website";
my ${opengraph_image} = ${image} || ${config}{'opengraph_image'} || "http://ikiwiki.info/logo/ikiwiki.png";
my ${opengraph_url} = ${url} || ${config}{'opengraph_url'} || "http://ikiwiki.info/";
my ${opengraph_tags} =<<EOF;
<meta property="og:title" content="${opengraph_title}">
\t<meta property="og:description" content="${opengraph_description}"/>
\t<meta property="og:type" content="${opengraph_type}">
\t<meta property="og:image" content="${opengraph_image}">
\t<meta property="og:url" content="${opengraph_url}">
EOF
${args}{template}->param('OPENGRAPH_TAGS' => ${opengraph_tags})
}
1;
Then on page.tmpl I added:
<TMPL_IF OPENGRAPH>
<TMPL_VAR OPENGRAPH_TAGS>
</TMPL_IF>
You may use the same approach for dynamically adding elements to the HTML section of the pages, or you could do a simpler approach but harder to mantain which is hard writing HTML directly on the page.tmpl file.
About page.tmpl
From the docs:
Template files are unlike template pages in that they have the
extension .tmpl. Template files are used extensively by Ikiwiki to
generate html. They can contain html that would not normally be
allowed on a wiki page.
Template files are located in /usr/share/ikiwiki/templates by default;
the templatedir setting can be used to make another directory be
searched first. Customised template files can also be placed inside
the "templates/" directory in your wiki's source -- files placed there
override ones in the templatedir.
Make sure the page.tmpl file you are modifying is stored under the template directory. Look out for this option on the wiki.setup file:
# additional directory to search for template files
templatedir: /usr/share/ikiwiki/templates