Skip to content

Commit

Permalink
Update composeMainContent to prevent tweet too long
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamigami55 committed Apr 6, 2022
1 parent b1d909e commit 5ee8674
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion scripts/postTweet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const composeProduct = (product) => {
return `${product.rank}. ${product.name} 🔼 ${product.votesCount}`
}

const composeMainContent = () => {
// =============================================================================

const _composeMainContentLong = () => {
const { products, date } = data
const formattedDate = formatInTimeZone(
new Date(date),
Expand All @@ -63,6 +65,35 @@ ${formattedProducts}
return content
}

const _composeMainContentShort = () => {
const { products, date } = data
const formattedDate = formatInTimeZone(
new Date(date),
'America/Los_Angeles',
'MMMM d, yyyy'
)

const formattedProducts = products
.map((product) => composeProduct(product))
.join('\n')

let content = `🔥 Top 5 on Product Hunt yesterday
📅 ${formattedDate} #ProductHunt
${formattedProducts}`

return content
}

const composeMainContent = () => {
if (_composeMainContentLong().length > 280) {
return _composeMainContentShort()
}
return _composeMainContentLong()
}

// =============================================================================

const _composeDetailContentLong = (product) => {
const { name, description, url, rank, votesCount } = product
return `${rankToNumberEmoji(rank)} ${name} ${rankToMedalEmoji(rank)}
Expand Down Expand Up @@ -90,6 +121,8 @@ const composeDetailContent = (product) => {
return _composeDetailContentLong(product)
}

// =============================================================================

async function run() {
const { products } = data

Expand Down

0 comments on commit 5ee8674

Please sign in to comment.