Truncate tweet text used in titles using lodash

This commit is contained in:
Jackson Harper 2023-04-25 11:39:55 +08:00
parent 2d648fcb6d
commit 155fad5b9c
2 changed files with 5 additions and 1 deletions

View file

@ -31,6 +31,7 @@
"addressparser": "^1.0.1",
"axios": "^0.27.2",
"linkedom": "^0.14.16",
"lodash": "^4.17.21",
"luxon": "^3.0.4",
"puppeteer-core": "^19.1.1",
"rfc2047": "^4.0.1",

View file

@ -2,6 +2,7 @@ import { ContentHandler, PreHandleResult } from '../content-handler'
import axios from 'axios'
import { DateTime } from 'luxon'
import _ from 'underscore'
import { truncate } from 'lodash'
import { Browser, BrowserContext } from 'puppeteer-core'
interface TweetIncludes {
@ -135,7 +136,9 @@ const getTweetsByIds = async (ids: string[]): Promise<Tweets> => {
}
const titleForTweet = (author: { name: string }, text: string) => {
return `${author.name} on Twitter: ${text.replace(/http\S+/, '')}`
return `${author.name} on Twitter: ${truncate(text.replace(/http\S+/, ''), {
length: 100,
})}`
}
const tweetIdFromStatusUrl = (url: string): string | undefined => {