Coder Social home page Coder Social logo

Comments (7)

xoxys avatar xoxys commented on June 14, 2024

Thanks for your report. Can you provide some more details in which situations the toc fail? The current toc shortcode is just a wrapper around the default TableOfContents of the current page provided by Goldmark.

from hugo-geekdoc.

signalogic avatar signalogic commented on June 14, 2024

Ok I think it does work. First I added to [Params] section of config.toml:

[markup]
  [markup.tableOfContents]
    endLevel = 6
    ordered = false
    startLevel = 1

then added a "TableOfContents_Geekdoc" param in the page's frontmatter, then put this in toc.html shortcode:

{{ if .Page.Params.TableOfContents_Geekdoc }}
  {{ $tocLevels := default (default 6 .Site.Params.GeekdocToC) .Page.Params.GeekdocToC }}

  <div class="gdoc-toc gdoc-toc__level--{{$tocLevels}}">{{ .Page.TableOfContents }}<hr></div>

{{ else }} {{/* default Hugo Toc */}}

  <div>{{ .Page.TableOfContents }}<hr></div> {{/* note that .TableOfContents is built-in Hugo var */}}

{{ end }}

Both ways work, I don't see any difference. What would the gdoc-toc class do or display differently ?

Thanks. Sorry to reply slow.

from hugo-geekdoc.

xoxys avatar xoxys commented on June 14, 2024

I don't really understand why you have added a TableOfContents_Geekdoc variable. The ToC is provided by the in-build page variable .Page.TableOfContents. You could completely ignore the toc shortcode and use .Page.TableOfContents directly in your markdown files. If you want to configure the ToC you could use:

[markup]
  [markup.tableOfContents]
    endLevel = 6
    ordered = false
    startLevel = 1

The shortcode is just a second way to add a ToC to your markdown pages and has some small benefits:

  • it is wrapped by a div block and has it's own CSS classes which could be used to customize how the ToC looks like
  • it adds a small horizontal line at the bottom of the ToC to separate it from the content
  • it will place the ToC at whatever position you want it to be on the page
  • it has it's own CSS based way to define the ToC level depth because the old markdown renderer was not able to configure the ToC, this feature was introduced by Goldmark

So in general you have two ways to use the ToC. You could choose between the shortcode wrapper or the plain build-in .Page.TableOfContents variable. You could also choose between the methods to control the ToC depth. One option is to use the default Goldmark config options (see above) or the custom CSS solution controlled by the GeekdocToC variable but this one only works with the shortcode because it required the injected CSS classes gdoc-toc gdoc-toc__level--*. For example GeekdocToC = 3 will display ToC level 1-3.

from hugo-geekdoc.

signalogic avatar signalogic commented on June 14, 2024

I added the var for testing purposes, just to quickly switch back and forth (see the first {{if ... }} in toc.html).

Thanks for the benefits list. Being able to control depth level and place the toc as needed are definitely useful.

You mention injected classes. I found the .gdoc-toc{} definition in _base.scss but where are the __level--N classes defined ?

Thanks.

from hugo-geekdoc.

xoxys avatar xoxys commented on June 14, 2024

It's also in _base.scss https://github.com/thegeeklab/hugo-geekdoc/blob/master/src/sass/_base.scss#L462.

from hugo-geekdoc.

signalogic avatar signalogic commented on June 14, 2024

Ok got it. I needed to bone up on the "&" selector.

from hugo-geekdoc.

xoxys avatar xoxys commented on June 14, 2024

As you can see on the file ending thats SASS syntax. I'm going to close the issue.

from hugo-geekdoc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.