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