Skip to content

Commit 4fee17f

Browse files
authored
Merge branch 'Hypertopic:main' into requirement-287
2 parents 7590684 + 1387526 commit 4fee17f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1581
-738
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function(doc, req) {
2+
const body = JSON.parse(req.body, (k, v) => (k === 'history') ? undefined : v);
3+
if (!doc) {
4+
doc = Object.assign({}, body, {
5+
_id: req.id,
6+
_rev: req.rev,
7+
history: [{
8+
user: req.userCtx.name,
9+
date: new Date().toISOString(),
10+
action: 'creation',
11+
}],
12+
});
13+
} else {
14+
doc = Object.assign({}, doc, body);
15+
}
16+
return [doc, { json: { status: 'ok' } }];
17+
}

backend/hyperglosae/src/views/lib/links.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,31 @@ exports.getRelatedDocuments = ({isPartOf, links}) =>
1212
.map(x => parseReference(x).id)
1313
);
1414

15-
exports.emitPassages = ({text, isPartOf, related}) => {
15+
// Should have the same definition as in `frontend/src/parallelDocuments.js`
16+
const parseText = (text) => {
17+
if (!text) return [];
1618
const PASSAGE = /{([^{]+)} ([^{]*)/g;
1719
let passages = [...text.matchAll(PASSAGE)];
18-
passages = (passages.length) ? passages : [[null, null, text]];
19-
passages.forEach(([_, rubric, passage]) => {
20-
related.forEach(x => {
21-
emit([x, Number(rubric)], {text: passage, isPartOf, _id: null});
22-
});
23-
});
20+
passages = (passages.length) ? passages : [[null, '0', text]];
21+
return passages.map(([_, rubric, passage]) => ({
22+
rubric,
23+
passage,
24+
parsed_rubric: rubric.match(/(?:(\d+)[:., ])?(\d+) ?([a-z]?)/)
25+
.slice(1)
26+
.filter(x => !!x)
27+
.map(x => {
28+
let n = Number(x) ;
29+
return Number.isNaN(n) ? x : n;
30+
})
31+
}));
32+
}
33+
34+
exports.emitPassages = ({text, isPartOf, related}) => {
35+
parseText(text).forEach(({rubric, passage, parsed_rubric}) =>
36+
related.forEach((x) => {
37+
emit([x, ...parsed_rubric], { text: passage, isPartOf, rubric, _id: null });
38+
})
39+
);
2440
}
2541

2642
exports.emitIncludedDocuments = ({isPartOf, links}) => {

0 commit comments

Comments
 (0)