将字体链接添加到 ikiwiki 模板

Adding font links to ikiwiki template

我想将以下内容添加到我的 ikiwiki 中所有 HTML 页面的所有 headers。

<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'/>

我尝试在自定义 templates/page.tmpl.mdwn 中添加这些行,但每次我部署 wiki 时,都没有添加这些行。

我做错了什么?

$git_repo/templates 中创建一个名为 page.tmpl 的文件,它是 /usr/share/ikiwiki/templates/page.tmpl 的副本——或者该文件在您本地系统中的任何位置。

然后,您可以修改$git_repo/templates/page.tmpl添加任何您想要的。

我已经使用插件在所有页面的 HTML 添加了 opengraph 数据:

#!/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;

然后在 page.tmpl 我补充说:

<TMPL_IF OPENGRAPH>
<TMPL_VAR OPENGRAPH_TAGS>
</TMPL_IF>

您可以使用相同的方法将元素动态添加到页面的 HTML 部分,或者您可以采用更简单但更难维护的方法直接在 page.tmpl 文件上硬写 HTML。


关于page.tmpl

来自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.

确保您正在修改的page.tmpl文件存储在模板目录下。在 wiki.setup 文件中寻找这个选项:

# additional directory to search for template files
templatedir: /usr/share/ikiwiki/templates