Skip to content

Commit

Permalink
feat: TOC auto-shortens when the article gets too long
Browse files Browse the repository at this point in the history
feat: TOC auto-shortens when the article gets too long
feat: Enabled  option for floating + static TOC
chore: better styling for TOC
  • Loading branch information
chollinger93 committed Jun 20, 2023
1 parent 3e17a48 commit 318f4b4
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 11 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,29 @@ And some **bugfixes**:

![Screenshot](https://raw.githubusercontent.com/chollinger93/ink-free/master/images/screenshot.png "Ink-Free theme")

![Screenshot](https://raw.githubusercontent.com/chollinger93/ink-free/master/images/screenshot2.png "Ink-Free theme")
![image-20230620151830930](images/screenshot2.png)

### Static vs Floating TOC
### Table Of Contents Options

#### Floating

![image-20230620114414684](images/floating_toc.png)

![image-20230620114454738](images/static_toc.png)
#### Static

![image-20230620151300448](images/static_toc.png)

#### Both

![image-20230620151006141](images/both_toc.png)

#### Truncated

![image-20230620151110164](images/truncated_toc.png)

#### Mobile

![image-20230620151645609](images/mobile_toc.png)

### Run the example
```
Expand Down
6 changes: 4 additions & 2 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ copyright = "© Copyright notice"
mode = "auto"

# Enable a table of contents:
# Either "static"/true, "floating", or "none"
# Either "static"/true, "floating", "both", or "none" (default: static)
# The floating TOC dissapears on mobile and adds 200px vertical space
toc = "floating"
toc = "both"
# Whether to truncate everything but H1/H2 headings if the last element in a TOC isn't visible. Enabled by default
enableTocTrunate = true

# Max tags
maxTags = 7
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/content/posts/post-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def make[F[_]: Sync: Parallel: ThrowableMonadError](cfg: ServiceConfig, client:
</html>
{{< /highlight >}}

### Inline code
`Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum `

## List Types

### Ordered List
Expand Down
211 changes: 211 additions & 0 deletions exampleSite/content/posts/post-9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
---
title: "Floating Navigation bar"
date: "2023-06-19"
description: "The Floating Navigation bar can get truncated to show h2 headings if the table of content gets to long"
tags: [markdown, css, html, themes]
categories: [themes, syntax]
---

## Intro

Try this example with `toc = "floating"` and `toc = "static"`!

## Header

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

## Header 2

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

### Subitem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum tempus odio eu consectetur.

## Header 1
### Subitem
## Header 2
### Subitem
## Header 3
### Subitem
## Header 4
### Subitem
## Header 5
### Subitem
## Header 6
### Subitem
## Header 7
### Subitem
## Header 8
### Subitem
## Header 9
### Subitem
## Header 10
### Subitem
## Header 11
### Subitem
## Header 12
### Subitem
## Header 13
### Subitem
## Header 14
### Subitem
## Header 15
### Subitem
## Header 16
### Subitem
## Header 17
### Subitem
## Header 18
### Subitem
## Header 19
### Subitem
## Header 20
### Subitem
## Header 21
### Subitem
## Header 22
### Subitem
## Header 23
### Subitem
## Header 24
### Subitem
## Header 25
### Subitem
## Header 26
### Subitem
## Header 27
### Subitem
## Header 28
### Subitem
## Header 29
### Subitem
## Header 30
### Subitem
## Header 31
### Subitem
## Header 32
### Subitem
## Header 33
### Subitem
## Header 34
### Subitem
## Header 35
### Subitem
## Header 36
### Subitem
## Header 37
### Subitem
## Header 38
### Subitem
## Header 39
### Subitem
## Header 40
### Subitem
## Header 41
### Subitem
## Header 42
### Subitem
## Header 43
### Subitem
## Header 44
### Subitem
## Header 45
### Subitem
## Header 46
### Subitem
## Header 47
### Subitem
## Header 48
### Subitem
## Header 49
### Subitem
## Header 50
Binary file added images/both_toc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mobile_toc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static_toc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/truncated_toc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<body>


{{ if and (gt .WordCount 400 ) (eq .Site.Params.toc "floating") }}
{{ if and (gt .WordCount 400 ) (or (eq .Site.Params.toc "floating") (eq .Site.Params.toc "both") )}}
<div class="container-wide wrapper">
{{ partial "head.html" . }}

Expand All @@ -20,7 +20,7 @@
{{ end }}

{{ partial "footer.html" . }}
{{ if and (gt .WordCount 400 ) (eq .Site.Params.toc "floating") }}
{{ if and (gt .WordCount 400 ) (or (eq .Site.Params.toc "floating") (eq .Site.Params.toc "both") )}}
{{ partial "toc_script.html" . }}
{{ end }}
</body>
Expand Down
11 changes: 10 additions & 1 deletion layouts/partials/content_floating_toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
{{ partial "post_header.html" . }}

<!-- The TOC will be static on mobile decides -->
<aside class="show-on-mobile toc">
{{ if and (gt .WordCount 400 ) (eq .Site.Params.toc "both") }}
<aside class="toc" id="static-toc">
<header>
<h3>Contents</h3>
</header>
{{.TableOfContents}}
</aside>
{{ else }}
<aside class="show-on-mobile toc" id="static-toc">
<header>
<h3>Contents</h3>
</header>
{{.TableOfContents}}
</aside>
{{ end }}

{{ .Content }}

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/content_static.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- Inline TOC -->
{{ if and (gt .WordCount 400 ) (or (eq .Site.Params.toc "static") (eq .Site.Params.toc "true") )}}
<aside class="toc">
<aside class="toc" id="static-toc">
<header>
<h3>Contents</h3>
</header>
Expand Down
Loading

0 comments on commit 318f4b4

Please sign in to comment.