-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
57 lines (45 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//var dots = require("dot").process({path: "views"});
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var APIKey = hexo.config.google_maps_api_key || false;
var filePath = path.join(__dirname, 'google-maps-template.html');
var tags = hexo.extend.tag;
function googleMaps(args, content) {
var template = fs.readFileSync(filePath).toString().trim();
var markers = [];
function toMarker(d) {
var list = d.split(',');
return {
name: list[0] || '',
latitude: parseFloat(list[1]),
longitude: parseFloat(list[2]),
icon: (list[3] || '').trim()
};
}
if (content.length) {
markers = _.map(content.split('\n'), toMarker);
}
var model = {
id: 'googleMap' + ((Math.random() * 9999) | 0),
width: args[3] || '100%',
height: args[4] || '250px',
zoom: args[2] || 8,
scrollwheel: false,
center: {
latitude: args[0] || markers[0].latitude,
longitude: args[1] || markers[0].longitude,
},
markers: markers,
apikey: APIKey
};
var templateFunction = _.template(template);
var compiledMap = templateFunction(model);
// console.log(compiledMap);
// console.log('\n\n\n', args, content);
return compiledMap;
}
tags.register('googlemaps', googleMaps, {
async: true,
ends: true
});