Skip to content

Commit 07c581f

Browse files
authored
feat(profile): add Open Graph meta tags for social sharing (@TryOmar) (monkeytypegame#6598)
Add Open Graph meta tags to user profile pages to improve how they appear when shared on social media platforms. This includes title, description and URL meta tags. Closes monkeytypegame#6597 ### Description This PR adds Open Graph Protocol (OGP) meta tags to user profile pages to fix the issue with LinkedIn and other social media platforms incorrectly redirecting profile links to the homepage. The implementation: - Adds dynamic Open Graph meta tags for title, description and URL - Updates tags whenever a profile page is loaded - Uses the user's name in the title tag for better personalization ### Checks - [x] Check if any open issues are related to this PR; if so, be sure to tag them below. - [x] Make sure the PR title follows the Conventional Commits standard. - [x] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. <!-- label(optional scope): pull request title (@your_github_username) --> Closes monkeytypegame#6597 <!-- pro tip: you can mention an issue, PR, or discussion on GitHub by referencing its hash number e.g: [monkeytypegame#1234](monkeytypegame#1234) --> <!-- pro tip: you can press . (dot or period) in the code tab of any GitHub repo to get access to GitHub's VS Code web editor Enjoy! :) -->
1 parent 1826948 commit 07c581f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

frontend/src/ts/controllers/page-controller.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ type ChangeOptions = {
2323
data?: unknown;
2424
};
2525

26+
function updateOpenGraphUrl(): void {
27+
const ogUrlTag = document.querySelector('meta[property="og:url"]');
28+
const currentUrl = window.location.href;
29+
30+
if (ogUrlTag) {
31+
// Update existing tag
32+
ogUrlTag.setAttribute("content", currentUrl);
33+
} else {
34+
// Create and append new tag if it doesn't exist
35+
const newOgUrlTag = document.createElement("meta");
36+
newOgUrlTag.setAttribute("property", "og:url");
37+
newOgUrlTag.content = currentUrl;
38+
document.head.appendChild(newOgUrlTag);
39+
}
40+
}
41+
2642
export async function change(
2743
pageName: PageName,
2844
options = {} as ChangeOptions
@@ -92,12 +108,15 @@ export async function change(
92108
}
93109
Focus.set(false);
94110
ActivePage.set(nextPage.id);
111+
95112
await previousPage?.afterHide();
96113
await nextPage?.beforeShow({
97114
params: options.params,
98115
// @ts-expect-error for the future (i think)
99116
data: options.data,
100117
});
118+
119+
updateOpenGraphUrl();
101120
}
102121
);
103122
});

0 commit comments

Comments
 (0)