diff options
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/branding.pm | 110 | ||||
-rw-r--r-- | IkiWiki/Plugin/copyright.pm | 69 | ||||
-rw-r--r-- | IkiWiki/Plugin/farbar.pm | 110 | ||||
-rw-r--r-- | IkiWiki/Plugin/footer.pm | 110 | ||||
-rw-r--r-- | IkiWiki/Plugin/h1title.pm | 87 | ||||
-rw-r--r-- | IkiWiki/Plugin/htmlpacker.pm | 40 | ||||
-rw-r--r-- | IkiWiki/Plugin/img.pm | 16 | ||||
-rw-r--r-- | IkiWiki/Plugin/license.pm | 69 | ||||
-rw-r--r-- | IkiWiki/Plugin/meta.pm | 7 | ||||
-rw-r--r-- | IkiWiki/Plugin/osm.pm | 50 | ||||
-rw-r--r-- | IkiWiki/Plugin/pandoc.pm | 212 | ||||
-rw-r--r-- | IkiWiki/Plugin/topbar.pm | 110 | ||||
-rw-r--r-- | IkiWiki/Plugin/underlaydirbase.pm | 30 | ||||
-rw-r--r-- | IkiWiki/Plugin/varioki.pm | 190 | ||||
-rw-r--r-- | IkiWiki/Plugin/wikistatedir.pm | 28 |
15 files changed, 1226 insertions, 12 deletions
diff --git a/IkiWiki/Plugin/branding.pm b/IkiWiki/Plugin/branding.pm new file mode 100644 index 0000000..653eea4 --- /dev/null +++ b/IkiWiki/Plugin/branding.pm @@ -0,0 +1,110 @@ +#!/usr/bin/perl +# Branding plugin. +# by Jonas Smedegaard <dr@jones.dk> +# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi> + +package IkiWiki::Plugin::branding; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "branding", call => \&getsetup); + hook(type => "preprocess", id => "branding", call => \&preprocess); + hook(type => "pagetemplate", id => "branding", call => \&pagetemplate); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 1, + }, + global_brandings => { + type => "boolean", + example => 1, + description => "show branding page on all pages?", + safe => 1, + rebuild => 1, + }, +} + +my %pagebranding; + +sub preprocess (@) { + my %params=@_; + + my $page=$params{page}; + return "" unless $page eq $params{destpage}; + + if (! defined $params{content}) { + $pagebranding{$page}=undef; + } + else { + my $file = $pagesources{$page}; + my $type = pagetype($file); + + $pagebranding{$page}= + IkiWiki::htmlize($page, $page, $type, + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, $params{content}))); + } + + return ""; +} + +my $oldfile; +my $oldcontent; + +sub branding_content ($) { + my $page=shift; + + return delete $pagebranding{$page} if defined $pagebranding{$page}; + + return if ! exists $pagebranding{$page} && + defined $config{global_brandings} && ! $config{global_brandings}; + + my $branding_page=bestlink($page, "branding") || return; + my $branding_file=$pagesources{$branding_page} || return; + my $branding_type=pagetype($branding_file); + + if (defined $branding_type) { + # FIXME: This isn't quite right; it won't take into account + # adding a new branding page. So adding such a page + # currently requires a wiki rebuild. + add_depends($page, $branding_page); + + my $content; + if (defined $oldfile && $branding_file eq $oldfile) { + $content=$oldcontent; + } + else { + $content=readfile(srcfile($branding_file)); + $oldcontent=$content; + $oldfile=$branding_file; + } + + return unless length $content; + return IkiWiki::htmlize($branding_page, $page, $branding_type, + IkiWiki::linkify($branding_page, $page, + IkiWiki::preprocess($branding_page, $page, + IkiWiki::filter($branding_page, $page, $content)))); + } + +} + +sub pagetemplate (@) { + my %params=@_; + + my $template=$params{template}; + if ($params{destpage} eq $params{page} && + $template->query(name => "branding")) { + my $content=branding_content($params{destpage}); + if (defined $content && length $content) { + $template->param(branding => $content); + } + } +} + +1 diff --git a/IkiWiki/Plugin/copyright.pm b/IkiWiki/Plugin/copyright.pm new file mode 100644 index 0000000..0eda81c --- /dev/null +++ b/IkiWiki/Plugin/copyright.pm @@ -0,0 +1,69 @@ +# A plugin for ikiwiki to implement adding a footer with copyright information +# based on a default value taken out of a file. + +# Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# A footer with copyright information will be added to every rendered page if +# (a) such a footer isn't present already (see the `meta' plugin's +# ``copyright'' facility) and (b) a file `copyright.html' is found (using the +# same rules as for the sidebar plugin). +# +# The state which page's copyright text was gathered from which source is not +# tracked, so you'll need a full wiki-rebuild if (b)'s files are changed. +# +# You can use wiki links in `copyright.html'. + +package IkiWiki::Plugin::copyright; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "pagetemplate", id => "copyright", call => \&pagetemplate, + # Run last, as to have the `meta' plugin do its work first. + last => 1); +} + +sub pagetemplate (@) +{ + my %params = @_; + my $page = $params{page}; + my $destpage = $params{destpage}; + + my $template = $params{template}; + + if ($template->query (name => "copyright") && + ! defined $template->param ('copyright')) + { + my $content; + my $copyright_page = bestlink ($page, "copyright") || return; + my $copyright_file = $pagesources{$copyright_page} || return; + #my $pagetype = pagetype ($copyright_file); + # Check if ``$pagetype eq 'html'''? + $content = readfile (srcfile ($copyright_file)); + + if (defined $content && length $content) + { + $template->param (copyright => + IkiWiki::linkify ($page, $destpage, $content)); + } + } +} + +1 diff --git a/IkiWiki/Plugin/farbar.pm b/IkiWiki/Plugin/farbar.pm new file mode 100644 index 0000000..37f1013 --- /dev/null +++ b/IkiWiki/Plugin/farbar.pm @@ -0,0 +1,110 @@ +#!/usr/bin/perl +# Farbar plugin. +# by Jonas Smedegaard <dr@jones.dk> +# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi> + +package IkiWiki::Plugin::farbar; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "farbar", call => \&getsetup); + hook(type => "preprocess", id => "farbar", call => \&preprocess); + hook(type => "pagetemplate", id => "farbar", call => \&pagetemplate); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 1, + }, + global_farbars => { + type => "boolean", + example => 1, + description => "show farbar page on all pages?", + safe => 1, + rebuild => 1, + }, +} + +my %pagefarbar; + +sub preprocess (@) { + my %params=@_; + + my $page=$params{page}; + return "" unless $page eq $params{destpage}; + + if (! defined $params{content}) { + $pagefarbar{$page}=undef; + } + else { + my $file = $pagesources{$page}; + my $type = pagetype($file); + + $pagefarbar{$page}= + IkiWiki::htmlize($page, $page, $type, + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, $params{content}))); + } + + return ""; +} + +my $oldfile; +my $oldcontent; + +sub farbar_content ($) { + my $page=shift; + + return delete $pagefarbar{$page} if defined $pagefarbar{$page}; + + return if ! exists $pagefarbar{$page} && + defined $config{global_farbars} && ! $config{global_farbars}; + + my $farbar_page=bestlink($page, "farbar") || return; + my $farbar_file=$pagesources{$farbar_page} || return; + my $farbar_type=pagetype($farbar_file); + + if (defined $farbar_type) { + # FIXME: This isn't quite right; it won't take into account + # adding a new farbar page. So adding such a page + # currently requires a wiki rebuild. + add_depends($page, $farbar_page); + + my $content; + if (defined $oldfile && $farbar_file eq $oldfile) { + $content=$oldcontent; + } + else { + $content=readfile(srcfile($farbar_file)); + $oldcontent=$content; + $oldfile=$farbar_file; + } + + return unless length $content; + return IkiWiki::htmlize($farbar_page, $page, $farbar_type, + IkiWiki::linkify($farbar_page, $page, + IkiWiki::preprocess($farbar_page, $page, + IkiWiki::filter($farbar_page, $page, $content)))); + } + +} + +sub pagetemplate (@) { + my %params=@_; + + my $template=$params{template}; + if ($params{destpage} eq $params{page} && + $template->query(name => "farbar")) { + my $content=farbar_content($params{destpage}); + if (defined $content && length $content) { + $template->param(farbar => $content); + } + } +} + +1 diff --git a/IkiWiki/Plugin/footer.pm b/IkiWiki/Plugin/footer.pm new file mode 100644 index 0000000..b4d7b50 --- /dev/null +++ b/IkiWiki/Plugin/footer.pm @@ -0,0 +1,110 @@ +#!/usr/bin/perl +# Footer plugin. +# by Jonas Smedegaard <dr@jones.dk> +# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi> + +package IkiWiki::Plugin::footer; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "footer", call => \&getsetup); + hook(type => "preprocess", id => "footer", call => \&preprocess); + hook(type => "pagetemplate", id => "footer", call => \&pagetemplate); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 1, + }, + global_footers => { + type => "boolean", + example => 1, + description => "show footer page on all pages?", + safe => 1, + rebuild => 1, + }, +} + +my %pagefooter; + +sub preprocess (@) { + my %params=@_; + + my $page=$params{page}; + return "" unless $page eq $params{destpage}; + + if (! defined $params{content}) { + $pagefooter{$page}=undef; + } + else { + my $file = $pagesources{$page}; + my $type = pagetype($file); + + $pagefooter{$page}= + IkiWiki::htmlize($page, $page, $type, + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, $params{content}))); + } + + return ""; +} + +my $oldfile; +my $oldcontent; + +sub footer_content ($) { + my $page=shift; + + return delete $pagefooter{$page} if defined $pagefooter{$page}; + + return if ! exists $pagefooter{$page} && + defined $config{global_footers} && ! $config{global_footers}; + + my $footer_page=bestlink($page, "footer") || return; + my $footer_file=$pagesources{$footer_page} || return; + my $footer_type=pagetype($footer_file); + + if (defined $footer_type) { + # FIXME: This isn't quite right; it won't take into account + # adding a new footer page. So adding such a page + # currently requires a wiki rebuild. + add_depends($page, $footer_page); + + my $content; + if (defined $oldfile && $footer_file eq $oldfile) { + $content=$oldcontent; + } + else { + $content=readfile(srcfile($footer_file)); + $oldcontent=$content; + $oldfile=$footer_file; + } + + return unless length $content; + return IkiWiki::htmlize($footer_page, $page, $footer_type, + IkiWiki::linkify($footer_page, $page, + IkiWiki::preprocess($footer_page, $page, + IkiWiki::filter($footer_page, $page, $content)))); + } + +} + +sub pagetemplate (@) { + my %params=@_; + + my $template=$params{template}; + if ($params{destpage} eq $params{page} && + $template->query(name => "footer")) { + my $content=footer_content($params{destpage}); + if (defined $content && length $content) { + $template->param(footer => $content); + } + } +} + +1 diff --git a/IkiWiki/Plugin/h1title.pm b/IkiWiki/Plugin/h1title.pm new file mode 100644 index 0000000..1a16b1f --- /dev/null +++ b/IkiWiki/Plugin/h1title.pm @@ -0,0 +1,87 @@ +#!/usr/bin/perl + +package IkiWiki::Plugin::h1title; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { + hook(type => "filter", id => "h1title", call => \&filter); +} + +sub filter(@) { + my %params = @_; + my $page = $params{page}; + my $content = $params{content}; + + if ($content =~ s/^\#(?=[^#])[ \t]*(.*?)[ \t]*\#*\n//) { + $pagestate{$page}{meta}{title} = $1; + } + return $content; +} + +1 + +__END__ + +=head1 NAME + +ikiwiki Plug-in: h1title + +=head1 SYNOPSIS + +If there is a level 1 Markdown atx-style (hash mark) header on the first line, +this plugin uses it to set the page title and removes it from the page body so +that it won't be rendered twice. Level 1 headers in the remainder of the page +will be ignored. + +For example, the following page will have title "My Title" and the rendered +page body will begin with the level two header "Introduction." + + # My Title + + ## Introduction + + Introductory text with a list: + + * Item 1 + * Item 2 + + ## Second header + + Second section + +This plugin can be used with page templates that use <h1> tags for the page +title to produce a consistent header hierarchy in rendered pages while keeping +the Markdown source clean and free of meta directives. + +=head1 AUTHOR + +Jason Blevins <jrblevin@sdf.lonestar.org>, + +=head1 SEE ALSO + +ikiwiki Homepage: +http://ikiwiki.info/ + +ikiwiki Plugin Documentation: +http://ikiwiki.info/plugins/write/ + +=head1 LICENSE + +Copyright (C) 2008 Jason Blevins + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/IkiWiki/Plugin/htmlpacker.pm b/IkiWiki/Plugin/htmlpacker.pm new file mode 100644 index 0000000..cc1bf9c --- /dev/null +++ b/IkiWiki/Plugin/htmlpacker.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::htmlpacker; + +# htmlpacker: HTML code cleaner +# +# Copyright 2011 Jonas Smedegaard <dr@jones.dk> +# Based on htmlbalance which is... +# Copyright 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/> +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "htmlpacker", call => \&getsetup); + hook(type => "sanitize", id => "htmlpacker", call => \&sanitize); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => undef, + }, +} + +sub sanitize (@) { + my %params=@_; + my $ret = ''; + + eval q{use HTML::Packer}; + error $@ if $@; + my $packer = HTML::Packer->init(); + $ret = $packer->minify( \$params{content}, { html5 => $config{html5} } ); + return $ret; +} + +1 diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm index 17a58ca..9f9c72c 100644 --- a/IkiWiki/Plugin/img.pm +++ b/IkiWiki/Plugin/img.pm @@ -65,15 +65,23 @@ sub preprocess (@) { my $dir = $params{page}; my $base = IkiWiki::basename($file); my $issvg = $base=~s/\.svg$/.png/i; + my $usegm = 1; + my $ispdf = $base=~s/\.pdf$/.png/i; my $pagenumber = exists($params{pagenumber}) ? int($params{pagenumber}) : 0; if ($pagenumber != 0) { $base = "p$pagenumber-$base"; } - eval q{use Image::Magick}; - error gettext("Image::Magick is not installed") if $@; - my $im = Image::Magick->new(); + eval q{use Graphics::Magick}; + if ($@) { + $usegm = 0; + eval q{use Image::Magick}; + error gettext("Image::Magick is not installed") if $@; + } + my $im = $usegm + ? Graphics::Magick->new($issvg ? (magick => "png") : ()) + : Image::Magick->new($issvg ? (magick => "png") : ()); my $imglink; my $imgdatalink; my $r = $im->Read("$srcfile\[$pagenumber]"); @@ -120,7 +128,7 @@ sub preprocess (@) { will_render($params{page}, $imglink); if (-e $outfile && (-M $srcfile >= -M $outfile)) { - $im = Image::Magick->new; + $im = $usegm ? Graphics::Magick->new : Image::Magick->new; $r = $im->Read($outfile); error sprintf(gettext("failed to read %s: %s"), $outfile, $r) if $r; } diff --git a/IkiWiki/Plugin/license.pm b/IkiWiki/Plugin/license.pm new file mode 100644 index 0000000..2375c22 --- /dev/null +++ b/IkiWiki/Plugin/license.pm @@ -0,0 +1,69 @@ +# A plugin for ikiwiki to implement adding a footer with licensing information +# based on a default value taken out of a file. + +# Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# A footer with licensing information will be added to every rendered page if +# (a) such a footer isn't present already (see the `meta' plugin's ``license'' +# facility) and (b) a file `license.html' is found (using the same rules as for +# the sidebar plugin). +# +# The state which page's license text was gathered from which source is not +# tracked, so you'll need a full wiki-rebuild if (b)'s files are changed. +# +# You can use wiki links in `license.html'. + +package IkiWiki::Plugin::license; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import +{ + hook (type => "pagetemplate", id => "license", call => \&pagetemplate, + # Run last, as to have the `meta' plugin do its work first. + last => 1); +} + +sub pagetemplate (@) +{ + my %params = @_; + my $page = $params{page}; + my $destpage = $params{destpage}; + + my $template = $params{template}; + + if ($template->query (name => "license") && + ! defined $template->param ('license')) + { + my $content; + my $license_page = bestlink ($page, "license") || return; + my $license_file = $pagesources{$license_page} || return; + #my $pagetype = pagetype ($license_file); + # Check if ``$pagetype eq 'html'''? + $content = readfile (srcfile ($license_file)); + + if (defined $content && length $content) + { + $template->param (license => + IkiWiki::linkify ($page, $destpage, $content)); + } + } +} + +1 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index e7b96bd..ebbf4d7 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -194,11 +194,12 @@ sub preprocess (@) { elsif ($key eq 'script') { my $defer=exists $params{defer} ? ' defer="defer"' : ''; my $async=exists $params{async} ? ' async="async"' : ''; + my $srcurl=$value; my $js=bestlink($page, $value.".js"); - if (! length $js) { - error gettext("script not found"); + if (length $js) { + $srcurl=urlto($js, $page); } - push @{$metaheaders{$page}}, scrub('<script src="'.urlto($js, $page). + push @{$metaheaders{$page}}, scrub('<script src="'. $srcurl . '"' . $defer . $async . ' type="text/javascript"></script>', $page, $destpage); } diff --git a/IkiWiki/Plugin/osm.pm b/IkiWiki/Plugin/osm.pm index 472e269..e6707d4 100644 --- a/IkiWiki/Plugin/osm.pm +++ b/IkiWiki/Plugin/osm.pm @@ -67,6 +67,13 @@ sub getsetup () { safe => 0, rebuild => 1, }, + osm_leaflet_url_stem => { + type => "string", + example => "http://cdn.leafletjs.com/leaflet-0.6.4/leaflet", + description => "Url used as stem for the Leaflet files", + safe => 0, + rebuild => 1, + }, osm_layers => { type => "string", example => { 'OSM', 'GoogleSatellite' }, @@ -81,6 +88,13 @@ sub getsetup () { safe => 1, rebuild => 1, }, + osm_slippy_engine => { + type => "string", + example => "openlayers", + description => "the slippy map engine to use, can be openlayers or leaflet (leaflet always uses GeoJSON, disregarding osm_format)", + safe => 0, + rebuild => 1, + }, } sub register_rendered_files { @@ -472,7 +486,7 @@ sub format (@) { my %params=@_; if ($params{content}=~m!<div[^>]*id="mapdiv-[^"]*"[^>]*>!g) { - if (! ($params{content}=~s!</body>!include_javascript($params{page})."</body>"!em)) { + if (! ($params{content}=~s!</body>!include_javascript($params{page})."</body>"!em)) { #" # no <body> tag, probably in preview mode $params{content}=$params{content} . include_javascript($params{page}); } @@ -481,6 +495,9 @@ sub format (@) { } sub preferred_format() { + if (get_slippy_engine() eq 'leaflet') { + $config{'osm_format'} = 'GeoJSON'; + } if (!defined($config{'osm_format'}) || !$config{'osm_format'}) { $config{'osm_format'} = 'KML'; } @@ -489,12 +506,22 @@ sub preferred_format() { } sub get_formats() { + if (get_slippy_engine() eq 'leaflet') { + $config{'osm_format'} = 'GeoJSON'; + } if (!defined($config{'osm_format'}) || !$config{'osm_format'}) { $config{'osm_format'} = 'KML'; } map { $_ => 1 } split(/, */, $config{'osm_format'}); } +sub get_slippy_engine() { + if (!defined($config{'osm_slippy_engine'}) || !$config{'osm_slippy_engine'}) { + $config{'osm_slippy_engine'} = 'openlayers'; + } + return $config{'osm_slippy_engine'}; +} + sub include_javascript ($) { my $page=shift; my $loader; @@ -551,10 +578,23 @@ sub cgi($) { sub embed_map_code(;$) { my $page=shift; - my $olurl = $config{osm_openlayers_url} || "http://www.openlayers.org/api/OpenLayers.js"; - my $code = '<script src="'.$olurl.'" type="text/javascript" charset="utf-8"></script>'."\n". - '<script src="'.urlto("ikiwiki/osm.js", $page). - '" type="text/javascript" charset="utf-8"></script>'."\n"; + my $code; + if (get_slippy_engine() eq 'openlayers') { + my $olurl = $config{osm_openlayers_url} || "http://www.openlayers.org/api/OpenLayers.js"; + $code = '<script src="'.$olurl.'" type="text/javascript" charset="utf-8"></script>'."\n". + '<script src="'.urlto("ikiwiki/osm.js", $page). + '" type="text/javascript" charset="utf-8"></script>'."\n"; + } + if (get_slippy_engine() eq 'leaflet') { + my $leafurlbase = $config{osm_leaflet_url_stem} || "http://cdn.leafletjs.com/leaflet-0.6.4/leaflet"; + $code = '<link href="'.$leafurlbase.'.css" rel="stylesheet" type="text/css">'."\n". + '<!--[if lte IE 8]>'."\n". + '<link href="'.$leafurlbase.'.ie.css" rel="stylesheet" type="text/css">'."\n". + '<![endif]-->'."\n". + '<script src="'.$leafurlbase.'.js" type="text/javascript" charset="utf-8"></script>'."\n". + '<script src="'.urlto("ikiwiki/leaflet.js", $page). + '" type="text/javascript" charset="utf-8"></script>'."\n"; + } if ($config{'osm_google_apikey'}) { $code .= '<script src="http://maps.google.com/maps?file=api&v=2&key='.$config{'osm_google_apikey'}.'&sensor=false" type="text/javascript" charset="utf-8"></script>'; } diff --git a/IkiWiki/Plugin/pandoc.pm b/IkiWiki/Plugin/pandoc.pm new file mode 100644 index 0000000..5f960b6 --- /dev/null +++ b/IkiWiki/Plugin/pandoc.pm @@ -0,0 +1,212 @@ +#!/usr/bin/perl + +package IkiWiki::Plugin::pandoc; + +use warnings; +use strict; +use IkiWiki; +use FileHandle; +use IPC::Open2; + +sub import { + my $markdown_ext = $config{pandoc_markdown_ext} || "mdwn"; + + hook(type => "getsetup", id => "pandoc", call => \&getsetup); + hook(type => "htmlize", id => $markdown_ext, + # longname => "Pandoc Markdown", + call => sub { htmlize("markdown", @_) }); + if ($config{pandoc_latex}) { + hook(type => "htmlize", id => "tex", + call => sub { htmlize("latex", @_) }); + } + if ($config{pandoc_rst}) { + hook(type => "htmlize", id => "rst", + call => sub { htmlize("rst", @_) }); + } +} + + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 1, + }, + pandoc_command => { + type => "string", + example => "/usr/bin/pandoc", + description => "Path to pandoc executable", + safe => 0, + rebuild => 0, + }, + pandoc_markdown_ext => { + type => "string", + example => "mdwn", + description => "File extension for Markdown files", + safe => 1, + rebuild => 1, + }, + pandoc_latex => { + type => "boolean", + example => 0, + description => "Enable Pandoc processing of LaTeX documents", + safe => 0, + rebuild => 1, + }, + pandoc_rst => { + type => "boolean", + example => 0, + description => "Enable Pandoc processing of reStructuredText documents", + safe => 0, + rebuild => 1, + }, + pandoc_smart => { + type => "boolean", + example => 1, + description => "Use smart quotes, dashes, and ellipses", + safe => 1, + rebuild => 1, + }, + pandoc_obfuscate => { + type => "boolean", + example => 1, + description => "Obfuscate emails", + safe => 1, + rebuild => 1, + }, + pandoc_html5 => { + type => "boolean", + example => 0, + description => "Generate HTML5", + safe => 1, + rebuild => 1, + }, + pandoc_ascii => { + type => "boolean", + example => 0, + description => "Generate ASCII instead of UTF8", + safe => 1, + rebuild => 1, + }, + pandoc_numsect => { + type => "boolean", + example => 0, + description => "Number sections", + safe => 1, + rebuild => 1, + }, + pandoc_sectdiv => { + type => "boolean", + example => 0, + description => "Attach IDs to section DIVs instead of Headers", + safe => 1, + rebuild => 1, + }, + pandoc_codeclasses => { + type => "string", + example => "", + description => "Classes to use for indented code blocks", + safe => 1, + rebuild => 1, + }, + pandoc_math => { + type => "string", + example => "unicode", + description => "Process TeX math using", + safe => 0, + rebuild => 1, + }, +} + + +sub htmlize ($@) { + my $format = shift; + my %params = @_; + my $page = $params{page}; + + local(*PANDOC_IN, *PANDOC_OUT); + my @args; + + my $command = $config{pandoc_command} || "/usr/bin/pandoc"; + + if ($config{pandoc_smart}) { + push @args, '--smart'; + }; + + if ($config{pandoc_obfuscate}) { + push @args, '--email-obfuscation=references'; + } else { + push @args, '--email-obfuscation=none'; + }; + + if ($config{pandoc_html5}) { + push @args, '--html5'; + }; + + if ($config{pandoc_ascii}) { + push @args, '--ascii'; + }; + + if ($config{pandoc_numsect}) { + push @args, '--number-sections'; + }; + + if ($config{pandoc_sectdiv}) { + push @args, '--section-divs'; + }; + + if ($config{pandoc_codeclasses} && ($config{pandoc_codeclasses} ne "")) { + push @args, '--indented-code-classes=' . $config{pandoc_codeclasses}; + }; + + + for ($config{pandoc_math}) { + if (/^mathjax$/) { + push @args, '--mathjax=/dev/null'; + } + elsif (/^jsmath$/) { + push @args, '--jsmath'; + } + elsif (/^latexmathml$/) { + push @args, '--latexmathml'; + } + elsif (/^mimetex$/) { + push @args, '--mimetex'; + } + elsif (/^mathtex$/) { + push @args, '--mimetex=/cgi-bin/mathtex.cgi'; + } + elsif (/^google$/) { + push @args, '--webtex'; + } + elsif (/^mathml$/) { + push @args, '--mathml'; + } + else { } + } + + # $ENV{"LC_ALL"} = "en_US.UTF-8"; + my $pid = open2(*PANDOC_IN, *PANDOC_OUT, $command, + '-f', $format, + '-t', 'html', + @args); + + error("Unable to open $command") unless $pid; + + # Workaround for perl bug (#376329) + require Encode; + my $content = Encode::encode_utf8($params{content}); + + print PANDOC_OUT $content; + close PANDOC_OUT; + + my @html = <PANDOC_IN>; + close PANDOC_IN; + + waitpid $pid, 0; + + $content = Encode::decode_utf8(join('', @html)); + return $content; +} + +1 diff --git a/IkiWiki/Plugin/topbar.pm b/IkiWiki/Plugin/topbar.pm new file mode 100644 index 0000000..2705161 --- /dev/null +++ b/IkiWiki/Plugin/topbar.pm @@ -0,0 +1,110 @@ +#!/usr/bin/perl +# Topbar plugin. +# by Jonas Smedegaard <dr@jones.dk> +# Heavily based on Sidebar by Tuomo Valkonen <tuomov at iki dot fi> + +package IkiWiki::Plugin::topbar; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "topbar", call => \&getsetup); + hook(type => "preprocess", id => "topbar", call => \&preprocess); + hook(type => "pagetemplate", id => "topbar", call => \&pagetemplate); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => 1, + }, + global_topbars => { + type => "boolean", + example => 1, + description => "show topbar page on all pages?", + safe => 1, + rebuild => 1, + }, +} + +my %pagetopbar; + +sub preprocess (@) { + my %params=@_; + + my $page=$params{page}; + return "" unless $page eq $params{destpage}; + + if (! defined $params{content}) { + $pagetopbar{$page}=undef; + } + else { + my $file = $pagesources{$page}; + my $type = pagetype($file); + + $pagetopbar{$page}= + IkiWiki::htmlize($page, $page, $type, + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, $params{content}))); + } + + return ""; +} + +my $oldfile; +my $oldcontent; + +sub topbar_content ($) { + my $page=shift; + + return delete $pagetopbar{$page} if defined $pagetopbar{$page}; + + return if ! exists $pagetopbar{$page} && + defined $config{global_topbars} && ! $config{global_topbars}; + + my $topbar_page=bestlink($page, "topbar") || return; + my $topbar_file=$pagesources{$topbar_page} || return; + my $topbar_type=pagetype($topbar_file); + + if (defined $topbar_type) { + # FIXME: This isn't quite right; it won't take into account + # adding a new topbar page. So adding such a page + # currently requires a wiki rebuild. + add_depends($page, $topbar_page); + + my $content; + if (defined $oldfile && $topbar_file eq $oldfile) { + $content=$oldcontent; + } + else { + $content=readfile(srcfile($topbar_file)); + $oldcontent=$content; + $oldfile=$topbar_file; + } + + return unless length $content; + return IkiWiki::htmlize($topbar_page, $page, $topbar_type, + IkiWiki::linkify($topbar_page, $page, + IkiWiki::preprocess($topbar_page, $page, + IkiWiki::filter($topbar_page, $page, $content)))); + } + +} + +sub pagetemplate (@) { + my %params=@_; + + my $template=$params{template}; + if ($params{destpage} eq $params{page} && + $template->query(name => "topbar")) { + my $content=topbar_content($params{destpage}); + if (defined $content && length $content) { + $template->param(topbar => $content); + } + } +} + +1 diff --git a/IkiWiki/Plugin/underlaydirbase.pm b/IkiWiki/Plugin/underlaydirbase.pm new file mode 100644 index 0000000..adc4749 --- /dev/null +++ b/IkiWiki/Plugin/underlaydirbase.pm @@ -0,0 +1,30 @@ +#!/usr/bin/perl +# Underlaydirbase plugin. +# by Jonas Smedegaard <dr@jones.dk> + +package IkiWiki::Plugin::underlaydirbase; + +use warnings; +use strict; +use IkiWiki 3.00; + +my ($master_language_code, $master_language_name); + +sub import { + hook(type => "getsetup", id => "underlaydirbase", call => \&getsetup); +} + +sub getsetup () { + return + plugin => { + safe => 0, + rebuild => 1, + }, + underlaydirbase => { + type => "string", + safe => 0, + rebuild => 1, + }, +} + +1 diff --git a/IkiWiki/Plugin/varioki.pm b/IkiWiki/Plugin/varioki.pm new file mode 100644 index 0000000..0132aad --- /dev/null +++ b/IkiWiki/Plugin/varioki.pm @@ -0,0 +1,190 @@ +#!/usr/bin/perl +# -*- Mode: Cperl -*- +# varioki.pm --- +# Author : Manoj Srivastava ( srivasta@glaurung.internal.golden-gryphon.com ) +# Created On : Wed Dec 6 22:25:44 2006 +# Created On Node : glaurung.internal.golden-gryphon.com +# Last Modified By : Manoj Srivastava +# Last Modified On : Thu Dec 7 13:07:36 2006 +# Last Machine Used: glaurung.internal.golden-gryphon.com +# Update Count : 127 +# Status : Unknown, Use with caution! +# HISTORY : +# Description : +# +# arch-tag: 6961717b-156f-4ab2-980f-0d6a973aea21 +# +# Copyright (c) 2006 Manoj Srivastava +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +require 5.002; + +package IkiWiki::Plugin::varioki; + +use warnings; +use strict; +use IkiWiki '1.00'; + +our $VERSION = "0.1"; +my $file = __FILE__; + + +=head1 NAME + +varioki - Add variables for use in ikiwiki templates + +=cut + +=head1 DESCRIPTION + +This plugin attempts to provide a means to add templates for use in +ikiwiki templates, based on a hash variable set in the ikiwiki +configuration file. The motivation for this plugin was to provide an +easy way for end users to add information to be used in templates -- +for example, my C blog entry template does fancy things with +the date components of the entry, and there was no easy way to get +that information into the template. Or if one wants to have a +different page template for the top level index page than for the rest +of the pages in the wiki (for example, to only put special content, +like, say, C play lists, only on the front page). + +This plugin hooks itsef into the C hook, and adds +parameters to the appropriate templates based on the type. For +example, the following inseted into C creates +C, C, C and C which can +then be used in your templates. The array and hash variables are only +for completeness; I suspect that the first two forms are all that are +really required. + + varioki => { + 'motto' => '"Manoj\'s musings"', + 'toplvl' => 'sub {return $page eq "index"}', + 'arrayvar' => '[0, 1, 2, 3]', + 'hashvar' => '{1, 1, 2, 2}' + }, + +Please note that the values in the hash must be simple strings which +are then eval'd, so a string value has to be double quoted, as above +(the eval strips off the outer quotes). + +=cut + + +sub import { #{{{ + hook(type => "pagetemplate", id => "varioki", call => \&pagetemplate); +} # }}} + + +=pod + +For every key in the configured hash, the corresponding value is +evaluated. Based on whether the value was a stringified scalar, code, +array, or hash, the value of the template parameter is generated on +the fly. The available variables are whatever is available to +C hook scripts, namely, C<$page>, C<$destpage>, and +C<$template>. Additionally, the global variables and functions as +defined in the Ikiwiki documentation +(L) may be used. + +=cut + +sub pagetemplate (@) { #{{{ + my %params=@_; + my $page=$params{page}; + my $template=$params{template}; + + return unless defined $config{varioki}; + for my $var (keys %{$config{varioki}}) { + my $value; + my $foo; + eval "\$foo=$config{varioki}{$var}"; + if (ref($foo) eq "CODE") { + $value = $foo->(); + } + elsif (ref($foo) eq "SCALAR") { + $value = $foo; + } + elsif (ref($foo) eq "ARRAY") { + $value = join ' ', @$foo; + } + elsif (ref($foo) eq "HASH") { + for my $i (values %$foo ) { + $value .= ' ' . "$i"; + } + } + else { + $value = $foo; + } +# warn "$page $var $value\n"; + if ($template->query(name => "$var")) { + $template->param("$var" =>"$value"); + } + } +} # }}} + +1; + +=head1 CAVEATS + +This is very inchoate, at the moment, and needs testing. Also, there +is no good way to determine how to handle hashes as values -- +currently, the code just joins all hash values with spaces, but it +would be easier for the user to just use an anonymous sub instead of +passing in a hash or an array. + +=cut + +=head1 BUGS + +Since C evals the configuration file, the values have to all +on a single physical line. This is the reason we need to use strings +and eval, instead of just passing in real anonymous sub references, +since the eval pass converts the coderef into a string of the form +"(CODE 12de345657)" which can't be dereferenced. + +=cut + +=head1 AUTHOR + +Manoj Srivastava + +=head1 COPYRIGHT AND LICENSE + +This script is a part of the Devotee package, and is + +Copyright (c) 2002 Manoj Srivastava + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +=cut + +1; + +__END__ + diff --git a/IkiWiki/Plugin/wikistatedir.pm b/IkiWiki/Plugin/wikistatedir.pm new file mode 100644 index 0000000..2f579a3 --- /dev/null +++ b/IkiWiki/Plugin/wikistatedir.pm @@ -0,0 +1,28 @@ +#!/usr/bin/perl +# Wikistatedir plugin. +# by Jonas Smedegaard <dr@jones.dk> + +package IkiWiki::Plugin::wikistatedir; + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "wikistatedir", call => \&getsetup); +} + +sub getsetup () { + return + plugin => { + safe => 0, + rebuild => 1, + }, + wikistatedir => { + type => "string", + safe => 0, + rebuild => 1, + }, +} + +1 |