in apps-rendering/src/item.ts [369:482]
logo: paidContentLogo(content.tags),
webUrl: content.webUrl,
edition: Optional.fromNullable(request.edition).withDefault(Edition.UK),
promotedNewsletter: fromNullable(request.promotedNewsletter),
shouldHideAdverts: request.content.fields?.shouldHideAdverts ?? false,
outline: request.content.fields?.showTableOfContents
? fromBodyElements(body)
: [],
};
};
const parseBody = (
context: Context,
request: RenderingRequest,
): BodyElement[] => {
const { content } = request;
const body = content.blocks?.body ?? [];
const atoms = content.atoms;
const campaigns = request.campaigns ?? [];
const elements = [...body].shift()?.elements;
return elements !== undefined
? Result.partition(parseElements(context, campaigns, atoms)(elements))
.oks
: [];
};
const hasSomeTag =
(tagIds: string[]) =>
(tags: Tag[]): boolean =>
tags.some((tag) => tagIds.includes(tag.id));
const hasTag =
(tagId: string) =>
(tags: Tag[]): boolean =>
tags.some((tag) => tag.id === tagId);
const hasMainElement =
(mainMediaKind: MainMediaKind) =>
(mainMedia: Option<MainMedia>): boolean =>
mainMedia.kind === OptionKind.Some
? mainMedia.value.kind === mainMediaKind
: false;
const isAudio = hasTag('type/audio');
const isVideo = hasTag('type/video');
const isGallery = hasTag('type/gallery');
const isNews = hasTag('tone/news');
const isReview = hasSomeTag([
'tone/reviews',
'tone/livereview',
'tone/albumreview',
]);
const isAnalysis = hasTag('tone/analysis');
const isExplainer = hasTag('tone/explainers');
const isLetter = hasTag('tone/letters');
const isComment = hasTag('tone/comment');
const isFeature = hasTag('tone/features');
const isLive = hasTag('tone/minutebyminute');
const isRecipe = hasTag('tone/recipes');
const isInterview = hasTag('tone/interview');
const isObituary = hasTag('tone/obituaries');
const isGuardianView = hasTag('tone/editorials');
const isQuiz = hasTag('tone/quizzes');
const isLabs = hasTag('tone/advertisement-features');
const isMatchReport = hasTag('tone/matchreports');
const isTimeline = hasTag('tone/timelines');
const isProfile = hasTag('tone/profiles');
const isCorrection = hasTag('theguardian/series/correctionsandclarifications');
const isPicture = hasTag('type/picture');
const hasCartoon = hasMainElement(MainMediaKind.Cartoon);
const fromCapiLiveBlog =
(context: Context) =>
(
request: RenderingRequest,
blockId: Option<string>,
itemFields: ItemFields,
): LiveBlog | DeadBlog => {
const { content, campaigns } = request;
const body = content.blocks?.body ?? [];
const pageSize = content.tags.map((c) => c.id).includes('sport/sport')
? 30
: 10;
const parsedBlocks = parseLiveBlocks(context)(
body,
content.tags,
campaigns ?? [],
);
const pagedBlocks = getPagedBlocks(pageSize, parsedBlocks, blockId);
return {