fix: full text for newsletter ai-generated subject
This commit is contained in:
@@ -3,7 +3,7 @@ import { summirize } from '@utils/summarize';
|
|||||||
import { NewsType } from '@utils/validationSchemas';
|
import { NewsType } from '@utils/validationSchemas';
|
||||||
import createDOMPurify from 'isomorphic-dompurify';
|
import createDOMPurify from 'isomorphic-dompurify';
|
||||||
import Template from './Template';
|
import Template from './Template';
|
||||||
import extractMainTopic from '@utils/extractMainTopic';
|
import newsletterSubject from '@utils/newsletterSubject';
|
||||||
|
|
||||||
export default async function NewsletterTemplate(stories: NewsType[]) {
|
export default async function NewsletterTemplate(stories: NewsType[]) {
|
||||||
const summary = await summirize(stories);
|
const summary = await summirize(stories);
|
||||||
@@ -17,7 +17,7 @@ export default async function NewsletterTemplate(stories: NewsType[]) {
|
|||||||
throw new Error('Failed to sanitize summary');
|
throw new Error('Failed to sanitize summary');
|
||||||
}
|
}
|
||||||
|
|
||||||
const topic = extractMainTopic(sanitizedSummary);
|
const topic = newsletterSubject(sanitizedSummary);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subject: topic,
|
subject: topic,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export default function extractMainTopic(summary: string): string {
|
function extractMainTopic(summary: string): string {
|
||||||
const firstParaMatch = summary.match(/<p>(.*?)<\/p>/);
|
const firstParaMatch = summary.match(/<p>(.*?)<\/p>/);
|
||||||
if (!firstParaMatch) return 'tech updates';
|
if (!firstParaMatch) return 'tech updates';
|
||||||
|
|
||||||
@@ -56,10 +56,15 @@ export default function extractMainTopic(summary: string): string {
|
|||||||
.slice(0, 2)
|
.slice(0, 2)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
const topic = words.toLowerCase() || 'tech updates';
|
return words.toLowerCase() || 'tech updates';
|
||||||
|
}
|
||||||
const titleSuffix =
|
|
||||||
topic === 'tech updates' ? topic : `tech: ${topic} in focus`;
|
export default function newsletterSubject(summary: string) {
|
||||||
|
const topic = extractMainTopic(summary);
|
||||||
return `Today in ${titleSuffix}`;
|
const title =
|
||||||
|
topic === 'tech updates'
|
||||||
|
? 'Today in tech updates'
|
||||||
|
: `Today in tech: ${topic}`;
|
||||||
|
|
||||||
|
return title;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user