Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# hexo-generator-postmap | ||
|
||
Generates a locations.xml and page showing an interactive Google map embed with your posts/pages marked on the map with pop up links to your posts/pages. | ||
|
||
This package is still pretty rough around the edges and is not recommended for anything important yet. | ||
|
||
You should tag posts by putting the lat and long in the location metadata: | ||
|
||
```yaml | ||
location: [50.092953, 14.445974] | ||
``` | ||
|
||
## Install | ||
|
||
``` bash | ||
$ npm install hexo-generator-postmap --save | ||
``` | ||
|
||
- Hexo 3: 0.1.x | ||
|
||
## Options | ||
|
||
You can configure this plugin in `_config.yml`. | ||
|
||
``` yaml | ||
postmap: | ||
xmlpath: 'locations.xml', | ||
mappagestub: 'mapofposts', | ||
mappagetitle: 'Map of posts' | ||
``` | ||
|
||
- **xmlpath** - Path to your locations.xml document. | ||
- **mappagestub** - The url friendly name of your map page without slashes (eg mapofposts) | ||
- **mappagetitle** - The human friendly name of your map page, used as the hexo title of page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var merge = require('utils-merge'); | ||
var pathFn = require('path'); | ||
|
||
var config = hexo.config.postmap = merge({ | ||
xmlpath: 'locations.xml', | ||
mappagestub: 'postmap', | ||
mappagetitle: 'Map of posts' | ||
}, hexo.config.postmap); | ||
|
||
if (!pathFn.extname(config.locationpath)){ | ||
config.locationpath += '.xml'; | ||
} | ||
|
||
hexo.extend.generator.register('postmap', require('./lib/generator')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var ejs = require('ejs'); | ||
var pathFn = require('path'); | ||
var fs = require('fs'); | ||
|
||
var locationsSrc = pathFn.join(__dirname, '../locations.ejs'); | ||
var locationsTmpl = ejs.compile(fs.readFileSync(locationsSrc, 'utf8')); | ||
|
||
var mapEmbedSrc = pathFn.join(__dirname, '../mapembed.ejs'); | ||
var mapEmbedTmpl = ejs.compile(fs.readFileSync(mapEmbedSrc, 'utf8')); | ||
|
||
module.exports = function(locals) { | ||
var config = this.config; | ||
|
||
var posts = [].concat(locals.posts.toArray(), locals.pages.toArray()) | ||
.filter(function(post) { | ||
return post.location != null; | ||
}); | ||
|
||
var xml = locationsTmpl({ | ||
config: config, | ||
posts: posts | ||
}); | ||
|
||
return [{ | ||
path: config.postmap.xmlpath, | ||
data: xml | ||
}, { | ||
path: config.postmap.mappagestub + '/index.html', | ||
data: { | ||
'title': config.postmap.mappagetitle, | ||
'content': mapEmbedTmpl({ | ||
'url': encodeURI(config.root + config.postmap.xmlpath) | ||
}), | ||
'description': 'A map of geo-tagged posts on ' + config.title | ||
}, | ||
layout: ['page'] | ||
}]; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<locations> | ||
<% var url = config.url + config.root %> | ||
<% posts.forEach(function(post){ %> | ||
<location | ||
url="<%- encodeURI(url + post.path) %>" | ||
lastmod="<%= post.updated.toISOString() || post.date.toISOString() %>" | ||
lat="<%= post.location[0] %>" | ||
lng="<%= post.location[1] %>" | ||
title="<%= post.title %>"> | ||
</location> | ||
<% }) %> | ||
</locations> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
<script src="https://maps.googleapis.com/maps/api/js"></script> | ||
|
||
<script type="text/javascript"> | ||
function initialise() { | ||
myLatlng = new google.maps.LatLng(54.559323, -3.321304); | ||
mapOptions = { | ||
zoom: 1, | ||
center: myLatlng, | ||
mapTypeId: google.maps.MapTypeId.ROADMAP, | ||
} | ||
geocoder = new google.maps.Geocoder(); | ||
infoWindow = new google.maps.InfoWindow; | ||
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | ||
xmlUrl = "<%= url %>"; | ||
loadMarkers(); | ||
} | ||
function downloadUrl(url, callback) { | ||
var request = window.ActiveXObject ? | ||
new ActiveXObject('Microsoft.XMLHTTP') : | ||
new XMLHttpRequest; | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4) { | ||
//request.onreadystatechange = doNothing; | ||
callback(request, request.status); | ||
} | ||
}; | ||
request.open('GET', url, true); | ||
request.send(null); | ||
} | ||
function bindInfoWindow(marker, map, infoWindow, html) { | ||
google.maps.event.addListener(marker, 'click', function() { | ||
infoWindow.setContent(html); | ||
infoWindow.open(map, marker); | ||
}); | ||
} | ||
function loadMarkers() { | ||
map.markers = map.markers || [] | ||
downloadUrl(xmlUrl, function(data) { | ||
var xml = data.responseXML; | ||
markers = xml.documentElement.getElementsByTagName("location"); | ||
for (var i = 0; i < markers.length; i++) { | ||
var title = markers[i].getAttribute("title"); | ||
var url = markers[i].getAttribute("url"); | ||
var lastmod = markers[i].getAttribute("lastmod"); | ||
var point = new google.maps.LatLng( | ||
parseFloat(markers[i].getAttribute("lat")), | ||
parseFloat(markers[i].getAttribute("lng"))); | ||
var html = "<div class='infowindow'><b>" + title + "</b> <br/><a href='" + url + "'>" + url + "</a><br/> " + lastmod + " <br/></div>"; | ||
var marker = new google.maps.Marker({ | ||
map: map, | ||
position: point, | ||
title: title | ||
}); | ||
map.markers.push(marker); | ||
bindInfoWindow(marker, map, infoWindow, html); | ||
} | ||
}); | ||
} | ||
google.maps.event.addDomListener(window, 'load', initialise); | ||
</script> | ||
|
||
<div id="map-canvas" style="height: 500px; width: 90%;"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "hexo-generator-postmap", | ||
"version": "0.1.0", | ||
"description": "A plugin for the Hexo static site generator that generates an archive page with geo-tagged posts and pages on an interactive google map", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"hexo", | ||
"maps", | ||
"google", | ||
"plugin" | ||
], | ||
"author": { | ||
"name": "Jamie I", | ||
"url" : "http://jamiei.com/" | ||
}, | ||
"dependencies": { | ||
"ejs": "^1.0.0", | ||
"utils-merge": "^1.0.0" | ||
}, | ||
"repository" : | ||
{ | ||
"type" : "git", | ||
"url" : "https://github.com/jamiei/hexo-generator-postmap.git" | ||
}, | ||
"license": "MIT", | ||
"readme": "README.md" | ||
} |