ToC or Sidebar in GitHub Wiki

南笙酒味 提交于 2019-12-04 07:28:48

问题


How do I create a ToC or a sidebar menu in a GitHub Wiki?

I saw some mentions of it and gollum the backend seems to support it, but how do I do it in a current GitHub project?

It should best be based on the headers I have in the page automatically.

These links all mention it, but do not show how to do it:

  • https://gist.github.com/379469 - some JavaScript hack
  • https://github.com/blog/774-git-powered-wikis-improved - GitHub mentioning it:

    "GitHub Wikis have a little-documented ability for footers and sidebars, something which some of our git-based Wiki authors are familiar with. The new Wiki editor gives you limited web-based editing of the footers and sidebars you have on your site. "


回答1:


While your solution works, there's an easier way to do it using GitHub's web interface. You can simply create a page named _Sidebar and/or _Footer.

See detailed instructions in Github Wiki sidebar menu builder with multi-level.

Edit The original article is gone and I can't find it in the cache so I've updated the link.




回答2:


Okay. Let me see if I understand this correctly:

  1. Clone your GitHub wiki. (There’s a Git section in the wiki. You can checkout your wiki-like code.)
  2. Create _Sidebar.md
  3. In normal wiki pages, use [[link]] for the sidebar
  4. Commit and push back to GitHub

This process is a pain in the ass. I’m surprised this “gollum” wiki has any acceptance.

Also: _Sidebar.md is therefore global for all pages. I would have to organize my wiki into folders, so I can define different sidebars for different pages.




回答3:


When you are in the wiki of your project, there is a link Add a custom sidebar. Click that.

Now you have a page that you edit as you would edit any other Markdown page. To make a table of contents you have to do it manually though. There is no automated method (as of August 2014). So for example:

# My menu
* [Home][home]
* [Technical documentation][techdocs]
* [User manual][usermanual]

[home]: https://github.com/myproject/wiki/Home
[techdocs]: https://github.com/myproject/wiki/Technical-documentation
[usermanual]: https://github.com/myproject/wiki/User-manual



回答4:


Note that the original question was about creating a side bar (easy, solved in the answers) or an actual table of contents (not answered).

One thing I can say is that the gollum 2.1 wiki syntax allows for a [[_TOC_]] tag, but a GitHub wiki won't recognise that (yet?).




回答5:


I think this is described in the Gollum README. (See the header and sidebar sections.)

Essentially, you make a _footer.ext and _sidebar.ext in the directory containing the page content.




回答6:


I just created a Python script which generates an index in the _Sidebar.md of GitHub based on the folder structure and pages in the wiki git.




回答7:


I have implemented the npm module github-wiki-sidebar to help github users to easily create and maintain the sidebar menu.

Source and Result: https://raw.githubusercontent.com/wiki/adriantanasa/github-wiki-sidebar/images/github-wiki-sidebar-generator.png

Source pages (as displayed in Wiki admin):

Home
Installation
Roadmap
Usage
Usage: Command line modifiers
Usage: Init Mode

Result (with customised order):

  • Home
  • Installation
  • Usage
    • Init mode
    • Command line modifiers
  • Roadmap

Pre-requirements:

  • clone your github wiki repository locally (displayed on the bottom-right of the Wiki UI)
  • install the github-wiki-sidebar

    git clone <https://github.com/<username>/<my-project-name>.wiki.git
    npm install -g github-wiki-sidebar
    

Create/update your wiki menu:

  • create new pages / rename pages on your github.com wiki admin
  • execute locally the github-wiki-sidebar script in your wiki repository folder

    cd /path/to/<my-project-name>.wiki
    # this fetches latest changes, generates sidebar file (_Sidebar.md) and pushes changes to github
    github-wiki-sidebar --git-push
    

The module allows customisation of the markdown output including ordering of items, the category separator, the template for the menu, the format of links and others.



来源:https://stackoverflow.com/questions/9239588/toc-or-sidebar-in-github-wiki

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!