Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: start bluesky conversions #1088

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/i18n/locales/english/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"learn-to-code-cta": "https://www.freecodecamp.org/learn/",
"twitter": "https://twitter.com/freecodecamp",
"bluesky": "https://bsky.app/profile/freecodecamp.bsky.social",
"footer": {
"about": "https://www.freecodecamp.org/news/about/",
"support": "https://www.freecodecamp.org/news/support/",
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/english/author/author.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const selectors = {
link: "[data-test-label='x-link']",
icon: "[data-test-label='x-icon']"
},
bluesky: {
link: "[data-test-label='bluesky-link']",
icon: "[data-test-label='bluesky-icon']"
},
facebook: {
link: "[data-test-label='facebook-link']",
icon: "[data-test-label='facebook-icon']"
Expand Down Expand Up @@ -173,6 +177,8 @@ describe('Author page (Hashnode sourced)', () => {
.find('svg')
.should('have.attr', 'data-test-label', 'x-icon');
});

//TODO: Add a bluesky test
});
});

Expand Down
14 changes: 7 additions & 7 deletions src/_data/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const { currentLocale_i18nISOCode, siteURL } = require('../../config');
const getUsername = require('../../utils/get-username');
const translate = require('../../utils/translate');

// Get X / Twitter profile based on links in config/i18n/locales/lang/links.json --
// Get Bluesky profile based on links in config/i18n/locales/lang/links.json --
// falls back to English Twitter profile if one for the current UI locale
// isn't found
const twitterURL = translate('links:twitter');
const twitterHandle = twitterURL
? `@${getUsername(twitterURL)}`
: '@freecodecamp';
const blueskyURL = translate('links:bluesky');
const blueskyHandle = blueskyURL
? `@${getUsername(blueskyURL)}`
: '@freecodecamp.bsky.social';
const logoURL =
'https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg';
const coverImageURL =
Expand All @@ -27,8 +27,8 @@ module.exports = async () => {
title: 'freeCodeCamp.org',
facebook: 'https://www.facebook.com/freecodecamp',
facebook_username: 'freecodecamp',
twitter_handle: twitterHandle,
twitter: `https://x.com/${twitterHandle}`,
bluesky_handle: blueskyHandle,
bluesky: `https://bsky.app/profile/${blueskyHandle}`,
logo: logoURL,
cover_image: coverImageURL,
og_image: coverImageURL,
Expand Down
40 changes: 20 additions & 20 deletions src/_includes/assets/js/social-row.js
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);
});
4 changes: 2 additions & 2 deletions src/_includes/partials/author-info.njk
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
{% include "partials/icons/website.njk" %}
</a>
{% endif %}
{% if author.twitter_handle %}
{% if author.bluesky_handle %}
<a
class="social-link social-link-tw"
href="https://x.com/{{ author.twitter_handle | replace("@", "") }}"
href="https://bsky.app/profile/{{ author.blueksy_handle | replace("@", "") }}"
target="_blank"
rel="noopener noreferrer"
data-test-label="x-link"
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/partials/social-row.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if post.primary_author.twitter_handle or post.original_post.primary_author.twitter_handle %}
{% if post.primary_author.bluesky_handle or post.original_post.primary_author.bluesky_handle %}
{% set tweetCTAKey = 'social-row.cta.tweet-a-thanks' %}
{% else %}
{% set tweetCTAKey = 'social-row.cta.tweet-it' %}
Expand Down
Loading