Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically render wiki TOC #19873

Merged
merged 5 commits into from
Jun 8, 2022
Merged

Automatically render wiki TOC #19873

merged 5 commits into from
Jun 8, 2022

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Jun 2, 2022

Automatically add sidebar in the wiki view containing a TOC for the wiki page.

Fix #822

Signed-off-by: Andrew Thornton art27@cantab.net

Automatically add sidebar in the wiki view containing a TOC for the wiki page.

Fix go-gitea#822

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 2, 2022
@zeripath zeripath added this to the 1.18.0 milestone Jun 2, 2022
Signed-off-by: Andrew Thornton <art27@cantab.net>
@lunny
Copy link
Member

lunny commented Jun 3, 2022

I think the problem is the toc need a hide button but that could be another PR.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 3, 2022
Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

zeripath commented Jun 3, 2022

Happy for this to be moved into 1.17 btw.

@zeripath
Copy link
Contributor Author

zeripath commented Jun 3, 2022

I think the problem is the toc need a hide button but that could be another PR.

done

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 4, 2022
@lunny
Copy link
Member

lunny commented Jun 4, 2022

I think the problem is the toc need a hide button but that could be another PR.

done

I would like it becomes a per-user setting to show or hide the directory defaultly and also we need a more width screen for the main area.

Copy link
Contributor

@Gusted Gusted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise lgtm, just the helper function can cause some issues when used by future code.

modules/templates/helper.go Outdated Show resolved Hide resolved
Signed-off-by: Andrew Thornton <art27@cantab.net>
Copy link
Contributor

@Gusted Gusted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 8, 2022
@wxiaoguang wxiaoguang modified the milestones: 1.18.0, 1.17.0 Jun 8, 2022
@wxiaoguang wxiaoguang merged commit ac88f21 into go-gitea:main Jun 8, 2022
@buhtz
Copy link

buhtz commented Jun 8, 2022

Sorry for asking but I am not able to find the information in the code diff.

How should a markdown file look like that Gitea render an automatic TOC for it? Something like this?

[[TOC]]

# Header A
foobar

## Header A.a
Foobar

# Header B
Foobar

And how would the result look like? Do you have a screenshot?

@wxiaoguang
Copy link
Contributor

You can try it on try.gitea.io: https://try.gitea.io/wxiaoguang/test/wiki/test-toc

# H1
## h2
### h3

image

@buhtz
Copy link

buhtz commented Jun 8, 2022

You can try it on try.gitea.io: https://try.gitea.io/wxiaoguang/test/wiki/test-toc

I assume I miss understand something. This link goes to a wiki page. Does this work for markdown-files (e.g. README.md) also?

I also would say it is not a good idea to render the TOC as a separate element. It is lost where it is now. A toc should be there where the TOC-Placeholder (e.g. something like [[toc]]) is placed.

Let me give you an example:
https://codeberg.org/buhtz/hyperorg/src/branch/main/README.md

Here you see

  1. The toc is part of the rendered README file.
  2. The toc is not on top but the third section (or second firts-level section) because I (the user) want it there.
  3. But the toc is hand written not autogenerated.

@wxiaoguang
Copy link
Contributor

Does this work for markdown-files (e.g. README.md) also?

Nope, this PR is only for Wiki TOC.

I also would say it is not a good idea to render the TOC as a separate element. It is lost where it is now. A toc should be there where the TOC-Placeholder (e.g. something like [[toc]]) is placed.
And for README ....

Since this PR has got approvals and got merged, there could be new issues for the features & enhancements.

@zeripath zeripath deleted the wiki-toc branch June 8, 2022 19:26
@zeripath
Copy link
Contributor Author

zeripath commented Jun 8, 2022

Add this to the top of your markdown file.

---
gitea: none
include_toc: true
---

zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 9, 2022
* giteaofficial/main:
  Prevent NPE whilst migrating if there is a team request review (go-gitea#19855)
  [skip ci] Updated translations via Crowdin
  Add support for rendering terminal output with colors (go-gitea#19497)
  Fix viewed images not loading in a PR (go-gitea#19919)
  Remove out-dated comments (go-gitea#19921)
  Automatically render wiki TOC (go-gitea#19873)
  Improve wording on delete access token modal (go-gitea#19909)
  [skip ci] Updated translations via Crowdin
  Add breaking email restrictions checker in doctor (go-gitea#19903)
  Ensure minimum mirror interval is reported on settings page (go-gitea#19895)
  Improve UX on modal for deleting an access token (go-gitea#19894)
  update discord invite (go-gitea#19907)
  Only log non ErrNotExist errors in git.GetNote  (go-gitea#19884)
  [skip ci] Updated translations via Crowdin
  Update frontend guideline (go-gitea#19901)
  Make AppDataPath absolute against the AppWorkPath if it is not (go-gitea#19815)
@buhtz
Copy link

buhtz commented Jun 9, 2022

---
gitea: none
include_toc: true
---

Where can I find the documentation about it? The term include_toc give me any results on https://docs.gitea.io/en-us/search/?s=toc_include.

Are there some more modifiers for the toc? e.g. I don't like the fold-mechanism and the headline is not in h1-style.

@garfeng
Copy link

garfeng commented Jun 24, 2022

Thank you very much for your excellent work.

Could you add this feature to TOC ?

When user scroll the page down, make the TOC fixed to top,.

function convertRemToPixels(rem) {    
    return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}

function UpdateTOCPosition() {
    if (!jQuery) {
        return;
    }
    const toc = jQuery(".wiki-content-toc");
    if (toc.length <= 0) {
        return;
    }
    const parent = toc[0].parentElement;
    const parentRect = parent.getBoundingClientRect();
    if (parentRect.top < 0) {
        const padding = convertRemToPixels(2)
        toc.css({ position: "fixed", width: parent.clientWidth-padding, "top": 0 })
    } else {
        toc.css({ position: "inherit", width: "auto" })
    }
}

window.addEventListener("scroll", UpdateTOCPosition);
window.addEventListener("resize", UpdateTOCPosition);

AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 24, 2022
Automatically add sidebar in the wiki view containing a TOC for the wiki page.
Make the TOC collapsable

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TOC for Wiki Pages
7 participants