Skip to content

Instantly share code, notes, and snippets.

@omerk
Last active January 26, 2023 04:08
Show Gist options
  • Save omerk/0a876dad5d0d897132f73d4063f16b43 to your computer and use it in GitHub Desktop.
Save omerk/0a876dad5d0d897132f73d4063f16b43 to your computer and use it in GitHub Desktop.
Mastodon RSS to Twitter (via IFTTT, with some transformation)
// Trim Mastodon RSS feed and add a reference to the original status URL
// This needs the Pro+ feature "Filter Code" blocks on IFTTT
let status_text = Feed.newFeedItem.EntryContent;
let status_url = Feed.newFeedItem.EntryUrl;
const tweet_max_length = 280;
// reference to original mastodon post
let footer = "\n\n(from ".concat(status_url).concat(")");
// if status + footer is shorter than twitter max chars, post as is
// longer ones get trimmed with ellipsis added...
let tweet_text = "";
if (status_text.length < (tweet_max_length - footer.length)) {
tweet_text = status_text.concat(footer);
} else {
let status_trim = status_text.substring(0, (tweet_max_length - footer.length - 3));
tweet_text = status_trim.concat("...").concat(footer);
}
Twitter.postNewTweet.setTweet(tweet_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment