mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 15:05:38 -04:00
[sources][nouns] allow linking from dictionary entries to specific fragment of example
This commit is contained in:
parent
d6129b95df
commit
58fda3d400
@ -26,7 +26,7 @@ const approve = async (db, id) => {
|
|||||||
const addVersions = async (req, nouns) => {
|
const addVersions = async (req, nouns) => {
|
||||||
const keys = new Set();
|
const keys = new Set();
|
||||||
nouns.filter(s => !!s && s.sources)
|
nouns.filter(s => !!s && s.sources)
|
||||||
.forEach(s => s.sources.split(',').forEach(k => keys.add(`'` + k + `'`)));
|
.forEach(s => s.sources.split(',').forEach(k => keys.add(`'` + k.split('#')[0] + `'`)));
|
||||||
|
|
||||||
const sources = await req.db.all(SQL`
|
const sources = await req.db.all(SQL`
|
||||||
SELECT s.*, u.username AS submitter FROM sources s
|
SELECT s.*, u.username AS submitter FROM sources s
|
||||||
@ -41,11 +41,31 @@ const addVersions = async (req, nouns) => {
|
|||||||
sources.forEach(s => sourcesMap[s.key] = s)
|
sources.forEach(s => sourcesMap[s.key] = s)
|
||||||
|
|
||||||
return nouns.map(n => {
|
return nouns.map(n => {
|
||||||
n.sourcesData = (n.sources ? n.sources.split(',') : []).map(s => sourcesMap[s]);
|
n.sourcesData = (n.sources ? n.sources.split(',') : []).map(s => selectFragment(sourcesMap, s));
|
||||||
return n;
|
return n;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const selectFragment = (sourcesMap, keyAndFragment) => {
|
||||||
|
const [key, fragment] = keyAndFragment.split('#');
|
||||||
|
if (sourcesMap[key] === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (fragment === undefined) {
|
||||||
|
return sourcesMap[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = {...sourcesMap[key]};
|
||||||
|
|
||||||
|
const fragments = source.fragments
|
||||||
|
? source.fragments.replace('\\@', '###').split('@').map(x => x.replace('###', '\\@'))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
source.fragments = fragments[parseInt(fragment) - 1];
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/nouns', async (req, res) => {
|
router.get('/nouns', async (req, res) => {
|
||||||
|
@ -114,7 +114,7 @@ export class Source {
|
|||||||
this.extra = extra;
|
this.extra = extra;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.fragments = fragments
|
this.fragments = fragments
|
||||||
? fragments.replace(/\|/g, '\n').replace('\\@', '###').split('@').map(x => x.replace('###', '\@'))
|
? fragments.replace(/\|/g, '\n').replace('\\@', '###').split('@').map(x => x.replace('###', '\\@'))
|
||||||
: [];
|
: [];
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.link = link;
|
this.link = link;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user