summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/meta.pm20
-rw-r--r--IkiWiki/Plugin/osm.pm100
2 files changed, 95 insertions, 25 deletions
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 421f1dc..e7b96bd 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -107,12 +107,12 @@ sub preprocess (@) {
# fallthrough
}
elsif ($key eq 'license') {
- push @{$metaheaders{$page}}, '<link rel="license" href="#page_license" />';
+ push @{$metaheaders{$page}}, '<link rel="license" href="#pagelicense" />';
$pagestate{$page}{meta}{license}=$value;
return "";
}
elsif ($key eq 'copyright') {
- push @{$metaheaders{$page}}, '<link rel="copyright" href="#page_copyright" />';
+ push @{$metaheaders{$page}}, '<link rel="copyright" href="#pagecopyright" />';
$pagestate{$page}{meta}{copyright}=$value;
return "";
}
@@ -121,6 +121,18 @@ sub preprocess (@) {
add_link($page, $value);
return "";
}
+ elsif ($key eq 'enclosure') {
+ my $link=bestlink($page, $value);
+ if (! length $link) {
+ error gettext("enclosure not found")
+ }
+ add_depends($page, $link, deptype("presence"));
+
+ $value=urlto($link, $page, 1);
+ $pagestate{$page}{meta}{enclosure}=$value;
+ $pagestate{$page}{meta}{enclosurefile}=$link;
+ # fallthrough
+ }
elsif ($key eq 'author') {
$pagestate{$page}{meta}{author}=$value;
if (exists $params{sortas}) {
@@ -318,6 +330,10 @@ sub pagetemplate (@) {
$template->param(title_overridden => 1);
}
+ if (exists $pagestate{$page}{meta}{enclosure}) {
+ $template->param(enclosure => HTML::Entities::encode_entities(IkiWiki::urlabs($pagestate{$page}{meta}{enclosure}, $config{url})));
+ }
+
foreach my $field (qw{authorurl}) {
eval q{use HTML::Entities};
$template->param($field => HTML::Entities::encode_entities($pagestate{$page}{meta}{$field}))
diff --git a/IkiWiki/Plugin/osm.pm b/IkiWiki/Plugin/osm.pm
index c9c5646..c9650d0 100644
--- a/IkiWiki/Plugin/osm.pm
+++ b/IkiWiki/Plugin/osm.pm
@@ -60,6 +60,46 @@ sub getsetup () {
safe => 0,
rebuild => 1,
},
+ osm_openlayers_url => {
+ type => "string",
+ example => "http://www.openlayers.org/api/OpenLayers.js",
+ description => "Url for the OpenLayers.js file",
+ safe => 0,
+ rebuild => 1,
+ },
+ osm_layers => {
+ type => "string",
+ example => { 'OSM', 'GoogleSatellite' },
+ description => "Layers to use in the map. Can be either the 'OSM' string or a type option for Google maps (GoogleNormal, GoogleSatellite, GoogleHybrid or GooglePhysical). It can also be an arbitrary URL in a syntax acceptable for OpenLayers.Layer.OSM.url parameter.",
+ safe => 0,
+ rebuild => 1,
+ },
+ osm_google_apikey => {
+ type => "string",
+ example => "",
+ description => "Google maps API key, Google layer not used if missing, see https://code.google.com/apis/console/ to get an API key",
+ safe => 1,
+ rebuild => 1,
+ },
+}
+
+sub register_rendered_files {
+ my $map = shift;
+ my $page = shift;
+ my $dest = shift;
+
+ if ($page eq $dest) {
+ my %formats = get_formats();
+ if ($formats{'GeoJSON'}) {
+ will_render($page, "$map/pois.json");
+ }
+ if ($formats{'CSV'}) {
+ will_render($page, "$map/pois.txt");
+ }
+ if ($formats{'KML'}) {
+ will_render($page, "$map/pois.kml");
+ }
+ }
}
sub preprocess {
@@ -98,6 +138,8 @@ sub preprocess {
);
}
+ register_rendered_files($map, $page, $dest);
+
$pagestate{$page}{'osm'}{$map}{'displays'}{$name} = {
height => $height,
width => $width,
@@ -108,6 +150,7 @@ sub preprocess {
lat => $lat,
lon => $lon,
href => $href,
+ google_apikey => $config{'osm_google_apikey'},
};
return "<div id=\"mapdiv-$name\"></div>";
}
@@ -149,19 +192,9 @@ sub process_waypoint {
}
}
$icon = urlto($icon, $dest, 1);
+ $icon =~ s!/*$!!; # hack - urlto shouldn't be appending a slash in the first place
$tag = '' unless $tag;
- if ($page eq $dest) {
- my %formats = get_formats();
- if ($formats{'GeoJSON'}) {
- will_render($page, "$map/pois.json");
- }
- if ($formats{'CSV'}) {
- will_render($page, "$map/pois.txt");
- }
- if ($formats{'KML'}) {
- will_render($page, "$map/pois.kml");
- }
- }
+ register_rendered_files($map, $page, $dest);
$pagestate{$page}{'osm'}{$map}{'waypoints'}{$name} = {
page => $page,
desc => $desc,
@@ -327,22 +360,29 @@ sub writekml($;$) {
foreach my $map (keys %waypoints) {
my $output;
my $writer = XML::Writer->new( OUTPUT => \$output,
- DATA_MODE => 1, ENCODING => 'UTF-8');
+ DATA_MODE => 1, DATA_INDENT => ' ', ENCODING => 'UTF-8');
$writer->xmlDecl();
$writer->startTag("kml", "xmlns" => "http://www.opengis.net/kml/2.2");
+ $writer->startTag("Document");
# first pass: get the icons
+ my %tags_map = (); # keep track of tags seen
foreach my $name (keys %{$waypoints{$map}}) {
my %options = %{$waypoints{$map}{$name}};
- $writer->startTag("Style", id => $options{tag});
- $writer->startTag("IconStyle");
- $writer->startTag("Icon");
- $writer->startTag("href");
- $writer->characters($options{icon});
- $writer->endTag();
- $writer->endTag();
- $writer->endTag();
- $writer->endTag();
+ if (!$tags_map{$options{tag}}) {
+ debug("found new style " . $options{tag});
+ $tags_map{$options{tag}} = ();
+ $writer->startTag("Style", id => $options{tag});
+ $writer->startTag("IconStyle");
+ $writer->startTag("Icon");
+ $writer->startTag("href");
+ $writer->characters($options{icon});
+ $writer->endTag();
+ $writer->endTag();
+ $writer->endTag();
+ $writer->endTag();
+ }
+ $tags_map{$options{tag}}{$name} = \%options;
}
foreach my $name (keys %{$waypoints{$map}}) {
@@ -389,6 +429,7 @@ sub writekml($;$) {
$writer->endTag();
}
$writer->endTag();
+ $writer->endTag();
$writer->end();
writefile("pois.kml", $config{destdir} . "/$map", $output);
@@ -500,6 +541,7 @@ sub cgi($) {
zoom => "urlParams['zoom']",
fullscreen => 1,
editable => 1,
+ google_apikey => $config{'osm_google_apikey'},
);
print "</script>";
print "</body></html>";
@@ -509,9 +551,14 @@ sub cgi($) {
sub embed_map_code(;$) {
my $page=shift;
- return '<script src="http://www.openlayers.org/api/OpenLayers.js" type="text/javascript" charset="utf-8"></script>'.
+ 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";
+ if ($config{'osm_google_apikey'}) {
+ $code .= '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$config{'osm_google_apikey'}.'&sensor=false" type="text/javascript" charset="utf-8"></script>';
+ }
+ return $code;
}
sub map_setup_code($;@) {
@@ -519,6 +566,8 @@ sub map_setup_code($;@) {
my $name=shift;
my %options=@_;
+ my $mapurl = $config{osm_map_url};
+
eval q{use JSON};
error $@ if $@;
@@ -535,6 +584,11 @@ sub map_setup_code($;@) {
$options{'kmlurl'} = urlto($map."/pois.kml");
}
+ if ($mapurl) {
+ $options{'mapurl'} = $mapurl;
+ }
+ $options{'layers'} = $config{osm_layers};
+
return "mapsetup('mapdiv-$name', " . to_json(\%options) . ");";
}