Skip to content

Commit

Permalink
Merge pull request #631 from gethinode/develop
Browse files Browse the repository at this point in the history
Make page breakpoint configurable
  • Loading branch information
markdumay authored Nov 14, 2023
2 parents c349c28 + 6821ac2 commit cc4a476
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 36 deletions.
1 change: 1 addition & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
endorse = true
footerBelowFold = false
loading = "lazy"
breakpoint = "md"
[main.externalLinks]
cue = false
tab = false
Expand Down
1 change: 1 addition & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
canonifyAssetsURLs = false
footerBelowFold = false
loading = "lazy"
breakpoint = "md"
[main.externalLinks]
cue = true
tab = true
Expand Down
6 changes: 6 additions & 0 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@
"col-8",
"col-9",
"col-auto",
"col-lg-2",
"col-lg-4",
"col-lg-8",
"col-md-10",
"col-md-2",
"col-md-3",
"col-md-4",
"col-md-8",
"col-md-9",
"col-md-auto",
"col-sm-12",
"col-sm-3",
Expand All @@ -141,6 +144,7 @@
"d-grid",
"d-inline",
"d-inline-flex",
"d-lg-block",
"d-md-block",
"d-md-flex",
"d-md-none",
Expand Down Expand Up @@ -332,6 +336,7 @@
"row",
"row-cols-1",
"row-cols-2",
"row-cols-lg-3",
"row-cols-md-2",
"row-cols-md-3",
"row-cols-sm-2",
Expand All @@ -341,6 +346,7 @@
"search-suggestions",
"shadow",
"show",
"sidebar-overflow",
"slide",
"small",
"spinner-border",
Expand Down
3 changes: 3 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
{{ $sections := partial "utilities/GetSections.html" (dict "page" . "loading" $loading) }}
{{- $.Scratch.Set "sections" $sections -}}

{{- /* Define main breakpoint */ -}}
{{- $.Scratch.Set "breakpoint" (partial "utilities/GetBreakpoint.html") }}

<!doctype html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
Expand Down
12 changes: 8 additions & 4 deletions layouts/_default/list/body.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{- $sections := $.Scratch.Get "sections" -}}
{{- $fullCover := $.Scratch.Get "fullCover" -}}
{{- $breakpoint := $.Scratch.Get "breakpoint" -}}
{{- $layout := .Params.layout -}}

<div class="row row-cols-1 row-cols-sm-2">
<div class="col col-sm-12 col-md-8">
<div class="row row-cols-1 row-cols-{{ $breakpoint.current }}-2">
<div class="col-12 col-{{ $breakpoint.current }}-9">
{{ if not .IsHome }}
{{ with .Title }}<p id="{{ anchorize . }}" class="display-4 mt-5{{ if and $.IsHome site.Params.home.centerHeadline }} text-center{{ end }}">{{ . }}</p>{{ end }}
{{ end }}
Expand All @@ -15,9 +16,12 @@
{{- if $fullCover }}{{ $loading = site.Params.main.loading }}{{ end }}
{{ end }}
{{- $content := partial "utilities/ProcessContent" (dict "page" . "raw" .RawContent "loading" $loading) -}}
{{ $content | safeHTML }}
{{- $content | safeHTML -}}
{{ if and (and $sections (eq (len $sections) 1)) (not $content) }}
<p class="pt-4">{{- T "emptyList" }}.</p>
{{ end }}
</div>
</div>
<div class="col col-{{ $breakpoint.current }}-3 d-none d-{{ $breakpoint.current }}-block">
{{/* Empty in default layout */}}
</div>
</div>
30 changes: 11 additions & 19 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{- define "partials/single-main.html" -}}
{{- $breakpoint := $.Scratch.Get "breakpoint" -}}
{{ if .Site.Params.navigation.breadcrumb }}{{ partial "assets/breadcrumb.html" . }}{{ end -}}

{{ .Render "single/header" }}

{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}}
<div class="d-md-none pb-5">{{ partial "assets/toc-dropdown.html" . }}</div>
<div class="d-{{ $breakpoint.current }}-none pb-5">{{ partial "assets/toc-dropdown.html" . }}</div>
{{- end -}}
{{ .Render "single/body" }}

Expand All @@ -18,6 +19,7 @@
{{ define "main" -}}
{{- $menu := .Scratch.Get "sidebar" -}}
{{- $version := .Scratch.Get "version" -}}
{{- $breakpoint := $.Scratch.Get "breakpoint" -}}

{{ $sidebar := "" }}
{{- $hasSidebar := .Site.Params.navigation.sidebar | default true -}}
Expand All @@ -38,34 +40,24 @@ <h5 class="offcanvas-title" id="offcanvas-label">{{ strings.FirstUpper $.Section
{{ end }}

<div class="container-xxl flex-fill p-4 px-xxl-0">
{{ if and $menu $hasSidebar -}}
<div class="row row-cols-md-2 row-cols-lg-3">
<div class="col col-md-3 col-lg-2 d-none pt-5 d-md-block sidebar-overflow sticky-top">
{{ if $hasSidebar -}}
<div class="row row-cols-1 row-cols-{{ $breakpoint.current }}-2 row-cols-{{ $breakpoint.next }}-3">
<div class="col col-{{ $breakpoint.next }}-2 d-none d-{{ $breakpoint.next }}-block sidebar-overflow sticky-top pt-5">
{{ $sidebar | safeHTML }}
</div>
<div class="col col-md-9 col-lg-8 mb-5 p-4">
<div class="col-12 col-{{ $breakpoint.current }}-9 col-{{ $breakpoint.next }}-8 mb-5 p-4">
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-lg-2 d-none d-lg-block pt-5">
<div class="col col-{{ $breakpoint.current }}-3 col-{{ $breakpoint.next }}-2 d-none d-{{ $breakpoint.current }}-block pt-5">
{{ $toc | safeHTML }}
</div>
</div>
{{ else if $hasSidebar }}
<div class="row row-cols-1 row-cols-sm-3">
<div class="col col-md-2 d-none d-md-block"></div>
<div class="col col-sm-12 col-md-8">
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-md-2 d-none d-md-block">
{{ $toc | safeHTML }}
</div>
</div>
{{ else }}
<div class="row row-cols-1 row-cols-sm-2">
<div class="col col-sm-12 col-md-9">
<div class="row row-cols-1 row-cols-{{ $breakpoint.current }}-2">
<div class="col col-{{ $breakpoint.prev }}-12 col-{{ $breakpoint.current }}-9">
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-md-3 d-none d-md-block">
<div class="col col-{{ $breakpoint.current }}-3 d-none d-{{ $breakpoint.current }}-block">
{{ $toc | safeHTML }}
</div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions layouts/partials/assets/card-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
-->

{{- $page := .page -}}
{{- $breakpoint := partial "utilities/GetBreakpoint.html" -}}

{{- if not (in (slice "*hugolib.pageState" "*hugolib.pageForShortcode") (printf "%T" $page)) -}}
{{- errorf "partial [assets/card-group.html] - Invalid value for param 'page': %T" $page -}}
Expand Down Expand Up @@ -108,10 +109,10 @@
{{- end -}}
{{- $colGrid := "" -}}
{{- if eq $cols "1" }}{{ $colGrid = "row-cols-1" -}}
{{- else if eq $cols "2" }}{{ if $responsive }}{{ $colGrid = "row-cols-1 row-cols-sm-1 row-cols-md-2" }}{{ else }}{{ $colGrid = "row-cols-2" }}{{ end -}}
{{- else if eq $cols "3" }}{{ if $responsive }}{{ $colGrid = "row-cols-1 row-cols-sm-2 row-cols-md-3" }}{{ else }}{{ $colGrid = "row-cols-3" }}{{ end -}}
{{- else if eq $cols "4" }}{{ if $responsive }}{{ $colGrid = "row-cols-1 row-cols-sm-2 row-cols-md-4" }}{{ else }}{{ $colGrid = "row-cols-4" }}{{ end -}}
{{- else if eq $cols "5" }}{{ if $responsive }}{{ $colGrid = "row-cols-1 row-cols-sm-3 row-cols-md-5" }}{{ else }}{{ $colGrid = "row-cols-5" }}{{ end -}}
{{- else if eq $cols "2" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-1 row-cols-%s-2" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-2" }}{{ end -}}
{{- else if eq $cols "3" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-3" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-3" }}{{ end -}}
{{- else if eq $cols "4" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-4" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-4" }}{{ end -}}
{{- else if eq $cols "5" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-3 row-cols-%s-5" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-5" }}{{ end -}}
{{ end -}}

{{- $gutter := .gutter | default "4" -}}
Expand Down
21 changes: 21 additions & 0 deletions layouts/partials/utilities/GetBreakpoint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- /* Define main breakpoint */ -}}
{{ $prev := 0 }}
{{ $next := 0 }}
{{ $result := dict }}
{{- $breakpoints := slice "xs" "sm" "md" "lg" "xl" "xxl" }}
{{- $breakpoint := site.Params.main.breakpoint | default "md" -}}
{{- if not (in $breakpoints $breakpoint) -}}
{{- errorf "layout [_default/baseof.html] - Invalid value for param 'breakpoint': %s" $breakpoint -}}
{{ else }}
{{ range $index, $item := $breakpoints }}
{{ if eq $item $breakpoint }}
{{ $prev = sub $index 1 }}
{{ $next = add $index 1 }}
{{ end }}
{{ end }}
{{ if lt $prev 0 }}{{ $prev = 0 }}{{ end }}
{{ if ge $next (len $breakpoints) }}{{ $next = sub (len $breakpoints) 1 }}{{ end }}
{{ $result = dict "prev" (index $breakpoints $prev) "current" $breakpoint "next" (index $breakpoints $next) }}
{{- end -}}

{{ return $result }}
3 changes: 2 additions & 1 deletion layouts/partials/utilities/GetSections.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

{{- $thumbnail := (or (and (reflect.IsMap $sectionPage.Params.Thumbnail) $sectionPage.Params.Thumbnail.url) $sectionPage.Params.Thumbnail) -}}
{{- $icon := $sectionPage.Params.Icon -}}
{{- $content := $sectionPage.Content -}}
{{- $content := "" -}}
{{ if not $sectionPage.IsSection }}{{ $content = $sectionPage.Content }}{{ end -}}
{{- $sectionTitle := strings.FirstUpper $sectionPage.Type -}}
{{- $moreTitle := "" -}}
{{- with (index site.Params.sections $section) -}}
Expand Down
11 changes: 6 additions & 5 deletions layouts/tags/list.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{{ define "main" }}
{{- $page := . -}}
{{- $layout := $page.Params.layout -}}
{{- $breakpoint := $.Scratch.Get "breakpoint" -}}

<div class="container-xxl flex-fill p-4 px-xxl-0">
<div class="row row-cols-1 row-cols-sm-3">
<div class="col col-md-2 d-none d-md-block"></div>
<div class="col col-sm-12 col-md-8">
<div class="row row-cols-1 row-cols-{{ $breakpoint.prev }}-3">
<div class="col col-{{ $breakpoint.current }}-2 d-none d-{{ $breakpoint.current }}-block"></div>
<div class="col col-{{ $breakpoint.prev }}-12 col-{{ $breakpoint.current }}-8">
{{- if ne $layout "featured" -}}
{{ if and (not $page.IsHome) site.Params.navigation.breadcrumb }}
<div>{{ partial "assets/breadcrumb.html" $page }}</div>
Expand Down Expand Up @@ -36,7 +37,7 @@
{{ $year := .Date.Year }}
{{ $lastYear := $.Scratch.Get "lastYear"}}
<div class="row mt-2">
<div class="d-none d-sm-block col-sm-3 mt-auto text-right">
<div class="d-none d-{{ $breakpoint.prev }}-block col-{{ $breakpoint.prev }}-3 mt-auto text-right">
<time class="post-date" datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ (partial "utilities/date.html" (dict "date" .Date "format" "medium")) }}
</time>
Expand All @@ -52,7 +53,7 @@
{{ end }}
{{ end }}
</div>
<div class="col col-md-2 d-none d-md-block"></div>
<div class="col col-{{ $breakpoint.current }}-2 d-none d-{{ $breakpoint.current }}-block"></div>
</div>
</div>
{{ end }}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.21.6",
"version": "0.21.7",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down

0 comments on commit cc4a476

Please sign in to comment.