Search code examples
javascripthtmljekyllliquidgitlab-pages

Access and display a gitlab username on a private gitlab pages hosted website


I built a static wiki website hosted by GitLab pages and requires that they log into their gitlab account before accessing the site. It uses Jekyll and some HTML templates to build the site pages from markdown files.

Some of the info on the site would be clearer to the users if I could display their gitlab usernames to them. I would have to indicate where it would be displayed on the markdown file.

Is there any way to set their gitlab username as a variable in html, liquid, or JavaScript that could be accessed from a markdown file?

Edit: I know it's static, but I've gotten the site to access to user's light/dark mode preferences using JavaScript. My naive understanding of JavaScript tells me getting their username should be doable.


Solution

  • You can call the gitlab api <your-gitlab.com>/api/v4/user this will return a user object of the currently logged in user with username, user-id the users email.