GitLab 自定义 wiki 侧边栏不起作用

问题描述 投票:0回答:4
  1. 我“拉取”了我项目的 wiki 存储库。
  2. 创建了“_sidebar.md”文件。
  3. Git 添加
  4. Git 提交
  5. 将更改推送到 GitLab。
  6. 在 Google Chrome 的隐身模式下加载了我的项目的 Wiki 页面。
  7. 自定义侧边栏未呈现。

刷新了很多次。没有运气。

这是我的_sidebar.md的内容:

0. [Home](home)
1. [Page 1](page-1)
2. [Page 2](page-2)

有什么想法吗?

git gitlab sidebar gitlab-wiki
4个回答
3
投票

现在正如 VonC 所解释的那样,它可以工作了。但是,您不需要克隆存储库。

只需在 GitLab GUI 上创建一个名为

_sidebar
的新页面即可。您可以通过以下方式访问它
your-repository/wikis/_sidebar
或在侧边栏中创建编辑链接:

0. [Home](home)
1. [Page 1](page-1)
2. [Page 2](page-2)

[Edit sidebar](/_sidebar/edit)

3
投票

现在应该可以使用 GitLab 11.2(2018 年 8 月 22 日)了,感谢 jsooter

参见“自定义 Wiki 侧边栏”:

在 GitLab 项目中使用 Wiki 来获取扩展文档时,右侧边栏默认显示 Wiki 页面结构的分层目录。
但是,在某些情况下,您可能希望提供其他内容,以扩展这组自动列出的页面。

在 GitLab 11.2 中,我们引入了一个选项,可以通过您自己的自定义侧边栏覆盖生成的目录。 通过添加

_sidebar
Wiki 页面,维护者可以完全自由地基于 GitLab Flavored Markdown 定义单独的 Wiki 侧边栏。


您还可以使用编辑器来确保侧边栏正确:请参阅GitLab 13.8(2021 年 1 月)。

快速编辑Wiki的侧边栏

在 Wiki 中创建名为

_sidebar
的 Markdown 文件将使用该文件的内容为您的项目生成自定义侧边栏导航菜单。
然而,编辑这个文件很棘手,因为界面中没有地方可以再次打开
_sidebar

感谢 GitLab 用户 Frank Li 的精彩社区贡献,从 GitLab 13.8 开始,Wiki 页面右上角现在有一个 Edit sidebar 按钮。

单击此按钮将自动创建

_sidebar
文件(如果尚不存在)并在页面编辑器中将其打开。
通过这种快速访问,可以更直观地创建并更轻松地维护自定义 Wiki 导航。

请参阅文档问题


3
投票

我发现手动更新侧边栏或目录很令人沮丧。因此,我编写了一个简单的代码,以正确的格式打印出列表,这样您就不需要手动编写它:

import os
ignore_list = [".git", ".idea", "create_table_of_content.py"]
spaces = "    "


def get_all_files_and_directories(path, depth):
    spaces_tmp = spaces*depth
    file_list = os.listdir(path)
    for f in file_list:
        if f in ignore_list:
            continue
        if os.path.isdir(path+"/"+f):
            print(f'{spaces_tmp}- {f}')
            get_all_files_and_directories(path+"/"+f, depth+1)
        elif f.split(".")[-1] == "md":
            print(f'{spaces_tmp}- [{f.split(".")[0]}]({f})')
    return


if __name__ == '__main__':
    c = os.getcwd()
    get_all_files_and_directories(c, 0)

只需在 wiki 存储库的根目录下运行即可。

输出示例:

- The-Code is a directory
    - editor-applications is a directory
        - [edit_hosts_file](edit_hosts_file.ps1.md)
        - [mount_logs_dir](mount_logs_dir.ps1.md)
        - [main-editor-app](main-editor-app.ps1.md)
        - [setup_tasks](setup_tasks.ps1.md)
- [home](home.md)
- [Logging](Logging.md)
- Execution is a directory
    - [User-Data](User-Data.md)
    - [General](General.md)
- [File-Structure](File-Structure.md)
- [Running-Manually](Running-Manually.md)
- [About](About.md)

这应该更容易维护。

编辑

我找到了这个仓库https://github.com/ekalinin/github-markdown-toc,其中包含一个按标题创建目录的工具。就我个人而言,我认为创建带有 TOC 的单页面比创建多页面 wiki 更好。


0
投票

我之前也遇到过这个问题。
您评论的示例代码(https://stackoverflow.com/a/69911858/23600355)非常有帮助。
我改进了它并创建了一个新的 Python 脚本。
▽ 示例代码(GitHhb)▽

import os

# Add directories, extensions, and file names that you do not want displayed in the sidebar.
IGNORE_LIST = [".git", "create_sidebar.py","README.md", \
               "_sidebar.md", "images", "githooks"]

# Initialize indentation (2 spaces ← 4 spaces will cause display errors)
SPACES = "  "
# Gets the current directory.
CURRENT_DIRECTORY = os.getcwd()
# Path of view_all_pages
ALL_PAGES = "<gitlab-repository-url>/-/wikis/pages"

def get_all_files_and_directories(path, depth):
    SPACES_tmp = SPACES*depth    
    file_list = os.listdir(path)    
    for f in file_list:
        if f in IGNORE_LIST:
            continue
        if os.path.isdir(path+"/"+f):
            writepath=(path+"/"+f)
            writepath=writepath.replace(CURRENT_DIRECTORY, '.')
            ## If the depth is 0, add "<details><summary>" before the folder name for folding in html.
            if depth==0:
                print(f'{SPACES_tmp}<details><summary> {f} </summary>')
                sidebar.write(f'{SPACES_tmp}<details><summary> {f} </summary>'+ "\n\n")
            else:
                print(f'{SPACES_tmp}* [{f}]({writepath})')
                #sidebar.write(f'{SPACES_tmp}* [{f}]({writepath})'+ "\n")
                sidebar.write(f'{SPACES_tmp}* 【{f}】'+ "\n")
            get_all_files_and_directories(path+"/"+f, depth+1)
            ## If the depth is 0, add "</details>" after the folder name for folding in html.
            if depth==0:
                print(f'{SPACES_tmp}</details>')
                sidebar.write(f'{SPACES_tmp}</details>'+ "\n\n")
        elif f.split(".")[-1] == "md":
            writepath=(path+"/"+f.split(".")[0])
            writepath=writepath.replace(CURRENT_DIRECTORY, '.')
            print(f'{SPACES_tmp}* [{f.split(".")[0]}]({writepath})')
            sidebar.write(f'{SPACES_tmp}* [{f.split(".")[0]}]({writepath})'+ "\n")

if __name__ == '__main__':
    sidebar = open("_sidebar.md", 'w', encoding="utf-8")
    get_all_files_and_directories(CURRENT_DIRECTORY, 0)
    ## Add ALL_PAGES.
    sidebar.write("\n" + f'##### 【[View All Pages]({ALL_PAGES})】'+ "\n")
    sidebar.close()

仅支持第一层目录的折叠结构。 默认的侧边栏在文章数量少的时候还好,但是当文章数量多的时候,它就有一个缺点,就是不能全部显示出来。

我决定将这个脚本与 git 预提交结合起来运行。

我确信这个问题已经解决了,但我会分享。

© www.soinside.com 2019 - 2024. All rights reserved.