访问并在托管在私有GitLab页面上的网站上显示GitLab用户名。

huangapple go评论76阅读模式
英文:

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.

英文:

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.

答案1

得分: 1

你可以调用GitLab API <your-gitlab.com>/api/v4/user,这将返回当前登录用户的用户对象,包括用户名、用户ID和用户的电子邮件。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月4日 02:22:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定