diff --git a/pages/data-providers/[id].jsx b/pages/data-providers/[id].jsx index 1f554b8..3156206 100644 --- a/pages/data-providers/[id].jsx +++ b/pages/data-providers/[id].jsx @@ -30,18 +30,10 @@ export async function getServerSideProps({ query: searchParams, }) { const { id } = routeParams - const { - q = '', - offset = 0, - limit = 10, - sort = 'recency', - // eslint-disable-next-line camelcase - search_id, - } = searchParams + const { q = '', offset = 0, limit = 10, sort = 'recency', t } = searchParams const data = {} try { - // eslint-disable-next-line camelcase - const dataProvider = await fetchMetadata(id, search_id) + const dataProvider = await fetchMetadata(id, t) const dataProviderStats = await fetchStats(id) Object.assign(data, { diff --git a/pages/search/index.jsx b/pages/search/index.jsx index 184ae39..53906fd 100644 --- a/pages/search/index.jsx +++ b/pages/search/index.jsx @@ -25,7 +25,7 @@ export const getServerSideProps = async ({ query: searchParams }) => { } // TODO for nice response // const { q, page = 1, limit = 10, sort = 'recency' } = searchParams - const { q, page = 1, limit = 10, sort = 'relevance' } = searchParams + const { q, page = 1, limit = 10, sort = 'relevance', t } = searchParams const data = { currentPage: +page, @@ -40,6 +40,7 @@ export const getServerSideProps = async ({ query: searchParams }) => { q, offset, limit, + t, exclude: ['fullText'], sort: sort === 'recent' ? 'recency' : sort, } diff --git a/pages/works/[id].jsx b/pages/works/[id].jsx index d0c8a53..5d892f9 100644 --- a/pages/works/[id].jsx +++ b/pages/works/[id].jsx @@ -22,14 +22,12 @@ export async function getServerSideProps({ req, }) { const { id } = routeParams - // eslint-disable-next-line camelcase - const { search_id } = searchParams + const { t } = searchParams const data = {} try { - // eslint-disable-next-line camelcase - const rawWork = await fetchWork(id, search_id) + const rawWork = await fetchWork(id, t) const { fullText: _, ...work } = rawWork const outputs = await fetchWorkOutputs(id) diff --git a/templates/search/results.jsx b/templates/search/results.jsx index f03c838..a62104b 100644 --- a/templates/search/results.jsx +++ b/templates/search/results.jsx @@ -42,6 +42,34 @@ const Results = ({ works, searchId }) => ?.replace(/(https:\/\/)(core\.ac\.uk)/, '$1api.$2') .replace('/reader/', '/reader-ui/') + const renderFullTextLink = ({ + fullTextLink: innerFullTextLink, + downloadLink: innerDownloadLink, + modifiedReaderLink: innerModifiedReaderLink, + searchId: innerSearchId, + id: innerId, + }) => { + if ( + innerFullTextLink == null && + innerDownloadLink == null && + innerModifiedReaderLink == null + ) + return null + if ( + (innerFullTextLink && innerFullTextLink.includes('core')) || + (innerDownloadLink && innerDownloadLink.includes('core')) || + (innerModifiedReaderLink && + innerModifiedReaderLink.includes('api.core')) + ) { + return generateMetadataLink( + innerModifiedReaderLink, + innerSearchId, + innerId + ) + } + if (innerDownloadLink) return innerDownloadLink + return innerFullTextLink + } return ( metadataLink: generateMetadataLink(metadataLink, searchId, id) || generateMetadataLink(displayLink, searchId, id), - fullTextLink: - generateMetadataLink(modifiedReaderLink, searchId, id) || - fullTextLink || + fullTextLink: renderFullTextLink({ + fullTextLink, downloadLink, + modifiedReaderLink, + searchId, + id, + }), dataProviders: dataProviders || [], isRecommended: memberType?.billing_type === 'sustaining', }}