1

I want to add the following to all the headers of all the HTML pages in my ikiwiki.

<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Tangerine">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Romanesco">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800,400italic,600italic,700italic' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,600,700,800,400italic,600italic,700italic' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=PT+Sans:400,600,700,800,400italic,600italic,700italic' rel='stylesheet' type='text/css'/>

I tried to add those line in a custom templates/page.tmpl.mdwn but every time I deploy the wiki, those are not added.

What am I doing wrong?

unor
  • 92,415
  • 26
  • 211
  • 360
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156

2 Answers2

1

In $git_repo/templates create a file called page.tmpl which is a copy of /usr/share/ikiwiki/templates/page.tmpl -- or where ever that file is in your local system.

Then, you can modify $git_repo/templates/page.tmpl to add whatever you want.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
0

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
Iuri Guilherme
  • 389
  • 1
  • 10