Skip to content

Commit

Permalink
Add langCode for wikiurls
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcaballerov authored and curibe committed Aug 17, 2021
1 parent 9a50781 commit 734cbe6
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@

$.getJSON(url, function (data) {
var item = data.entities["{{ q }}"];
if ('en' in item.labels) {
var title = item.labels.en.value

if (langCode in item.labels) {
$("#h1").text(item.labels[`${langCode}`].value);
}
else if ('en' in item.labels) {
var title = item.labels.en.value
$("#h1").text(title);

{% if request.path.endswith("curation") or request.path.endswith("curation/") %}
Expand All @@ -109,6 +113,8 @@

{% endif %}
}


$("#h1").append(' (<a href="https://www.wikidata.org/wiki/{{ q }}">{{ q }}</a>)');

{% if q2 %}
Expand Down Expand Up @@ -310,9 +316,27 @@
} catch(e) { console.log("Exception: " + e)
}
}


/* langCode Wikipedia */
if (`${langCode}wiki` in item.sitelinks) {
var title = item.sitelinks[`${langCode}wiki`].title;
var wikipediaApiUrl = `https://${langCode}.wikipedia.org/w/api.php?` +
'action=query&prop=extracts&exsentences=3&exlimit=1&exintro=1&' +
'explaintext=1&callback=?&format=json&titles=' +
encodeURIComponent(title);
var wikipediaUrl = `https://${langCode}.wikipedia.org/wiki/` + encodeURIComponent(title)

$.getJSON(wikipediaApiUrl, function(data) {
var pages = data.query.pages;
var text = pages[Object.keys(pages)[0]].extract + " ... "
var html = "(from the <a href=\"" + wikipediaUrl + "\">Wikipedia</a>)";
$("#intro").text(text).append(html);
}).fail(function(d, textStatus, error) {
console.error("getJSON failed, status: " + textStatus + ", error: "+error)
});
}
/* English Wikipedia */
if ('enwiki' in item.sitelinks) {
else if ('enwiki' in item.sitelinks) {
var title = item.sitelinks.enwiki.title;
var wikipediaApiUrl = 'https://en.wikipedia.org/api/rest_v1/page/summary/' +
encodeURIComponent(title);
Expand All @@ -330,9 +354,31 @@
});
}


/* langCode Wikiversity */
if (`${langCode}wikiversity` in item.sitelinks) {
var wikiversityTitle = item.sitelinks[`${langCode}wikiversity`].title;
var wikiversityApiUrl = `https://${langCode}.wikiversity.org/w/api.php?` +
'action=query&prop=extracts&exsentences=3&exlimit=1&exintro=1&' +
'explaintext=1&callback=?&format=json&titles=' +
encodeURIComponent(wikiversityTitle);
var wikiversityUrl = `https://${langCode}.wikiversity.org/wiki/` + encodeURIComponent(wikiversityTitle)

$.getJSON(wikiversityApiUrl, function(data) {
var pages = data.query.pages;
var text = pages[Object.keys(pages)[0]].extract;
if (text) {
var html = "... (from the <a href=\"" + wikiversityUrl + "\">Wikiversity</a>)";
}
else {
var html = "Read on the <a href=\"" + wikiversityUrl + "\">Wikiversity</a>";
}
$("#wikiversity-extract").text(text).append(html);
}).fail(function(d, textStatus, error) {
console.error("getJSON failed, status: " + textStatus + ", error: "+error)
});
}
/* English Wikiversity */
if ('enwikiversity' in item.sitelinks) {
else if ('enwikiversity' in item.sitelinks) {
var enwikiversityTitle = item.sitelinks.enwikiversity.title;
var wikiversityApiUrl = 'https://en.wikiversity.org/w/api.php?' +
'action=query&prop=extracts&exsentences=3&exlimit=1&exintro=1&' +
Expand Down Expand Up @@ -469,7 +515,8 @@
// Make list with results
data.most_similar.forEach(function(entry, idx, array) {
var listed_q = entry.item;
var language = 'en';
// var language = 'en';
var language = langCode;

if (idx !== 0) {
$( '#wembedder' ).append( ' &middot; ');
Expand Down

0 comments on commit 734cbe6

Please sign in to comment.