jekyll-geocode 0.1 → 0.2
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 +13 -7
- data/lib/jekyll_geocode.rb +63 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 865de4a807502167c5b10544e8a0e11bace6aced
|
4
|
+
data.tar.gz: 521cd82b9052eb92b35175dc60a8f9da5a7be517
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8865d2f87f4cc5a2def825745e4cb0578ed4b36ebe5a5643b42fc5b28cc99d80e864526b8fb03f8d904a545c6b74ff26493338982096f36698193f082cea4f78
|
7
|
+
data.tar.gz: 7041189666286518b889ba6a523a5204433409d05d0292ec8cffc2893219b54cbd82fa62efd807ddb6e551679980c8437c76ea6f40965035fcf5b1cdc2e29014
|
data/README.md
CHANGED
@@ -12,17 +12,23 @@ I took the [Nominatim](https://nominatim.openstreetmap.org/) open source service
|
|
12
12
|
## Example of YAML : _data/members.yml
|
13
13
|
|
14
14
|
```yaml
|
15
|
+
- name: "Bertrand Keller"
|
16
|
+
street: "place du vieux marché"
|
17
|
+
postcode: "76000"
|
18
|
+
city: "Rouen"
|
19
|
+
region: "normandy"
|
20
|
+
country: "france"
|
15
21
|
- name: "John Doe"
|
16
|
-
|
17
|
-
postcode: 76190
|
18
|
-
city: "Yvetot"
|
22
|
+
street: "rue Mendès France"
|
23
|
+
postcode: "76190"
|
24
|
+
city: "Yvetot"
|
19
25
|
region: "normandy"
|
20
26
|
country: "france"
|
21
27
|
- name: "Samuel Le Bihan"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
region: "
|
28
|
+
street: "Place Niemeyer"
|
29
|
+
city: "Le Havre"
|
30
|
+
postcode: "76600"
|
31
|
+
region: "normandy"
|
26
32
|
country: "france"
|
27
33
|
```
|
28
34
|
|
data/lib/jekyll_geocode.rb
CHANGED
@@ -4,11 +4,15 @@ require 'yaml'
|
|
4
4
|
require 'open-uri'
|
5
5
|
require "i18n"
|
6
6
|
|
7
|
-
module
|
7
|
+
module Jekyll_Geocode
|
8
8
|
class Generator < Jekyll::Generator
|
9
9
|
safe true
|
10
10
|
priority :highest
|
11
11
|
|
12
|
+
def request_service(url)
|
13
|
+
JSON.load(open(URI.encode(url)))
|
14
|
+
end
|
15
|
+
|
12
16
|
def generate(site)
|
13
17
|
|
14
18
|
#regEx for removing empty line
|
@@ -57,54 +61,76 @@ module Jekyll_Get
|
|
57
61
|
|
58
62
|
# Loop YML file
|
59
63
|
members.each do |d|
|
60
|
-
|
61
|
-
if
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
geo_name_field = d[geo_name].downcase.tr(" ", "-")
|
65
|
+
if d[geo_postcode]
|
66
|
+
geo_postcode_field = ", #{d[geo_postcode]}"
|
67
|
+
end
|
68
|
+
if d[geo_city]
|
69
|
+
geo_city_field = ", #{d[geo_city]}"
|
70
|
+
end
|
71
|
+
if d[geo_region]
|
72
|
+
geo_region_field = ", #{d[geo_region]}"
|
73
|
+
end
|
74
|
+
if d[geo_country]
|
75
|
+
geo_country_field = ", #{d[geo_country]}"
|
76
|
+
end
|
77
|
+
geo_coord = "#{d[geo_address]}#{geo_postcode_field}#{geo_city_field}#{geo_region_field}#{geo_country_field}"
|
78
|
+
geo_request = "#{geo_service}#{geo_coord}&limit=1"
|
79
|
+
p geo_request
|
80
|
+
|
81
|
+
|
82
|
+
# Loop for an YML output
|
83
|
+
if outputfile
|
84
|
+
|
85
|
+
# No cache at the first loop
|
86
|
+
geo_cache = true
|
87
|
+
|
88
|
+
# Read the YML file
|
89
|
+
if File.file?(path_yaml)
|
90
|
+
file_yaml = YAML.load(File.open(path_yaml))
|
71
91
|
end
|
72
|
-
|
73
|
-
|
92
|
+
|
93
|
+
# If YML file test if and address are the same as in the source file
|
94
|
+
if file_yaml
|
95
|
+
file_yaml.each do |coordinates|
|
96
|
+
if coordinates['address'] == geo_coord
|
97
|
+
geo_cache = false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
else
|
101
|
+
geo_cache = true
|
74
102
|
end
|
75
|
-
json = URI.encode("#{geo_service}#{d[geo_address]}#{geo_postcode_field}#{geo_city_field}#{geo_region_field}#{geo_country_field}&limit=1")
|
76
|
-
source = JSON.load(open(json))
|
77
103
|
|
78
|
-
#
|
79
|
-
if
|
80
|
-
|
81
|
-
|
104
|
+
# Write data
|
105
|
+
if geo_cache == true
|
106
|
+
p "geocode is requesting #{geo_coord}"
|
107
|
+
request_service(geo_request).each do |coordinates|
|
108
|
+
data = [ "title" => "#{d[geo_name]}", "url" => "##{d[geo_name]}", "data_set" => "01", "location" => { "latitude" => "#{coordinates["lat"]}","longitude" => "#{coordinates["lon"]}" }, "address" => "#{geo_coord}" ]
|
82
109
|
data_yml = data.to_yaml
|
83
|
-
#
|
110
|
+
# Add data in the YML file
|
84
111
|
if !File.file?(path_yaml)
|
85
112
|
File.open(path_yaml, "w") {|f| f.write(data_yml) }
|
86
113
|
end
|
87
|
-
# Test if there is yaml files and add data recursively
|
88
114
|
if File.file?(path_yaml)
|
89
115
|
File.open(path_yaml, 'a') { |f|
|
90
|
-
|
91
|
-
f.puts data_yml_simple
|
116
|
+
f.puts data_yml.gsub("---", "").gsub(regEx, '')
|
92
117
|
}
|
93
|
-
# Load YML file
|
94
|
-
file_yaml = YAML.load(File.open(path_yaml))
|
95
|
-
|
96
|
-
File.open(path_yaml, "w") {|f| f.write(file_yaml_uniq.to_yaml) }
|
118
|
+
# Load YML file => remove duplicated entries
|
119
|
+
file_yaml = YAML.load(File.open(path_yaml)).uniq { |s| s.first }
|
120
|
+
File.open(path_yaml, "w") {|f| f.write(file_yaml.to_yaml) }
|
97
121
|
end
|
98
122
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# JSON output :: Test if a JSON file exists for performance issues
|
127
|
+
if !outputfile && !File.file?("#{data_source}/#{d[geo_name]}.json")
|
128
|
+
site.data[geo_name_field] = request_service(geo_request)
|
129
|
+
#Create a JSON files if cache is enabled
|
130
|
+
if site.config['jekyll_geocode']['cache']
|
131
|
+
path_json = "#{data_source}/#{geo_name_field}.json"
|
132
|
+
open(path_json, 'wb') do |file|
|
133
|
+
file << JSON.generate(site.data[geo_name_field])
|
108
134
|
end
|
109
135
|
end
|
110
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-geocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertrand Keller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|