From 82ad3593a4735055d9b362ab94bc4a9e4f20e4a4 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 4 Feb 2026 17:04:55 +0100 Subject: feat(frontend): smaller list display instead of bigger one --- backend/data.go | 22 +++++++++++++--- backend/home.go | 2 +- backend/section.go | 4 ++- backend/templates/components.html | 52 +++++++++++++++++++++++++++---------- backend/templates/home_section.html | 2 +- frontend/scss/general.scss | 33 +++++++++++++++++++++++ 6 files changed, 95 insertions(+), 20 deletions(-) diff --git a/backend/data.go b/backend/data.go index 4f9bab1..9fd6aea 100644 --- a/backend/data.go +++ b/backend/data.go @@ -92,9 +92,11 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string "asset": func(path string) *assetData { return getAsset(r.Context(), path) }, - "next": func(i int) int { return i + 1 }, - "before": func(i int) int { return i - 1 }, - "first": templateFirst, + "next": func(i int) int { return i + 1 }, + "before": func(i int) int { return i - 1 }, + "first": templateFirst, + "firstData": templateFirstData, + "restData": templateRestData, }).ParseFS(templates, "templates/components.html", fmt.Sprintf("templates/%s.html", name), "templates/base.html") if err != nil { panic(err) @@ -215,3 +217,17 @@ func templateFirst(a []*Section) *Section { } return a[0] } + +func templateFirstData(a []*sectionData) *sectionData { + if len(a) == 0 { + return nil + } + return a[0] +} + +func templateRestData(a []*sectionData) []*sectionData { + if len(a) < 2 { + return nil + } + return a[1:] +} diff --git a/backend/home.go b/backend/home.go index f824a69..0fae11a 100644 --- a/backend/home.go +++ b/backend/home.go @@ -27,7 +27,7 @@ func (h *homeData) SetData(d *data) { func HandleHome(r *chi.Mux) { r.Get("/", func(w http.ResponseWriter, r *http.Request) { cfg := r.Context().Value(configKey).(*Config) - d := handleGenericSectionDisplay(w, r, cfg.Sections, 3) + d := handleGenericSectionDisplay(w, r, cfg.Sections, 4) if d == nil { return } diff --git a/backend/section.go b/backend/section.go index 9d49ea2..376f562 100644 --- a/backend/section.go +++ b/backend/section.go @@ -43,6 +43,7 @@ type sectionData struct { DataTitle string Content template.HTML Slug string + URI string } func (d *sectionData) SetData(dt *data) { @@ -163,7 +164,7 @@ func (s *Section) Handle(r *chi.Mux) { } func (s *Section) handleList(w http.ResponseWriter, r *http.Request) { - p := s.handlePagination(w, r, 5) + p := s.handlePagination(w, r, 7) if p == nil { return } @@ -214,6 +215,7 @@ func (s *Section) parse(d *sectionData, mu *sync.Mutex, path, slug string) bool d.Article = true d.DataTitle = slug d.Slug = slug + d.URI = s.URI b, err := os.ReadFile(path + ".md") if err != nil { if os.IsNotExist(err) { diff --git a/backend/templates/components.html b/backend/templates/components.html index e49a8c4..bf555f0 100644 --- a/backend/templates/components.html +++ b/backend/templates/components.html @@ -13,27 +13,51 @@ {{ end }} {{ end }} -{{ define "section_display" }} -
- {{ $uri := .URI }} - {{ range .Data }} - - {{ end }} +{{ define "data_display" }} + +{{ end }} +{{ define "section_pagination" }} +{{ end }} +{{ define "section_display--no-first" }} +
+ {{ range .Data }} + {{ template "data_display" . }} + {{ end }} + {{ template "section_pagination" . }} +
+{{ end }} +{{ define "section_display" }} +
+ {{ $first := firstData .Data }} +
+

{{ $first.DataTitle }}

+
+ {{ $first.Img.Alt }} +
{{ $first.Img.Legend }}
+
+

{{ $first.Description }}

+
+ {{ range restData .Data }} + {{ template "data_display" . }} + {{ end }} + {{ template "section_pagination" . }}
{{ end }} diff --git a/backend/templates/home_section.html b/backend/templates/home_section.html index 1101843..6f31fc0 100644 --- a/backend/templates/home_section.html +++ b/backend/templates/home_section.html @@ -5,7 +5,7 @@

{{ .Name }}

{{ .Description }}

- {{ template "section_display" . }} + {{ template "section_display--no-first" . }} {{ end }} {{ end }} diff --git a/frontend/scss/general.scss b/frontend/scss/general.scss index 28c1c81..13d2053 100644 --- a/frontend/scss/general.scss +++ b/frontend/scss/general.scss @@ -215,3 +215,36 @@ th { padding-left: 0.5rem; padding-right: 0.5rem; } + +.article__list { + display: flex; + flex-direction: column; + gap: calc(2 * var(--margin-base)); +} + +article.large { + display: grid; + grid-template-columns: 1fr 1fr; + align-items: center; + gap: 2rem; + + @media only screen and (max-width: 800px) { + grid-template-columns: 1fr; + } + + & h3 { + margin-top: 0; + } + + & p { + margin-bottom: 0; + } + + & figure { + margin-bottom: 0; + } + + & > div { + margin-bottom: 2rem; + } +} -- cgit v1.2.3