generated from freeCodeCamp/template
-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
37 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const tweetButton = document.getElementById('tweet-btn'); | ||
const shareButton = document.getElementById('tweet-btn'); | ||
const url = window.location; | ||
// Use Nunjucks URL encoding here in case titles have any special characters like backticks | ||
const title = '{{ post.title | urlencode }}'.replace(/'/g, '%27'); | ||
const twitterHandles = { | ||
const blueskyHandles = { | ||
originalPostAuthor: | ||
'{{ post.original_post.primary_author.twitter_handle }}', | ||
currentPostAuthor: '{{ post.primary_author.twitter_handle }}' // Author or translator depending on context | ||
'{{ post.original_post.primary_author.bluesky_handle }}', | ||
currentPostAuthor: '{{ post.primary_author.bluesky_handle }}' // Author or translator depending on context | ||
}; | ||
const isTranslation = Boolean('{{ post.original_post }}'); | ||
let thanks; | ||
|
||
// Customize the tweet message only in cases where the (original post) author | ||
// or translator has a Twitter handle | ||
// or translator has a Bluesky handle | ||
if ( | ||
isTranslation && | ||
(twitterHandles.originalPostAuthor || twitterHandles.currentPostAuthor) | ||
(blueskyHandles.originalPostAuthor || blueskyHandles.currentPostAuthor) | ||
) { | ||
const names = { | ||
originalPostAuthor: '{{ post.original_post.primary_author.name }}', | ||
currentPostAuthor: '{{ post.primary_author.name }}' | ||
}; | ||
|
||
// Use either an X /Twitter handle or name in the post text | ||
// Use either a Bluesky handle or name in the post text | ||
thanks = encodeURIComponent(`{% t 'social-row.tweets.translation', { | ||
author: '${ | ||
twitterHandles.originalPostAuthor | ||
? twitterHandles.originalPostAuthor | ||
blueskyHandles.originalPostAuthor | ||
? blueskyHandles.originalPostAuthor | ||
: names.originalPostAuthor | ||
}', | ||
translator: '${ | ||
twitterHandles.currentPostAuthor | ||
? twitterHandles.currentPostAuthor | ||
blueskyHandles.currentPostAuthor | ||
? blueskyHandles.currentPostAuthor | ||
: names.currentPostAuthor | ||
}' | ||
} %}`); | ||
} else if (!isTranslation && twitterHandles.currentPostAuthor) { | ||
} else if (!isTranslation && blueskyHandles.currentPostAuthor) { | ||
// An original post on a source Ghost instance | ||
// Only customize the post text if the author has an X / Twitter handle | ||
// Only customize the post text if the author has an Bluesky handle | ||
thanks = encodeURIComponent(`{% t 'social-row.tweets.default', { | ||
author: '${twitterHandles.currentPostAuthor}' | ||
author: '${blueskyHandles.currentPostAuthor}' | ||
} %}`); | ||
} | ||
|
||
const twitterIntentStr = thanks | ||
? `https://x.com/intent/post?text=${thanks}%0A%0A${title}%0A%0A${url}` | ||
: `https://x.com/intent/post?text=${title}%0A%0A${url}`; | ||
const blueSkyIntentStr = thanks | ||
? `https://bsky.app/intent/compose?text=${thanks}%0A%0A${title}%0A%0A${url}` | ||
: `https://bsky.app/intent/compose?text=${title}%0A%0A${url}`; | ||
|
||
const windowOpenStr = `window.open( | ||
'${twitterIntentStr}', | ||
'share-twitter', | ||
'${blueSkyIntentStr}', | ||
'share-bluesky', | ||
'width=550, height=235' | ||
); return false;`; | ||
|
||
tweetButton.setAttribute('onclick', windowOpenStr); | ||
shareButton.setAttribute('onclick', windowOpenStr); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters