Skip to content

Commit

Permalink
Merge pull request #5 from ntk148v/floating-toc
Browse files Browse the repository at this point in the history
feat(toc): implement toc sidebar
  • Loading branch information
ntk148v authored Jul 25, 2023
2 parents 923a174 + 213d2b9 commit 38bebfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
14 changes: 10 additions & 4 deletions assets/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
--page-gutter: 24px;
--header-height: 48px;
--footer-height: 48px;
--sidebar-top: 70px;
--sidebar-top: 72px;

--content-width: 40rem;
--content-height: calc(100vh - (var(--page-top) * 2) - var(--footer-height));

@media (min-width: 640px) {
--page-top: 192px;
--sidebar-top: 300px;
@media (min-width: 1080px) {
--page-top: 128px;
--sidebar-top: 144px;
--page-gutter: 48px;
}
}
Expand Down Expand Up @@ -119,6 +119,12 @@ pre > code {
/* ################################# */
/* # Table of contents # */
/* ################################# */
@media screen and (min-width: 1080px) {
#toc {
@apply fixed top-0 left-0 z-40 w-1/4 px-page-gutter py-sidebar-top;
}
}

#toc-list ol {
@apply pl-3 m-1 border-l-2 text-sm text-muted;
counter-reset: tocitem;
Expand Down
12 changes: 1 addition & 11 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ <h1>{{ .Title | emojify }}</h1>
{{- partial "date" .Date -}}{{ if ne .Date .Lastmod }}<nobr class="text-sm text-muted">&#8674&nbsp;</nobr>{{- partial "date" .Lastmod -}}{{ end }}

{{- partial "tag" . -}}
<!-- Table of contents -->
{{ if default true (default .Site.Params.toc .Params.toc) }}
{{ if gt (.TableOfContents | countwords)
0
}}
<details>
<summary>Table of contents</summary>
<div id="toc-list">{{ .TableOfContents }}</div>
</details>
{{ end }}
{{ end }}
{{- partial "toc.html" . -}}
<!-- Content -->
{{- partial "custom/content-before.html" . -}}
<div class="content">{{ .Content | emojify }}</div>
Expand Down
13 changes: 13 additions & 0 deletions layouts/partials/toc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Table of contents -->
<div id="toc">
{{ if default true (default .Site.Params.toc .Params.toc) }}
{{ if gt (.TableOfContents | countwords)
0
}}
<details>
<summary>Table of contents</summary>
<div id="toc-list">{{ .TableOfContents }}</div>
</details>
{{ end }}
{{ end }}
</div>

0 comments on commit 38bebfd

Please sign in to comment.