Skip to content

Commit a442906

Browse files
authored
Merge pull request #39 from PathwayCommons/24-improve-redirects
Improving redirects
2 parents 87f6597 + e7cb0c8 commit a442906

5 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ jobs:
4444
- name: Test with mocha
4545
run: npm run coverage
4646

47+
#----------------------------------------------
48+
# build
49+
#----------------------------------------------
50+
- name: Build code
51+
run: npm run build
52+
4753
#----------------------------------------------
4854
# reporting
4955
#----------------------------------------------

src/dashboard/categories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const toDate = o => {
66
};
77
const byDate = (a, b) => { return b.date - a.date; };
88
export const categories = data.map(({ id, name, description, img }) => ({ id, name, description, img }));
9-
export const getPapers = ({ id, limit = 20 }) => {
9+
export const getPapers = ({ id, limit = 100 }) => {
1010
let papers = [];
1111
const category = data.find(cat => cat.id === id);
1212
papers = category && category.papers.map(toDate).sort(byDate).slice(1, limit);

src/dashboard/category-results-screen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CategoryCard from './category-card.js';
44

55
function Paper ({ paper }) {
66
return h('div', { class: 'paper' }, [
7-
h('a', { href: `https://doi.org/${paper.doi}`, target: '_blank', class: 'paper-link' }, [
7+
h('a', { href: paper.finalURL, target: '_blank', class: 'paper-link' }, [
88
h('div', { class: 'paper-read' }),
99
h('div', { class: 'paper-title' }, paper.title)
1010
]),

src/data-search.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,37 @@ export async function getData () {
3838
await searcher.articles(articles);
3939
const doSearches = async config => {
4040
const { keywords } = config;
41-
const papers = await searcher.search(keywords, {
41+
const allPapers = await searcher.search(keywords, {
4242
combineWith: 'AND'
4343
});
44+
45+
// Filter for multiple versions of the same paper
46+
const papers = [];
47+
for (const paper of allPapers) {
48+
const exists = papers.find((obj) => obj.doi === paper.doi);
49+
50+
if (!exists) {
51+
const allVersions = allPapers.filter((obj) => obj.doi === paper.doi);
52+
if (allVersions.length > 1) {
53+
const max = allVersions.reduce((maxObj, obj) => {
54+
if (obj.version > maxObj.version) {
55+
return obj;
56+
} else {
57+
return maxObj;
58+
}
59+
}, { version: -Infinity });
60+
papers.push(max);
61+
} else {
62+
papers.push(paper);
63+
}
64+
}
65+
}
66+
67+
// Find and save final link for each paper's DOI
68+
for (const paper of papers) {
69+
const finalURL = `https://www.${paper.server}.org/content/${paper.doi}v${paper.version}`;
70+
paper.finalURL = finalURL;
71+
}
4472
return _.assign({}, config, { papers });
4573
};
4674
const collection = await Promise.all(config.map(doSearches));

src/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Search {
1212
constructor () {
1313
this.miniSearch = new MiniSearch({
1414
fields: ['title', 'authors', 'category', 'abstract'], // fields to index for full-text search
15-
storeFields: ['title', 'authors', 'category', 'abstract', 'date', 'server', 'doi'] // fields to return with search results
15+
storeFields: ['title', 'authors', 'category', 'abstract', 'date', 'server', 'doi', 'version'] // fields to return with search results
1616
});
1717
}
1818

0 commit comments

Comments
 (0)