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

feat: add the toc.position parameter #547

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions assets/hb/modules/blog/scss/post/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
grid-template-rows: auto auto 1fr;

@include media-breakpoint-up(lg) {
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 */
@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 assets/hb/modules/blog/scss/post/_toc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

/* stylelint-disable selector-id-pattern */
#TableOfContents {
border-bottom: 1px solid var(--#{$prefix}border-color);
font-size: 1rem !important;
}
/* stylelint-enable selector-id-pattern */
}

@include media-breakpoint-up(lg) {
height: calc(100vh - var(--#{$prefix}top-offset));
@if $hb-blog-toc-position != 'content' {
height: calc(100vh - var(--#{$prefix}top-offset));
}

@include top-offset;
}
Expand Down
3 changes: 3 additions & 0 deletions assets/hb/modules/blog/scss/variables.tmpl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
$hb-blog-sidebar: {{ $hasSidebar }};
$hb-blog-sidebar-position: {{ default "start" site.Params.hb.blog.sidebar.position }};
$hb-blog-home-pinned-posts-pos: '{{ default "" site.Params.hb.blog.home.pinned_posts_position }}';

// ToC
$hb-blog-toc-position: {{ default "end" site.Params.hb.blog.toc.position }};
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ pinned_posts_position = ""

[params.hb.blog.sidebar]
position = "start"

[params.hb.blog.toc]
position = "end" # start, end or content.
2 changes: 2 additions & 0 deletions layouts/partials/hb/modules/blog/post/toc.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-toc-begin" "Page" .) }}
{{- if partial "base/functions/has-toc" . }}
<div class="hb-module pb-1">
<div class="h6 d-none d-md-block">{{ i18n "on_this_page" }}</div>
Expand All @@ -19,3 +20,4 @@
</div>
</div>
{{- end }}
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-toc-end" "Page" .) }}
17 changes: 11 additions & 6 deletions layouts/partials/hb/modules/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ <h1 class="hb-blog-post-title">{{ .Title }}</h1>
<div class="hb-blog-post-desc lead mt-1">{{ . }}</div>
{{- end }}
</div>
<div
class="hb-blog-post-toc text-body-secondary position-sticky overflow-y-auto">
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-toc-begin" "Page" .) }}
{{- partialCached "hb/modules/blog/post/toc" . . }}
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-toc-end" "Page" .) }}
</div>
{{- $tocPos := default "start" site.Params.hb.blog.toc.position }}
{{- if ne $tocPos "content" }}
<div class="hb-blog-post-toc text-body-secondary position-sticky overflow-y-auto">
{{- partialCached "hb/modules/blog/post/toc" . . }}
</div>
{{- end }}
<div class="hb-blog-post-main">
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-begin" "Page" .) }}
{{- partial "hugopress/functions/render-hooks" (dict "Name" "hb-blog-post-content-begin" "Page" .) }}
{{- if eq $tocPos "content" }}
<div class="hb-blog-post-toc">
{{- partialCached "hb/modules/blog/post/toc" . . }}
</div>
{{- end }}
{{- $attributes := partial "hugopress/functions/render-attributes" (dict "Page" . "Name" "hb-blog-post-content") }}
<div
class="hb-blog-post-content hb-module"
Expand Down