@sankei-arc-shared-components/content-source_cxense-related-articles
v0.2.1
Published
# How do I use it in my Fusion Project?
Downloads
61
Readme
CXENSE Related Articles: A Sankei Shared Fusion Component
How do I use it in my Fusion Project?
import 'regenerator-runtime';
import 'isomorphic-fetch';
import createContentSource from '@sankei-arc-shared-components/content-source_cxense-related-articles';
import {
CXENSE_KEYWORDS_PERSISTED_KEY,
CXENSE_RELATED_ARTICLES_PERSISTED_KEY,
} from 'fusion:environment';
import { getArticleById } from './utils/fetch-helpers';
const params = {
storyId: 'text',
types: 'text',
};
const config = {
keywordsPersistedKey: CXENSE_KEYWORDS_PERSISTED_KEY,
articlesPersistedKey: CXENSE_RELATED_ARTICLES_PERSISTED_KEY,
};
const fetch = async (query) => {
const { 'arc-site': website = 'sankei', storyId, types: typesString } = query;
const types = typesString.split(',');
const includedFields = [
'canonical_website',
'content_elements',
'headlines.basic',
'label.yahoo.text',
// website is expected to be the canonical_website
// it will be set by the lambda, using info from draft API
`websites.${website}.website_section._id`,
];
const storyQuery = { _id: storyId, 'arc-site': website };
const story = await getArticleById(storyQuery, includedFields);
return createContentSource(config)(types, story);
};
export default {
cache: false,
fetch,
params,
};