mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-10 23:23:08 -04:00
fixes for wolfram sources
This commit is contained in:
parent
b54d99de2e
commit
07893bba18
2 changed files with 10 additions and 9 deletions
|
@ -8,12 +8,6 @@ const { citation } = require('../../../labscore/utils/markdown');
|
||||||
|
|
||||||
const { Permissions } = require("detritus-client/lib/constants");
|
const { Permissions } = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
function getWolframSource(ref, sources){
|
|
||||||
for(const s of Object.values(sources)){
|
|
||||||
if(s.ref == ref) return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createWolframPage(context, pod, query, sources){
|
function createWolframPage(context, pod, query, sources){
|
||||||
let res = {
|
let res = {
|
||||||
"embeds": [
|
"embeds": [
|
||||||
|
@ -34,9 +28,13 @@ function createWolframPage(context, pod, query, sources){
|
||||||
if(pod.value) res.embeds[0].description = pod.value.substr(0,1000)
|
if(pod.value) res.embeds[0].description = pod.value.substr(0,1000)
|
||||||
if(pod.value && pod.refs) {
|
if(pod.value && pod.refs) {
|
||||||
for(const r of pod.refs){
|
for(const r of pod.refs){
|
||||||
let src = getWolframSource(r, sources)
|
let src = Object.values(sources).filter((s)=>s.ref == r)[0]
|
||||||
|
// Only add a direct source if one is available
|
||||||
|
if(src.sources && src.sources[0].url){
|
||||||
|
res.embeds[0].description += citation(r, src.sources[0].url, src.title + ' | ' + src.sources[0].text)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
if(src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||||
if(src.sources) res.embeds[0].description += citation(r, src.sources[0].url, src.title + ' | ' + src.sources[0].text)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(pod.image) res.embeds[0].image = { url: pod.image };
|
if(pod.image) res.embeds[0].image = { url: pod.image };
|
||||||
|
|
|
@ -42,7 +42,10 @@ module.exports.citation = function(number = 1, url, tooltip = ""){
|
||||||
let formatted = "";
|
let formatted = "";
|
||||||
for(const n of number.toString().split('')) formatted += SUPERSCRIPT_NUMBERS[parseInt(n)]
|
for(const n of number.toString().split('')) formatted += SUPERSCRIPT_NUMBERS[parseInt(n)]
|
||||||
if(url){
|
if(url){
|
||||||
if(tooltip.length) tooltip = ` '${tooltip}'`
|
if(tooltip.length){
|
||||||
|
if(tooltip.endsWith(' ')) tooltip = tooltip.substr(0, tooltip.length - 1)
|
||||||
|
tooltip = ` '${tooltip.replace(/["*]/g, '')}'`
|
||||||
|
}
|
||||||
return `[⁽${formatted}⁾](${url}${tooltip})`
|
return `[⁽${formatted}⁾](${url}${tooltip})`
|
||||||
}
|
}
|
||||||
return `⁽${formatted}⁾`
|
return `⁽${formatted}⁾`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue