Skip to content

Commit

Permalink
fix: sharing link for github id or url
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe committed Dec 13, 2024
1 parent 61b48f6 commit a104e16
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions blocks/author-box/author-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function openPopup(e) {
window.open(
href,
type,
'popup,top=233,left=233,width=700,height=467',
);
}

Expand All @@ -18,10 +17,14 @@ async function buildSharing(id, type = 'github') {
const sharing = document.createElement('div');
sharing.classList.add('sharing-details');
const scriptUrl = new URL(import.meta.url);
let href;
let iconsPath;
if (type === 'github') {
// support github id or url
href = id.startsWith('https://github.com/') ? id : `https://github.com/${id}`;
iconsPath = new URL('../../icons/icon-github.svg', scriptUrl).href;
} else if (type === 'linkedin') {
href = id;
iconsPath = new URL('../../icons/icon-linkedin.svg', scriptUrl).href;
}
// Fetch SVG content
Expand All @@ -48,7 +51,7 @@ async function buildSharing(id, type = 'github') {
} = profiles[type] || profiles.github;

sharing.innerHTML = `<span>
<a data-type="${dataType}" href="${id}" alt="${altText}" aria-label="${ariaLabel}" title="${titleText}">
<a data-type="${dataType}" data-href="${href}" alt="${altText}" aria-label="${ariaLabel}" title="${titleText}">
${svgContent}
</a>
</span>`;
Expand All @@ -59,7 +62,10 @@ async function addProfileLinkToImage(authorImage, profileId, type = 'github') {
const authorLink = document.createElement('a');
authorLink.classList.add('blog-author-link');
if (type === 'github') {
authorLink.setAttribute('data-href', `https://github.com/${profileId}`);
authorLink.setAttribute(
'data-href',
profileId.startsWith('https://github.com/') ? profileId : `https://github.com/${profileId}`,
);
} else if (type === 'linkedin') {
authorLink.setAttribute('data-href', profileId);
}
Expand Down Expand Up @@ -124,6 +130,7 @@ export default async function decorateAuthorBox(blockEl) {
shareBlock = await buildSharing(linkedinLink, 'linkedin');
}
if (shareBlock) {
shareBlock.addEventListener('click', openPopup);
bylineContainer.append(shareBlock);
}
}

0 comments on commit a104e16

Please sign in to comment.