Skip to content

Commit

Permalink
feat: add the toc page parameter, when false then hide the ToC (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Feb 11, 2024
1 parent c945247 commit c791065
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
44 changes: 25 additions & 19 deletions assets/hb/modules/blog/scss/post/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
grid-gap: 1rem;
grid-template-areas:
"intro"
"toc"
"main";
grid-template-rows: auto auto 1fr;

@include media-breakpoint-up(lg) {
@if $hb-blog-toc-position == 'start' {
grid-template-areas:
"toc intro"
"toc main";
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
grid-template-rows: 1fr auto;
grid-template-columns: 1fr 4fr;
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
} @else if $hb-blog-toc-position == 'end' {
grid-template-areas:
"intro toc"
"main toc";
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
grid-template-rows: auto 1fr;
grid-template-columns: 4fr 1fr;
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
&.toc {
grid-template-areas:
"intro"
"toc"
"main";
grid-template-rows: auto auto 1fr;

@include media-breakpoint-up(lg) {
@if $hb-blog-toc-position == 'start' {
grid-template-areas:
"toc intro"
"toc main";
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
grid-template-rows: 1fr auto;
grid-template-columns: 1fr 4fr;
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
} @else if $hb-blog-toc-position == 'end' {
grid-template-areas:
"intro toc"
"main toc";
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
grid-template-rows: auto 1fr;
grid-template-columns: 4fr 1fr;
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/hb/modules/blog/single.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="hb-blog-main-container">
<div class="hb-blog-main">
{{ partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-main-begin" "Page" .) }}
<div class="hb-blog-post position-relative">
{{- $toc := default true .Params.toc }}
<div class="hb-blog-post position-relative{{ cond $toc ` toc` `` }}">
<div class="hb-blog-post-intro hb-module mb-2">
<h1 class="hb-blog-post-title text-break">{{ .Title }}</h1>
<div class="hb-blog-post-meta">
Expand All @@ -15,7 +16,7 @@ <h1 class="hb-blog-post-title text-break">{{ .Title }}</h1>
{{- end }}
</div>
{{- $tocPos := default "start" site.Params.hb.blog.toc.position }}
{{- if ne $tocPos "content" }}
{{- if and $toc (ne $tocPos "content") }}
<div class="hb-blog-post-toc text-body-secondary position-sticky overflow-y-auto">
{{- partialCached "hb/modules/blog/post/toc" . . }}
</div>
Expand Down

0 comments on commit c791065

Please sign in to comment.