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

Link to tagged Github accounts in bio #68

Open
PatMyron opened this issue Mar 7, 2019 · 4 comments · May be fixed by #181
Open

Link to tagged Github accounts in bio #68

PatMyron opened this issue Mar 7, 2019 · 4 comments · May be fixed by #181

Comments

@PatMyron
Copy link

@PatMyron PatMyron commented Mar 7, 2019

Github itself will link to tagged accounts in bios. It'd be awesome if this website did as well in the bio!

@LandonPatmore
Copy link
Contributor

@LandonPatmore LandonPatmore commented Apr 1, 2019

@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!

@salifm
Copy link

@salifm salifm commented Aug 23, 2019

@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>
@LandonPatmore
Copy link
Contributor

@LandonPatmore LandonPatmore commented Aug 24, 2019

@salifm not a JS expert, but I appreciate the slimplified version!

xevenheaven added a commit to xevenheaven/personal-website that referenced this issue Oct 20, 2019
xevenheaven added a commit to xevenheaven/personal-website that referenced this issue Oct 20, 2019
xevenheaven added a commit to xevenheaven/personal-website that referenced this issue Oct 20, 2019
@xevenheaven xevenheaven linked a pull request that will close this issue Oct 20, 2019
@xevenheaven
Copy link

@xevenheaven xevenheaven commented Oct 20, 2019

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.