jekyll-maps 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/jekyll-maps/google_map.html +58 -0
- data/lib/jekyll-maps/google_map_tag.rb +55 -2
- data/lib/jekyll-maps/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b00622803d1ea55c166f6dd5a7eb8603092d07f
|
4
|
+
data.tar.gz: 8faf047b0c0b139ca3141f6e1d8f596b70ce9575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7bd47ce22e43f4a26b5659295164f4900fd2ad7bef769838f231991fdd4fade909531cb8a5d9ce60e31461a8d6afdc5bb03f45b0ddacdda3f23280b62bf0990
|
7
|
+
data.tar.gz: a5f32d206c1a08008a6145ddfcf35d60a0721c4dd9367a0df68ee70655a5709f85ffa9dc5a11104617a9521b40b963e215023723ada79c2ddfd894460a760529
|
data/README.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# jekyll-
|
1
|
+
# jekyll-maps
|
2
2
|
Google Maps support in Jekyll blog to easily embed maps with posts' locations
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<div id='google-map'></div>
|
2
|
+
|
3
|
+
<script type='text/javascript'>
|
4
|
+
var jekyllMaps = (function () {
|
5
|
+
'use strict';
|
6
|
+
|
7
|
+
return {
|
8
|
+
loadScript: function (url) {
|
9
|
+
var script = document.createElement('script');
|
10
|
+
script.type = 'text/javascript';
|
11
|
+
script.src = url;
|
12
|
+
document.body.appendChild(script);
|
13
|
+
},
|
14
|
+
initialize: function () {
|
15
|
+
this.options = {
|
16
|
+
center: new google.maps.LatLng(0, 0),
|
17
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
18
|
+
zoom: 3
|
19
|
+
}
|
20
|
+
this.map = new google.maps.Map(document.getElementById('google-map'), this.options);
|
21
|
+
this.showMarkers({{ locations }});
|
22
|
+
},
|
23
|
+
showMarkers: function (locations) {
|
24
|
+
var map = this.map,
|
25
|
+
bounds = new google.maps.LatLngBounds(),
|
26
|
+
markers = locations.map(function (location) {
|
27
|
+
var position = new google.maps.LatLng(location.latitude, location.longitude);
|
28
|
+
var marker = new google.maps.Marker({
|
29
|
+
position: position,
|
30
|
+
map: map,
|
31
|
+
title: location.title,
|
32
|
+
url: location.url
|
33
|
+
});
|
34
|
+
|
35
|
+
marker.addListener('click', function () {
|
36
|
+
if (this.url) {
|
37
|
+
window.location.href = this.url;
|
38
|
+
}
|
39
|
+
});
|
40
|
+
bounds.extend(position);
|
41
|
+
|
42
|
+
return marker;
|
43
|
+
});
|
44
|
+
|
45
|
+
new MarkerClusterer(map, markers, {
|
46
|
+
gridSize: 25,
|
47
|
+
imagePath: 'https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m'
|
48
|
+
});
|
49
|
+
map.fitBounds(bounds);
|
50
|
+
},
|
51
|
+
};
|
52
|
+
}());
|
53
|
+
|
54
|
+
window.onload = function () {
|
55
|
+
jekyllMaps.loadScript('https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js');
|
56
|
+
jekyllMaps.loadScript('http://maps.googleapis.com/maps/api/js?callback=jekyllMaps.initialize');
|
57
|
+
};
|
58
|
+
</script>
|
@@ -1,11 +1,64 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module Maps
|
3
3
|
class GoogleMapTag < Liquid::Tag
|
4
|
-
|
4
|
+
attr_accessor :context
|
5
|
+
|
6
|
+
def initialize(_, args, _)
|
7
|
+
unless args.empty?
|
8
|
+
@filter_key = args.split(":").first.strip
|
9
|
+
@filter_value = args.split(":").last.strip
|
10
|
+
end
|
11
|
+
|
5
12
|
super
|
6
13
|
end
|
7
14
|
|
8
|
-
def render(
|
15
|
+
def render(context)
|
16
|
+
@context = context
|
17
|
+
template.render!({ "locations" => locations.to_json })
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def locations
|
22
|
+
filter_posts.map do |post|
|
23
|
+
{
|
24
|
+
:latitude => post["location"]["latitude"],
|
25
|
+
:longitude => post["location"]["longitude"],
|
26
|
+
:title => post["title"],
|
27
|
+
:url => post.url
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def filter_posts
|
33
|
+
posts = context.registers[:site].posts.docs.reject do |post|
|
34
|
+
post["location"].nil? || post["location"].empty?
|
35
|
+
end
|
36
|
+
if @filter_key
|
37
|
+
posts.reject do |post|
|
38
|
+
post[@filter_key].nil? || post[@filter_key] != @filter_value
|
39
|
+
end
|
40
|
+
else
|
41
|
+
posts
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def template
|
47
|
+
@template ||= Liquid::Template.parse template_contents
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def template_contents
|
52
|
+
@template_contents ||= begin
|
53
|
+
File.read(template_path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def template_path
|
59
|
+
@template_path ||= begin
|
60
|
+
File.expand_path "./google_map.html", File.dirname(__FILE__)
|
61
|
+
end
|
9
62
|
end
|
10
63
|
end
|
11
64
|
end
|
data/lib/jekyll-maps/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoliy Yastreb
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- jekyll-maps.gemspec
|
83
83
|
- lib/jekyll-maps.rb
|
84
|
+
- lib/jekyll-maps/google_map.html
|
84
85
|
- lib/jekyll-maps/google_map_tag.rb
|
85
86
|
- lib/jekyll-maps/version.rb
|
86
87
|
- script/bootstrap
|