Skip to content

Commit 61b7f6b

Browse files
authored
Updated LinkedIn url building for different profile types (#543)
ref https://linear.app/ghost/issue/ENG-2409/not-possible-to-add-company-linkedin-profile-to-staff-member - Updates the LinkedIn url helper so that if a user has a company, school, or pub link, it gets built properly instead of prepending with in/ - If a username is stored without any of those, it will still prepend in/ to build a proper link
1 parent 00b1c6b commit 61b7f6b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

packages/social-urls/lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ module.exports.instagram = function instagram(username) {
8080
* @returns {string}
8181
*/
8282
module.exports.linkedin = function linkedin(username) {
83-
// LinkedIn URLs use /in/, stored without @
84-
return 'https://www.linkedin.com/in/' + username;
83+
// LinkedIn URLs use in/, company/, school/, or pub/ stored as-is
84+
const pathTypes = ['in/', 'company/', 'school/', 'pub/'];
85+
// If username doesn't start with one of those, default to in/
86+
const endOfUrl = pathTypes.some(pathType => username.startsWith(pathType)) ? username : 'in/' + username;
87+
88+
return 'https://www.linkedin.com/' + endOfUrl;
8589
};

packages/social-urls/test/urls.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,28 @@ describe('lib/social: urls', function () {
154154
});
155155

156156
describe('linkedin', function () {
157-
it('should return a correct concatenated URL', function () {
158-
social.linkedin('myusername').should.eql('https://www.linkedin.com/in/myusername');
157+
it('should return a correct concatenated URL for personal profile', function () {
158+
social.linkedin('in/myusername').should.eql('https://www.linkedin.com/in/myusername');
159+
});
160+
161+
it('should return a correct concatenated URL for company profile', function () {
162+
social.linkedin('company/mycompany').should.eql('https://www.linkedin.com/company/mycompany');
163+
});
164+
165+
it('should return a correct concatenated URL for school profile', function () {
166+
social.linkedin('school/myschool').should.eql('https://www.linkedin.com/school/myschool');
159167
});
160168

161-
it('should handle usernames with periods, hyphens, and underscores', function () {
162-
social.linkedin('john.smith-123').should.eql('https://www.linkedin.com/in/john.smith-123');
169+
it('should return a correct concatenated URL for a legacy pub profile', function () {
170+
social.linkedin('pub/johnsmith/12/34/567').should.eql('https://www.linkedin.com/pub/johnsmith/12/34/567');
171+
});
172+
173+
it('should handle usernames with hyphens', function () {
174+
social.linkedin('in/john-smith-123').should.eql('https://www.linkedin.com/in/john-smith-123');
175+
});
176+
177+
it('should default to in/ when username does not start with in/, company/, school/, or pub/', function () {
178+
social.linkedin('myusername').should.eql('https://www.linkedin.com/in/myusername');
163179
});
164180
});
165181
});

0 commit comments

Comments
 (0)