Add quickfacts-box to wikipedia article

This commit is contained in:
Pieter Vander Vennet 2021-10-18 20:40:24 +02:00
parent c1d21fcbe5
commit 902f32ba4b
14 changed files with 343 additions and 50 deletions

View file

@ -1,5 +1,6 @@
import {Utils} from "../../Utils"; import {Utils} from "../../Utils";
import {UIEventSource} from "../UIEventSource"; import {UIEventSource} from "../UIEventSource";
import * as wds from "wikibase-sdk"
export class WikidataResponse { export class WikidataResponse {
public readonly id: string public readonly id: string
@ -63,22 +64,15 @@ export class WikidataResponse {
} }
static extractClaims(claimsJson: any): Map<string, Set<string>> { static extractClaims(claimsJson: any): Map<string, Set<string>> {
const claims = new Map<string, Set<string>>();
for (const claimId in claimsJson) {
const claimsList: any[] = claimsJson[claimId] const simplified = wds.simplify.claims(claimsJson, {
const values = new Set<string>() timeConverter: 'simple-day'
for (const claim of claimsList) { })
let value = claim.mainsnak?.datavalue?.value;
if (value === undefined) { const claims = new Map<string, Set<string>>();
continue; for (const claimId in simplified) {
} const claimsList: any[] = simplified[claimId]
if (value.id !== undefined) { claims.set(claimId, new Set(claimsList));
value = value.id
}
values.add(value)
}
claims.set(claimId, values);
} }
return claims return claims
} }

View file

@ -20,6 +20,7 @@ export default class Wikipedia {
"ambox", "ambox",
"mw-editsection", "mw-editsection",
"mw-selflink", "mw-selflink",
"mw-empty-elt",
"hatnote" // Often redirects "hatnote" // Often redirects
] ]

View file

@ -12,6 +12,7 @@ import {WikimediaImageProvider} from "../../Logic/ImageProviders/WikimediaImageP
import Link from "../Base/Link"; import Link from "../Base/Link";
import Svg from "../../Svg"; import Svg from "../../Svg";
import BaseUIElement from "../BaseUIElement"; import BaseUIElement from "../BaseUIElement";
import {Utils} from "../../Utils";
export default class WikidataPreviewBox extends VariableUiElement { export default class WikidataPreviewBox extends VariableUiElement {
@ -54,9 +55,11 @@ export default class WikidataPreviewBox extends VariableUiElement {
Wikidata.IdToArticle(wikidata.id), true).SetClass("must-link") Wikidata.IdToArticle(wikidata.id), true).SetClass("must-link")
let info = new Combine([ let info = new Combine([
new Combine([Translation.fromMap(wikidata.labels).SetClass("font-bold"), new Combine(
[Translation.fromMap(wikidata.labels).SetClass("font-bold"),
link]).SetClass("flex justify-between"), link]).SetClass("flex justify-between"),
Translation.fromMap(wikidata.descriptions) Translation.fromMap(wikidata.descriptions),
WikidataPreviewBox.QuickFacts(wikidata)
]).SetClass("flex flex-col link-underline") ]).SetClass("flex flex-col link-underline")
@ -77,4 +80,89 @@ export default class WikidataPreviewBox extends VariableUiElement {
return info return info
} }
private static isHuman = [
{p: 31/*is a*/, q: 5 /* human */},
]
// @ts-ignore
// @ts-ignore
private static extraProperties: {
requires?: { p: number, q?: number }[],
property: string,
display: Translation | Map<string, string | (() => BaseUIElement) /*If translation: Subs({value: * }) */>
}[] = [
{
requires: WikidataPreviewBox.isHuman,
property: "P21",
display: new Map([
['Q6581097', () => Svg.gender_male_ui().SetStyle("width: 1rem; height: auto")],
['Q6581072', () => Svg.gender_female_ui().SetStyle("width: 1rem; height: auto")],
['Q1097630',() => Svg.gender_inter_ui().SetStyle("width: 1rem; height: auto")],
['Q1052281',() => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transwomen'*/],
['Q2449503',() => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transmen'*/],
['Q48270',() => Svg.gender_queer_ui().SetStyle("width: 1rem; height: auto")]
])
},
{
property: "P569",
requires: WikidataPreviewBox.isHuman,
display: new Translation({
"*":"Born: {value}"
})
},
{
property: "P570",
requires: WikidataPreviewBox.isHuman,
display: new Translation({
"*":"Died: {value}"
})
}
]
public static QuickFacts(wikidata: WikidataResponse): BaseUIElement {
const els : BaseUIElement[] = []
for (const extraProperty of WikidataPreviewBox.extraProperties) {
let hasAllRequirements =true
for (const requirement of extraProperty.requires) {
if(!wikidata.claims.has("P"+requirement.p)){
hasAllRequirements = false;
break
}
if(!wikidata.claims.get("P"+requirement.p).has("Q"+requirement.q)){
hasAllRequirements = false;
break
}
}
if(!hasAllRequirements){
continue
}
const key = extraProperty.property
const display = extraProperty.display
const value: string[] = Array.from(wikidata.claims.get(key))
if(value === undefined){
continue
}
if(display instanceof Translation){
els.push(display.Subs({value: value.join(", ")}).SetClass("m-2"))
continue
}
console.log("Display:", display, "key:",key)
const constructors = Utils.NoNull(value.map(property => display.get(property)))
const elems = constructors.map(v => {
if(typeof v === "string"){
return new FixedUiElement(v)
}else{
return v();
}
})
els.push(new Combine(elems).SetClass("flex m-2"))
}
if(els.length === 0){
return undefined;
}
return new Combine(els).SetClass("flex")
}
} }

View file

@ -182,6 +182,7 @@ export default class WikipediaBox extends Combine {
language: language language: language
}) })
const wp = Translations.t.general.wikipedia const wp = Translations.t.general.wikipedia
const quickFacts = WikidataPreviewBox.QuickFacts(wikidata);
const contents: UIEventSource<string | BaseUIElement> = htmlContent.map(htmlContent => { const contents: UIEventSource<string | BaseUIElement> = htmlContent.map(htmlContent => {
if (htmlContent === undefined) { if (htmlContent === undefined) {
// Still loading // Still loading
@ -198,7 +199,9 @@ export default class WikipediaBox extends Combine {
return undefined return undefined
}) })
return new Combine([new VariableUiElement(contents) return new Combine([
quickFacts?.SetClass("border-2 border-grey rounded-lg m-1 mb-0"),
new VariableUiElement(contents)
.SetClass("block pl-6 pt-2")]) .SetClass("block pl-6 pt-2")])
} }

10
assets/svg/gender_bi.svg Normal file
View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 56.831 0 v 6 h 10.573 L 53.909 19.496 c -4.395 -3.644 -10.034 -5.839 -16.176 -5.839 c -13.994 0 -25.379 11.385 -25.379 25.379 c 0 12.979 9.795 23.706 22.379 25.196 v 9.621 H 24.284 v 6 h 10.448 V 90 h 6 V 79.854 h 10.449 v -6 H 40.733 v -9.621 c 12.585 -1.49 22.38 -12.217 22.38 -25.196 c 0 -5.694 -1.886 -10.956 -5.065 -15.196 l 13.599 -13.599 v 10.574 h 6 V 0 H 56.831 z M 37.733 58.416 c -10.686 0 -19.379 -8.693 -19.379 -19.379 s 8.693 -19.379 19.379 -19.379 c 10.687 0 19.38 8.693 19.38 19.379 S 48.419 58.416 37.733 58.416 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 65.896 50.433 c 11.522 -11.522 11.522 -30.27 0 -41.792 c -11.521 -11.522 -30.27 -11.522 -41.792 0 c -11.522 11.522 -11.522 30.269 0 41.792 C 29.102 55.432 35.461 58.259 42 58.92 v 12.09 H 29.485 v 6.001 H 42 V 90 H 48 V 77.012 h 12.514 v -6.001 H 48 V 58.92 C 54.539 58.259 60.898 55.432 65.896 50.433 z M 28.347 12.885 C 32.939 8.294 38.969 5.998 45 5.998 c 6.031 0 12.061 2.295 16.653 6.886 c 9.182 9.183 9.182 24.123 0 33.306 c -9.183 9.182 -24.124 9.181 -33.305 0 C 19.165 37.008 19.165 22.067 28.347 12.885 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 58.771 52.128 l 29.336 29.336 V 51.136 h -5.992 V 67 L 62.152 47.036 c 2.395 -4.484 3.758 -9.599 3.758 -15.028 C 65.91 14.359 51.551 0 33.901 0 C 16.251 0 1.893 14.359 1.893 32.008 s 14.359 32.008 32.008 32.008 c 5.429 0 10.544 -1.363 15.028 -3.758 l 8.992 8.992 L 47.552 79.617 l 4.236 4.236 l 10.368 -10.367 L 78.67 90 l 4.236 -4.236 L 54.021 56.878 C 55.765 55.465 57.357 53.872 58.771 52.128 z M 7.885 32.008 c 0 -14.345 11.671 -26.016 26.016 -26.016 c 14.346 0 26.017 11.671 26.017 26.016 S 48.247 58.024 33.901 58.024 C 19.555 58.024 7.885 46.354 7.885 32.008 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 61.374 0 v 6.039 h 18.318 L 57.823 27.907 c -6.124 -5.16 -14.022 -8.278 -22.638 -8.278 C 15.784 19.63 0 35.414 0 54.815 C 0 74.216 15.784 90 35.185 90 s 35.185 -15.784 35.185 -35.185 c 0 -8.616 -3.118 -16.514 -8.278 -22.638 l 21.869 -21.869 v 18.318 H 90 V 0 H 61.374 z M 35.185 83.961 c -16.071 0 -29.147 -13.075 -29.147 -29.146 c 0 -16.071 13.075 -29.147 29.147 -29.147 s 29.147 13.075 29.147 29.147 C 64.332 70.886 51.257 83.961 35.185 83.961 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 65.896 39.567 C 60.898 34.568 54.539 31.742 48 31.08 V 18.642 l 8.417 4.64 l 2.897 -5.256 l -8.099 -4.465 l 8.099 -4.465 l -2.897 -5.256 L 48 8.481 V 0 H 42 v 8.481 l -8.417 -4.64 l -2.897 5.256 l 8.099 4.465 l -8.099 4.465 l 2.897 5.256 L 42 18.642 V 31.08 c -6.538 0.662 -12.897 3.488 -17.895 8.486 c -5.582 5.582 -8.656 13.002 -8.656 20.896 s 3.074 15.315 8.656 20.896 C 29.865 87.12 37.432 90 45 90 s 15.135 -2.88 20.896 -8.642 c 5.582 -5.581 8.656 -13.002 8.656 -20.896 S 71.478 45.148 65.896 39.567 z M 61.653 77.115 c -9.182 9.181 -24.122 9.182 -33.306 0 c -4.448 -4.448 -6.898 -10.362 -6.898 -16.653 c 0 -6.29 2.45 -12.204 6.898 -16.652 v 0 c 4.592 -4.591 10.622 -6.886 16.653 -6.886 c 6.031 0 12.061 2.295 16.653 6.887 c 4.448 4.448 6.898 10.362 6.898 16.652 C 68.55 66.753 66.101 72.667 61.653 77.115 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<desc>Created with Fabric.js 1.7.22</desc>
<defs>
</defs>
<g transform="translate(128 128) scale(0.72 0.72)" style="">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(-175.05 -175.05000000000004) scale(3.89 3.89)" >
<path d="M 67.238 0 v 6 h 7.545 L 60.421 20.362 c -4.227 -3.26 -9.517 -5.205 -15.255 -5.205 c -5.823 0 -11.184 2.004 -15.441 5.351 l -4.38 -4.38 l 5.273 -5.273 l -4.242 -4.242 l -5.273 5.273 L 15.217 6 h 7.545 V 0 H 4.975 v 17.788 h 6 v -7.545 l 5.885 5.885 L 11.587 21.4 l 4.242 4.242 l 5.273 -5.273 l 4.38 4.38 c -3.347 4.257 -5.351 9.618 -5.351 15.441 c 0 12.788 9.641 23.36 22.035 24.848 v 7.59 h -7.457 v 6 h 7.457 V 90 h 6 V 78.63 h 7.456 v -6 h -7.456 v -7.59 C 60.56 63.552 70.2 52.979 70.2 40.191 c 0 -5.908 -2.062 -11.34 -5.497 -15.627 l 14.322 -14.322 v 7.545 h 6 V 0 H 67.238 z M 45.166 59.226 c -10.496 0 -19.035 -8.539 -19.035 -19.034 c 0 -10.496 8.539 -19.035 19.035 -19.035 c 10.495 0 19.034 8.539 19.034 19.035 C 64.2 50.687 55.661 59.226 45.166 59.226 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -679,6 +679,90 @@
"authors": [], "authors": [],
"sources": [] "sources": []
}, },
{
"path": "gender_bi.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{
"path": "gender_female.svg",
"license": "CC0",
"authors": [],
"sources": []
},
{
"path": "gender_female.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{
"path": "gender_inter.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{
"path": "gender_intersekse.svg",
"license": "CC0",
"authors": [],
"sources": []
},
{
"path": "gender_male.svg",
"license": "CC0",
"authors": [],
"sources": []
},
{
"path": "gender_male.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{
"path": "gender_queer.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{
"path": "gender_trans.svg",
"license": "CC0",
"authors": [],
"sources": []
},
{
"path": "gender_trans.svg",
"license": "CC0",
"authors": [
"Gender Icon Pack"
],
"sources": [
"https://www.iconpacks.net/free-icon-pack/gender-107.html"
]
},
{ {
"path": "hand.svg", "path": "hand.svg",
"license": "CC0", "license": "CC0",

54
package-lock.json generated
View file

@ -21,6 +21,7 @@
"@types/leaflet.markercluster": "^1.4.3", "@types/leaflet.markercluster": "^1.4.3",
"@types/lz-string": "^1.3.34", "@types/lz-string": "^1.3.34",
"@types/prompt-sync": "^4.1.0", "@types/prompt-sync": "^4.1.0",
"@types/wikidata-sdk": "^6.1.0",
"country-language": "^0.1.7", "country-language": "^0.1.7",
"email-validator": "^2.0.4", "email-validator": "^2.0.4",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
@ -44,7 +45,9 @@
"parcel": "^1.2.4", "parcel": "^1.2.4",
"prompt-sync": "^4.2.0", "prompt-sync": "^4.2.0",
"tailwindcss": "^2.2.15", "tailwindcss": "^2.2.15",
"tslint": "^6.1.3" "tslint": "^6.1.3",
"wikibase-sdk": "^7.14.0",
"wikidata-sdk": "^7.14.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/polyfill": "^7.10.4", "@babel/polyfill": "^7.10.4",
@ -3024,6 +3027,15 @@
"integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==",
"dev": true "dev": true
}, },
"node_modules/@types/wikidata-sdk": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/@types/wikidata-sdk/-/wikidata-sdk-6.1.0.tgz",
"integrity": "sha512-4IG0mbD97vnpNUCCsybYOZvXDPOgv4riDHllKKkv4yKM90md2j2lH3yqp2pnPURHS79tbQibZybANHT++J25fA==",
"deprecated": "This is a stub types definition. wikidata-sdk provides its own type definitions, so you do not need this installed.",
"dependencies": {
"wikidata-sdk": "*"
}
},
"node_modules/abab": { "node_modules/abab": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz",
@ -17243,6 +17255,25 @@
"string-width": "^1.0.2 || 2" "string-width": "^1.0.2 || 2"
} }
}, },
"node_modules/wikibase-sdk": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-7.14.0.tgz",
"integrity": "sha512-9IcgqQ5CCNiOl5Xb/SdWdijvVxGh/9eCWvX5OeCgHKE0xeHHngAcuketBM8YBAbTUDKhFwbThPjxV/zl0Qr6gg==",
"engines": {
"node": ">= 6.4"
}
},
"node_modules/wikidata-sdk": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/wikidata-sdk/-/wikidata-sdk-7.14.0.tgz",
"integrity": "sha512-2B2TyyLAxfc1qHFSoKL+x1iQwXgrixQPopf1dRF0qdbvB1FFKOUP5cbSEhGH3pJ1Bos63o7bpN0P8voJ8DEs9Q==",
"dependencies": {
"wikibase-sdk": "^7.14.0"
},
"engines": {
"node": ">= 6.4"
}
},
"node_modules/word-wrap": { "node_modules/word-wrap": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
@ -20114,6 +20145,14 @@
"integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==",
"dev": true "dev": true
}, },
"@types/wikidata-sdk": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/@types/wikidata-sdk/-/wikidata-sdk-6.1.0.tgz",
"integrity": "sha512-4IG0mbD97vnpNUCCsybYOZvXDPOgv4riDHllKKkv4yKM90md2j2lH3yqp2pnPURHS79tbQibZybANHT++J25fA==",
"requires": {
"wikidata-sdk": "*"
}
},
"abab": { "abab": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz",
@ -31601,6 +31640,19 @@
"string-width": "^1.0.2 || 2" "string-width": "^1.0.2 || 2"
} }
}, },
"wikibase-sdk": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-7.14.0.tgz",
"integrity": "sha512-9IcgqQ5CCNiOl5Xb/SdWdijvVxGh/9eCWvX5OeCgHKE0xeHHngAcuketBM8YBAbTUDKhFwbThPjxV/zl0Qr6gg=="
},
"wikidata-sdk": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/wikidata-sdk/-/wikidata-sdk-7.14.0.tgz",
"integrity": "sha512-2B2TyyLAxfc1qHFSoKL+x1iQwXgrixQPopf1dRF0qdbvB1FFKOUP5cbSEhGH3pJ1Bos63o7bpN0P8voJ8DEs9Q==",
"requires": {
"wikibase-sdk": "^7.14.0"
}
},
"word-wrap": { "word-wrap": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",

View file

@ -68,6 +68,7 @@
"@types/leaflet.markercluster": "^1.4.3", "@types/leaflet.markercluster": "^1.4.3",
"@types/lz-string": "^1.3.34", "@types/lz-string": "^1.3.34",
"@types/prompt-sync": "^4.1.0", "@types/prompt-sync": "^4.1.0",
"@types/wikidata-sdk": "^6.1.0",
"country-language": "^0.1.7", "country-language": "^0.1.7",
"email-validator": "^2.0.4", "email-validator": "^2.0.4",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
@ -91,7 +92,9 @@
"parcel": "^1.2.4", "parcel": "^1.2.4",
"prompt-sync": "^4.2.0", "prompt-sync": "^4.2.0",
"tailwindcss": "^2.2.15", "tailwindcss": "^2.2.15",
"tslint": "^6.1.3" "tslint": "^6.1.3",
"wikibase-sdk": "^7.14.0",
"wikidata-sdk": "^7.14.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/polyfill": "^7.10.4", "@babel/polyfill": "^7.10.4",

16
test.ts
View file

@ -1,5 +1,13 @@
import FeaturedMessage from "./UI/BigComponents/FeaturedMessage"; import * as wd from "wikidata-sdk"
import Combine from "./UI/Base/Combine"; import * as wds from "wikibase-sdk"
import {Utils} from "./Utils";
new FeaturedMessage().AttachTo("maindiv") const url = wd.getEntities(["Q42"])
new Combine(FeaturedMessage.WelcomeMessages().map(wm => FeaturedMessage.CreateFeaturedBox(wm))).AttachTo("extradiv") console.log(url)
Utils.downloadJson(url).then(async (entities) => {
//const parsed = wd.parse.wb.entities(entities)["Q42"]
console.log(entities)
console.log(wds.simplify.entity(entities.entities["Q42"], {
timeConverter: 'simple-day'
}))
})