Merge pull request #2109 from omnivore-app/feat/tweet-titles
Better tweet titles
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -65,3 +65,7 @@ omnivore-app-sa-gcs*
|
||||
|
||||
# data migration file
|
||||
data.json
|
||||
|
||||
# android
|
||||
*.aab
|
||||
*.apk
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/addressparser": "^1.0.1",
|
||||
"@types/lodash": "^4.14.194",
|
||||
"@types/luxon": "^3.0.1",
|
||||
"@types/rfc2047": "^2.0.1",
|
||||
"@types/underscore": "^1.11.4",
|
||||
@ -31,6 +32,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",
|
||||
"underscore": "^1.13.6",
|
||||
|
||||
@ -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 {
|
||||
@ -134,8 +135,10 @@ const getTweetsByIds = async (ids: string[]): Promise<Tweets> => {
|
||||
return response.data
|
||||
}
|
||||
|
||||
const titleForAuthor = (author: { name: string }) => {
|
||||
return `${author.name} on Twitter`
|
||||
const titleForTweet = (author: { name: string }, text: string) => {
|
||||
return `${author.name} on Twitter: ${truncate(text.replace(/http\S+/, ''), {
|
||||
length: 100,
|
||||
})}`
|
||||
}
|
||||
|
||||
const tweetIdFromStatusUrl = (url: string): string | undefined => {
|
||||
@ -319,7 +322,7 @@ export class TwitterHandler extends ContentHandler {
|
||||
const authorId = tweetData.author_id
|
||||
const author = tweet.includes.users.filter((u) => (u.id = authorId))[0]
|
||||
// escape html entities in title
|
||||
const title = titleForAuthor(author)
|
||||
const title = titleForTweet(author, tweetData.text)
|
||||
const escapedTitle = _.escape(title)
|
||||
const authorImage = author.profile_image_url.replace('_normal', '_400x400')
|
||||
const description = _.escape(tweetData.text)
|
||||
|
||||
@ -8457,6 +8457,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.180.tgz#4ab7c9ddfc92ec4a887886483bc14c79fb380670"
|
||||
integrity sha512-XOKXa1KIxtNXgASAnwj7cnttJxS4fksBRywK/9LzRV5YxrF80BXZIGeQSuoESQ/VkUj30Ae0+YcuHc15wJCB2g==
|
||||
|
||||
"@types/lodash@^4.14.194":
|
||||
version "4.14.194"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
|
||||
integrity sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==
|
||||
|
||||
"@types/long@^4.0.0", "@types/long@^4.0.1":
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a"
|
||||
|
||||
Reference in New Issue
Block a user