Browse Source
Merge pull request #76 from plepe/wikidata-commons
Improve wikidata / wikipedia / wikimedia commons integration
master
Stephan Bösch-Plepelits
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
46 additions and
15 deletions
-
src/ImageLoader.js
-
src/twigFunctions.js
-
src/wikipedia.js
-
style.css
|
|
@ -1,3 +1,4 @@ |
|
|
|
const async = require('async') |
|
|
|
var wikidata = require('./wikidata') |
|
|
|
var wikipedia = require('./wikipedia') |
|
|
|
var cache = {} |
|
|
@ -75,23 +76,44 @@ ImageLoader.prototype.parseObject = function (data) { |
|
|
|
ImageLoader.prototype.loadWikidata = function (src, callback) { |
|
|
|
var value = src.value |
|
|
|
|
|
|
|
wikidata.load(value, function (err, result) { |
|
|
|
if (result && result.claims && result.claims.P18) { |
|
|
|
result.claims.P18.forEach(function (d) { |
|
|
|
var id = d.mainsnak.datavalue.value |
|
|
|
wikidata.load(value, (err, result) => { |
|
|
|
async.series([ |
|
|
|
(done) => { |
|
|
|
if (result && result.claims && result.claims.P18) { |
|
|
|
result.claims.P18.forEach((d) => { |
|
|
|
let id = d.mainsnak.datavalue.value |
|
|
|
|
|
|
|
if (this.found.indexOf(id) === -1) { |
|
|
|
this.found.push(id) |
|
|
|
this.data[id] = { |
|
|
|
id: id, |
|
|
|
type: 'wikimedia' |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
if (this.found.indexOf(id) === -1) { |
|
|
|
this.found.push(id) |
|
|
|
this.data[id] = { |
|
|
|
id: id, |
|
|
|
type: 'wikimedia' |
|
|
|
} |
|
|
|
done(null) |
|
|
|
}, |
|
|
|
(done) => { |
|
|
|
// wikimedia commons
|
|
|
|
if (result && result.claims && result.claims.P373) { |
|
|
|
result.claims.P373.forEach((d) => { |
|
|
|
let value = 'Category:' + d.mainsnak.datavalue.value |
|
|
|
|
|
|
|
this.sources.push({ |
|
|
|
type: 'wikimedia_commons', |
|
|
|
value |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}.bind(this)) |
|
|
|
} |
|
|
|
|
|
|
|
callback(err) |
|
|
|
}.bind(this)) |
|
|
|
done(null) |
|
|
|
} |
|
|
|
], (err) => { |
|
|
|
callback(err) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
ImageLoader.prototype.loadWikimediaCommons = function (src, callback) { |
|
|
|
|
|
@ -89,3 +89,10 @@ OverpassLayer.twig.extendFunction('evaluate', function (tags) { |
|
|
|
var d = global.currentCategory.layer.mainlayer.evaluate(ob) |
|
|
|
return d |
|
|
|
}) |
|
|
|
OverpassLayer.twig.extendFunction('enumerate', function (value) { |
|
|
|
let list = value.split(/,/) |
|
|
|
if (list.length > 1) { |
|
|
|
return list.slice(0, -1).join(lang_str.enumerate_join) + lang_str.enumerate_last + list.slice(-1)[0] |
|
|
|
} |
|
|
|
return value |
|
|
|
}) |
|
|
@ -32,7 +32,7 @@ function prepare (div) { |
|
|
|
} |
|
|
|
|
|
|
|
var p = content.firstChild.firstChild |
|
|
|
while (p && p.tagName !== 'P') { |
|
|
|
while (p && (p.tagName !== 'P' || p.className !== '' || p.textContent.match(/^\s*$/))) { |
|
|
|
p = p.nextSibling |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -389,6 +389,8 @@ a:active { |
|
|
|
} |
|
|
|
#contentDetails h4 { |
|
|
|
clear: both; |
|
|
|
text-decoration: underline; |
|
|
|
font-weight: bold; |
|
|
|
} |
|
|
|
.wikipedia .reference { |
|
|
|
display: none; |
|
|
|