Browse Source

Wikidata/TwigJS: filter 'wikidataEntity' returns structured data of the object

master
parent
commit
1a270fb71f
  1. 1
      doc/TwigJS.md
  2. 13
      src/wikidata.js

1
doc/TwigJS.md

@ -77,6 +77,7 @@ Extra filters:
* filter `enumerate`: enumerate the given list, e.g. "foo, bar, and bla". Input either an array (`[ "foo", "bar", "bla" ]|enumerate`) or a string with `;` as separator (`"foo;bar;bla"|enumerate`).
* filter `debug`: print the value (and further arguments) to the javascript console (via `console.log()`)
* filter `wikipediaAbstract`: shows the abstract of a Wikipedia article in the selected data language (or, if not available, the language which was used in input, resp. 'en' for Wikidata input). Input is either 'language:article' (e.g. 'en:Douglas Adams') or a wikidata id (e.g. 'Q42').
* filter `wikidataEntity`: returns the wikidata entity in structured form (or `null` if the entity is not cached or `false` if it does not exist). Example: https://www.wikidata.org/wiki/Special:EntityData/Q42.json
Notes:
* Variables will automatically be HTML escaped, unless the filter raw is used, e.g.: {{ tags.name|raw }}

13
src/wikidata.js

@ -1,3 +1,5 @@
const OverpassLayer = require('overpass-layer')
var httpGet = require('./httpGet')
var loadClash = {}
var cache = {}
@ -22,6 +24,7 @@ function wikidataLoad (id, callback) {
if (!result.entities || !result.entities[id]) {
console.log('invalid result', result)
cache[id] = false
return callback(err, null)
}
@ -39,3 +42,13 @@ function wikidataLoad (id, callback) {
module.exports = {
load: wikidataLoad
}
OverpassLayer.twig.extendFilter('wikidataEntity', function (value, param) {
if (value in cache) {
return cache[value]
}
wikidataLoad(value, () => {})
return null
})
Loading…
Cancel
Save