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

Add support for floating table of contents #25

Open
jpmvferreira opened this issue Feb 14, 2021 · 7 comments
Open

Add support for floating table of contents #25

jpmvferreira opened this issue Feb 14, 2021 · 7 comments

Comments

@jpmvferreira
Copy link

jpmvferreira commented Feb 14, 2021

The original academic theme supports a floating table of content, mentioned in this issue.

To summarize the entire discussion simply adding the following to /layouts/_default/single.html:

{{- define "main" -}}
{{ if .Params.toc }}
<div class="container-fluid docs">
    <div class="row flex-xl-nowrap">
      <div class="d-none d-xl-block col-xl-2 docs-toc">
        <ul class="nav toc-top">
          <li><a href="#" id="back_to_top" class="docs-toc-title">{{ i18n "on_this_page" }}</a></li>
        </ul>
        {{ .TableOfContents }}
        {{ partial "docs_toc_foot" . }}
      </div>
      <main class="col-12 col-md-0 col-xl-10 py-md-3 pl-md-5 docs-content" role="main">
{{ end }}
        <article class="article">
            {{ partial "page_header" . }}
            <div class="article-container">
              <div class="article-style">
                {{ .Content }}
              </div>
              {{ partial "page_footer" . }}
            </div>
        </article>
  {{ if .Params.toc }}
      </main>
    </div>
  </div>
  {{ end }}
{{- end -}}

And then adding toc: true to index.md on your post would result in this (source):
image

As you can see there's a floating toc on the right.

Here's what I did:

  • Added /layouts/_default/single.html with the previously mentioned content
  • Set toc: true on my post
  • Got error: page_footer.html doesn't exist
  • Changed page_foorter to site_footer because site_footer.html exists
  • Nothing happened
  • Picked up page_footer.html from the original academic theme as well as all the others partials that were called in this file
  • Blog post looked like a mess, there was in fact a toc on the right but it didn't move it was stuck in the beginning of the post and there were strange visual things happening with the footer, but no error

As as workaround I have a static toc in the beginning of the post, but I feel like this would be a good improvement and could be easy to implement, considering that it was fully functional in the academic theme.

@jpmvferreira
Copy link
Author

jpmvferreira commented Feb 14, 2021

There was a user in that same issue that suggested that changing to type: book would work because that type already has a floating toc however I was unable to get it working as well.

@somratpro
Copy link
Contributor

Hello @Jpund

In which version of academic has this ability?

@jpmvferreira
Copy link
Author

According to the issue is not built in, but according to the users on that issue thread after performing the modifications (changing /layouts/_default/single.html as specified and setting toc: true on the blog post) it worked as expected, and the websites show that (for instance here and I think here is also academic theme, although heavily modified).

@nick-zhy
Copy link

nick-zhy commented Mar 5, 2021

This method seems invalid for .Rmd.

How to get this toc sidebar for .Rmd?

@jpmvferreira
Copy link
Author

Did you manage to get this working for academia with .md? Because I can't get it to work on this theme, the instructions given for academic don't work under academia, there might be a few extra changes required for it to work.

Also I don't know much of .Rmd files, but I had the idea that you could easily convert it to .md files easily without making any changes, for instance I found this link from RStudio where they state that one of the goals of RMarkdown is to be easily converted into another flavors of markdown, so you might wanna check out on that.

@nick-zhy
Copy link

nick-zhy commented Mar 5, 2021

Did you manage to get this working for academia with .md? Because I can't get it to work on this theme, the instructions given for academic don't work under academia, there might be a few extra changes required for it to work.

Also I don't know much of .Rmd files, but I had the idea that you could easily convert it to .md files easily without making any changes, for instance I found this link from RStudio where they state that one of the goals of RMarkdown is to be easily converted into another flavors of markdown, so you might wanna check out on that.

I'm sorry, it works well on academic theme.

And thanks for your answer about converting .Rmd to .md. I know this process, but if I do this converting, another annoying problem arises: the math formulas in I wrote in .Rmd get wrong in .md (after rendering on the website). All subscribt "_" must have a "\" in front of it, otherwise the formulas go wrong after rendering.

I dong't know how to deal with this problem either. I' ve searched for ansewers for some days. Some people say goldmark goes well, but I don't know how to use it.

@jpmvferreira
Copy link
Author

Ah well, I have never used it before so I can't help you either.

If you somehow manage to get a floating table of contents in academia, let me know, because after doing the changes as suggested in academic in academia I ended up with a broken table of contents and blog post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants