refactor: get rid of article toolbar

Same 3 column layout for article page and homepage
This commit is contained in:
Jimmy Cai 2022-02-26 22:39:20 +00:00 committed by GitHub
parent e0e7974205
commit a02463077b
7 changed files with 28 additions and 99 deletions

View File

@ -122,67 +122,6 @@
} }
} }
.article-page.has-toc {
.left-sidebar {
display: none;
}
.right-sidebar {
width: 100%;
padding: 0;
display: none;
@include respond(xl) {
display: block;
top: var(--main-top-padding);
}
}
#article-toolbar {
display: block;
@include respond(md) {
padding: 0;
}
@include respond(xl) {
margin-top: 0;
position: sticky;
top: var(--main-top-padding);
flex-shrink: 1;
a {
background: transparent;
box-shadow: none;
border: 1px solid var(--body-text-color);
width: 100%;
margin-right: 0;
svg {
flex-shrink: 0;
}
}
}
}
.main-container {
align-items: start;
flex-direction: column;
@include respond(xl) {
flex-direction: row;
}
}
.main {
padding-top: 0;
@include respond(xl) {
padding-top: var(--main-top-padding);
}
}
}
.widget--toc { .widget--toc {
background-color: var(--card-background); background-color: var(--card-background);
border-radius: var(--card-border-radius); border-radius: var(--card-border-radius);

View File

@ -37,7 +37,7 @@
} }
.right-sidebar { .right-sidebar {
flex-shrink: 0; width: 100%;
display: none; display: none;
&.sticky { &.sticky {

View File

@ -108,16 +108,8 @@ params:
id: id:
widgets: widgets:
enabled: homepage: []
- search page: []
- archives
- tag-cloud
archives:
limit: 5
tagCloud:
limit: 10
opengraph: opengraph:
twitter: twitter:

View File

@ -140,7 +140,6 @@ params:
- type: tag-cloud - type: tag-cloud
params: params:
limit: 10 limit: 10
page: page:
- type: toc - type: toc

View File

@ -6,7 +6,8 @@
</head> </head>
<body class="{{ block `body-class` . }}{{ end }}"> <body class="{{ block `body-class` . }}{{ end }}">
{{- partial "head/colorScheme" . -}} {{- partial "head/colorScheme" . -}}
<div class="container main-container flex {{ block `container-class` . }}on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }}{{ end }}"> {{- $hasWidget := default (gt (len .Site.Params.widgets.homepage) 0) (.Scratch.Get "hasWidget") -}}
<div class="container main-container flex on-phone--column {{ if $hasWidget }}extended{{ else }}compact{{ end }}">
{{- block "left-sidebar" . -}} {{- block "left-sidebar" . -}}
{{ partial "sidebar/left.html" . }} {{ partial "sidebar/left.html" . }}
{{- end -}} {{- end -}}

View File

@ -1,15 +1,26 @@
{{ define "body-class" }} {{ define "body-class" }}
{{ $TOCEnabled := default (default false .Site.Params.article.toc) .Params.toc }} article-page
{{- .Scratch.Set "hasTOC" (and (ge (len .TableOfContents) 100) $TOCEnabled) -}} {{/*
article-page {{ if (.Scratch.Get "hasTOC") }}has-toc{{ end }} Enable the right sidebar if
{{ end }} - Widget different from 'TOC' is enabled
- TOC is enabled and not empty
*/}}
{{- $HasWidgetNotTOC := false -}}
{{- $TOCWidgetEnabled := false -}}
{{- range .Site.Params.widgets.page -}}
{{- if ne .type "toc" -}}
{{ $HasWidgetNotTOC = true -}}
{{- else -}}
{{ $TOCWidgetEnabled = true -}}
{{- end -}}
{{- end -}}
{{ define "container-class" }} {{- $TOCManuallyDisabled := eq .Params.toc false -}}
{{ if (.Scratch.Get "hasTOC") }} {{- $TOCEnabled := and (not $TOCManuallyDisabled) $TOCWidgetEnabled -}}
extended {{- $hasTOC := ge (len .TableOfContents) 100 -}}
{{ else }} {{- .Scratch.Set "TOCEnabled" (and $TOCEnabled $hasTOC) -}}
on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }}
{{ end }} {{- .Scratch.Set "hasWidget" (or $HasWidgetNotTOC (and $TOCEnabled $hasTOC)) -}}
{{ end }} {{ end }}
{{ define "main" }} {{ define "main" }}
@ -30,19 +41,6 @@
{{ partialCached "article/components/photoswipe" . }} {{ partialCached "article/components/photoswipe" . }}
{{ end }} {{ end }}
{{ define "left-sidebar" }}
{{ if (.Scratch.Get "hasTOC") }}
<div id="article-toolbar">
<a href="{{ .Site.BaseURL | relLangURL }}" class="back-home">
{{ (resources.Get "icons/back.svg").Content | safeHTML }}
<span>{{ T "article.back" }}</span>
</a>
</div>
{{ else }}
{{ partial "sidebar/left.html" . }}
{{ end }}
{{ end }}
{{ define "right-sidebar" }} {{ define "right-sidebar" }}
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }} {{ if .Scratch.Get "hasWidget" }}{{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }}{{ end}}
{{ end }} {{ end }}

View File

@ -1,4 +1,4 @@
{{ if (.Context.Scratch.Get "hasTOC") }} {{ if (.Context.Scratch.Get "TOCEnabled") }}
<section class="widget archives"> <section class="widget archives">
<div class="widget-icon"> <div class="widget-icon">
{{ partial "helper/icon" "hash" }} {{ partial "helper/icon" "hash" }}