Link to tagged Github accounts in bio #68
Comments
|
@PatMyron Here is a script I came up with that will tag accounts: <script>
let bio = "The coolest company to work for is @github! There is also @aws and @microsoft.";
let linkedBio = "";
let found = false;
let link = "";
for (let i = 0; i < bio.length; i++) {
let currentChar = bio[i];
if (currentChar.startsWith("@")) {
link += currentChar;
found = true;
continue // we don't need to look at other chars until next iterations
}
if (found) {
if (/[^A-Za-z0-9]/.test(currentChar)) { // we found the end of the link (you can add more special chars to this)
let tag = "<a href=https://github.com/" + link.substr(1) + ">" + link + "</a>"
linkedBio += tag + currentChar // we add the special char at the end of the tag so that it actually appears, otherwise it does not
link = "";
found = false;
} else {
link += currentChar;
}
} else {
linkedBio += currentChar;
}
}
if (link.length > 0) { // means we need to add a link that is the last possible thing without anything after it
let tag = "<a href=https://github.com/" + link.substr(1) + ">" + link + "</a>"
linkedBio += tag
}
document.getElementById("bio").innerHTML = linkedBio
</script>This can probably be slimmed down and simplified, but I wrote it pretty quickly. Hope this helps! |
|
@landonp1203 This is simplified: <script>
let bio = "The coolest company to work for is @github! There is also @aws and @microsoft.";
let linkedBio = bio.replace(new RegExp("(?:@)(\\w+)", "g"), "<a href='https://github.com/$1'>@$1</a>");
document.getElementById("bio").innerHTML = linkedBio;
</script> |
|
@salifm not a JS expert, but I appreciate the slimplified version! |
|
Created a PR to include this script in the website boilerplate so everyone can benefit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Github itself will link to tagged accounts in bios. It'd be awesome if this website did as well in the bio!
The text was updated successfully, but these errors were encountered: