MCPcopy Create free account
hub / github.com/dailydotdev/apps / getReason

Function getReason

packages/shared/src/features/feedExplain/describe.ts:172–239  ·  view source on GitHub ↗
(
  post: Post,
  explain: FeedItemExplain | null | undefined,
)

Source from the content-addressed store, hash-verified

170
171/** Why a card is on the page in one sentence, split so the name can be bold. */
172export const getReason = (
173 post: Post,
174 explain: FeedItemExplain | null | undefined,
175): ReasonParts => {
176 if (isFillIn(explain)) {
177 return {
178 lead: 'Popular this week.',
179 tail: " Your topics didn't have enough new posts, so we added it.",
180 };
181 }
182 if (!isRankedExplain(explain)) {
183 return pickedForYou;
184 }
185 const { match, follow } = explain;
186 if (isSourceFollow(explain)) {
187 return {
188 lead:
189 follow.kind === ExplainFollowKind.Squad ? "You're in " : 'You follow ',
190 name: post.source?.name,
191 tail: match ? `. It's also about #${match.tag}.` : '.',
192 };
193 }
194 if (follow.kind === ExplainFollowKind.Author) {
195 return { lead: 'Written by someone you follow', tail: '.' };
196 }
197 const gatheredBy = getGatheringSide(explain);
198 if (gatheredBy) {
199 return {
200 lead: 'You asked for more from ',
201 name:
202 gatheredBy === FollowSide.Source || !post.author
203 ? post.source?.name
204 : getAuthorLabel(post.author),
205 tail: '.',
206 };
207 }
208 if (!match) {
209 return pickedForYou;
210 }
211 const name = `#${match.tag}`;
212 const isSide = match.role === ExplainRole.Side;
213 if (match.origin === ExplainOrigin.Set) {
214 const boost = formatBoost(match.weight);
215 return isSide
216 ? { lead: 'Partly about ', name, tail: `. You gave it a ${boost} boost.` }
217 : { lead: 'You gave ', name, tail: ` a ${boost} boost.` };
218 }
219 if (match.origin === ExplainOrigin.Declared) {
220 const phrase = match.strength ? strengthPhrase[match.strength] : undefined;
221 const follows = `${phrase ? ` ${phrase}` : ''}.`;
222 return isSide
223 ? { lead: 'Partly about ', name, tail: `. You follow it${follows}` }
224 : { lead: 'You follow ', name, tail: follows };
225 }
226 const isStrong = match.strength === ExplainStrength.Strong;
227 if (isSide) {
228 return {
229 lead: 'Partly about ',

Callers 3

sentenceFunction · 0.90
FeedExplanationModalFunction · 0.90
ReasonLineFunction · 0.90

Calls 6

isRankedExplainFunction · 0.90
isFillInFunction · 0.85
isSourceFollowFunction · 0.85
getGatheringSideFunction · 0.85
getAuthorLabelFunction · 0.85
formatBoostFunction · 0.85

Tested by 1

sentenceFunction · 0.72