641 字
3 分钟
在GitLab 17.x中使用全局页脚悬挂上自己的ICP备案号
起因
我个人比较喜欢钻研一些自己不了解的东西, 然后就捣鼓我的GitLab, 既然我的GitLab在国内并且网站已经备案了,就需要悬挂ICP备案号, 所以就有了这篇文章。
一些闲话
我在GitLab的代码仓库发现了极狐GitLab几年前提交的代码, 这个代码就是如果有全局页脚文件, 就将其渲染出来, 这大大简化了实现页脚的流程
效果展示

准备工作
- 准备一个使用
omnibus软件包安装的GitLab实例(其他安装方式也行, 不过我用的就是这种方式安装所以就用这种方式做示例) - 必须是管理员并且可以使用ssh访问GitLab
开始
- cd到指定的目录下然后创建一个文件夹
$ cd /opt/gitlab/embedded/service/gitlab-rails/app/views/shared
$ mkdir footer
$ vim _global_footer.html.haml将下面的内容复制到这个文件中
%div{ style: 'border: 0px solid #000; height: 40px; background-color: #fbfafd; display: flex; justify-content: flex-end; align-items: center; position: fixed; bottom: 0; left: 0; width: 100%; padding-right: 60px;z-index: 3' }
%div.gl-flex.gl-items-center.gl-gap-3
%p.gl-text-sm{ style: "margin: 0;" }
%a{ href: "https://12377.cn", target: "_blank", style: "color: #737278; display: flex; align-items: center;" }
%img{ src: "https://static.rtast.cn/images/anti-law-928014fd1478111affd68504f2450afb07d3eab1b69150f9af9791326a592c77.svg", alt: "12377图标", style: "width: 1em; height: 1em; margin-right: 4px;" }
违法和不良信息举报中心
%p.gl-text-sm{ style: "margin: 0;" }
%a{ href: "https://beian.miit.gov.cn", target: "_blank", style: "color: #737278;" } 皖ICP备2024066235-1号
%p.gl-text-sm{ style: "margin: 0; display: flex; align-items: center;" }
%a{ href: "https://beian.mps.gov.cn/#/query/webSearch?code=34122102000574", target: "_blank", style: "color: #737278; display: flex; align-items: center;" }
%img{ src: "https://beian.mps.gov.cn/web/assets/logo01.6189a29f.png", alt: "公安备案图标", style: "width: 1em; height: 1em; margin-right: 4px;" }
皖公网安备34122102000574号把我的备案信息改成你的备案信息
-
重启GitLab的
puma服务(这个服务缓存了所有的haml代码,所以重启启动都需要重新加载haml,比较慢) -
大功告成
登陆页面的ICP页脚
这个页脚由于是修改了原有的代码,所以升级GitLab的时候会被升级的文件覆盖掉所以每次升级后都要重新弄一遍
$ vim /opt/gitlab/embedded/service/gitlab-rails/app/views/devise/shared_footer.html.haml然后把下面的内容复制到这个文件里
.footer-container.gl-w-full.gl-self-end
%hr.gl-m-0
.container.gl-py-5.gl-flex.gl-justify-between.gl-items-start
.gl-hidden.md:gl-flex.gl-gap-5.gl-flex-wrap
- unless public_visibility_restricted?
= link_to _("Explore"), explore_root_path
= link_to "Blog", "https://rtast.cn", target: "_blank"
= link_to "Github", "https://github.com/RTAkland", target: "_blank"
.gl-flex.gl-items-center.gl-gap-3
%p.gl-text-sm{style: "margin: 0;"}
%a{href: "https://beian.miit.gov.cn", target: "_blank"} 皖ICP备2024066235-1号
%p.gl-text-sm{style: "margin: 0; display: flex; align-items: center;"}
%a{href: "https://beian.mps.gov.cn/#/query/webSearch?code=34122102000574", target: "_blank", style: "display: flex; align-items: center;"}
%img{src: "https://beian.mps.gov.cn/web/assets/logo01.6189a29f.png", alt: "公安备案图标", style: "width: 1em; height: 1em; margin-right: 4px;"}
皖公网安备34122102000574号
- if one_trust_enabled?
= render Pajamas::ButtonComponent.new(category: :tertiary, size: :small, button_options: { class: 'ot-sdk-show-settings' }) do
= _("Cookie Preferences")
= render 'devise/shared/language_switcher'
= footer_message这里我删掉了原本的Help和About GitLab按钮你可以按需修改link_to的内容
登录页的效果展示
