From aad0c7eace797e7498212bd47bdd328312274ecc Mon Sep 17 00:00:00 2001 From: jacquesfize Date: Mon, 8 Dec 2025 21:27:12 +0100 Subject: [PATCH 1/3] add description in the detailed view --- .../core/taxonList/TaxonDetailed.vue | 44 ++++++++++++++++++- src/components/core/taxonList/TaxonView.vue | 11 +++++ src/lib/connectors/connector.ts | 12 +++++ src/lib/connectors/gbif.ts | 40 ++++++++++++++++- src/lib/media/Wikidata.ts | 2 +- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/components/core/taxonList/TaxonDetailed.vue b/src/components/core/taxonList/TaxonDetailed.vue index 0c02be4a..e844c1d5 100644 --- a/src/components/core/taxonList/TaxonDetailed.vue +++ b/src/components/core/taxonList/TaxonDetailed.vue @@ -1,6 +1,7 @@ diff --git a/src/lib/connectors/connector.ts b/src/lib/connectors/connector.ts index d2355862..58aec6ed 100644 --- a/src/lib/connectors/connector.ts +++ b/src/lib/connectors/connector.ts @@ -225,4 +225,16 @@ export class Connector { searchOnAPI(searchString: string): Promise { throw new Error('Not implemented'); } + + /** + * Fetches the description of a taxon. + * @param taxonID - The ID of the taxon. + * @returns A promise that resolves to the description of the taxon if found. + */ + fetchDescription( + taxonID: string | number, + lang: string = 'en' + ): Promise { + throw new Error('Not implemented'); + } } diff --git a/src/lib/connectors/gbif.ts b/src/lib/connectors/gbif.ts index d2ec4fa9..07bb02b5 100644 --- a/src/lib/connectors/gbif.ts +++ b/src/lib/connectors/gbif.ts @@ -9,6 +9,7 @@ import { CONNECTORS } from './connectors'; import { GBIFSearchScoring } from './search/gbif'; import { removeHoles } from './utils'; import { parse, stringify } from 'wellknown'; +import { fetchWikidataEntityByProperty } from '../media/Wikidata'; const GBIF_ENDPOINT_DEFAULT = 'https://api.gbif.org/v1'; // const GBIF_ENDPOINT_DEFAULT = 'https://api.gbif-uat.org/v1'; @@ -199,8 +200,9 @@ export class GbifConnector extends Connector { }; } - taxonsData[observation.taxonKey].nbObservations += - 1; + taxonsData[ + observation.taxonKey + ].nbObservations += 1; taxonsData[observation.taxonKey].lastSeenDate = new Date( Math.max( @@ -296,4 +298,38 @@ export class GbifConnector extends Connector { .then((response) => response.json()) .then((json) => json.results); } + + fetchDescription(taxonID: string | number, lang: string): Promise { + return fetchWikidataEntityByProperty('P846', taxonID.toString()).then( + (wikidataID) => { + if (!wikidataID) return ''; // nothing found → resolve with empty string + + return fetch( + `https://www.wikidata.org/wiki/Special:EntityData/${wikidataID}.json` + ) + .then((res) => res.json()) + .then((entityJson) => { + const langSelected = + `${lang}wiki` in + entityJson.entities[wikidataID].sitelinks + ? lang + : 'en'; + + const title = entityJson.entities[wikidataID].sitelinks[ + `${langSelected}wiki` + ].title + .replace(/ /g, '_') + .replace(/:/g, '%3A') + .replace(/#/g, '%23') + .replace(/"/g, '%22'); + + return fetch( + `https://${lang}.wikipedia.org/api/rest_v1/page/summary/${title}` + ) + .then((res) => res.json()) + .then((summaryJson) => summaryJson.extract || ''); + }); + } + ); + } } diff --git a/src/lib/media/Wikidata.ts b/src/lib/media/Wikidata.ts index f6246a03..253fe431 100644 --- a/src/lib/media/Wikidata.ts +++ b/src/lib/media/Wikidata.ts @@ -209,4 +209,4 @@ class WikiDataImageSource extends MediaSource { } } -export { WikiDataImageSource }; +export { WikiDataImageSource, fetchWikidataEntityByProperty }; From 291792ed2c5703da28a1e0a819d85517a933d132 Mon Sep 17 00:00:00 2001 From: jacquesfize Date: Mon, 8 Dec 2025 22:44:39 +0100 Subject: [PATCH 2/3] add first proto on thumbnail --- .../core/taxonList/TaxonDetailed.vue | 6 +- .../core/taxonList/TaxonThumbnail.vue | 191 ++++++++++++++++-- src/components/core/taxonList/TaxonView.vue | 1 + 3 files changed, 184 insertions(+), 14 deletions(-) diff --git a/src/components/core/taxonList/TaxonDetailed.vue b/src/components/core/taxonList/TaxonDetailed.vue index e844c1d5..6dd34475 100644 --- a/src/components/core/taxonList/TaxonDetailed.vue +++ b/src/components/core/taxonList/TaxonDetailed.vue @@ -72,7 +72,11 @@ }}
- + Description