Add head-widgets

This commit is contained in:
Svilen Markov
2025-05-06 13:37:14 +01:00
parent 9ffb2d9939
commit c9e6b774f3
8 changed files with 90 additions and 19 deletions

View File

@@ -73,13 +73,14 @@ type user struct {
}
type page struct {
Title string `yaml:"name"`
Slug string `yaml:"slug"`
Width string `yaml:"width"`
DesktopNavigationWidth string `yaml:"desktop-navigation-width"`
ShowMobileHeader bool `yaml:"show-mobile-header"`
HideDesktopNavigation bool `yaml:"hide-desktop-navigation"`
CenterVertically bool `yaml:"center-vertically"`
Title string `yaml:"name"`
Slug string `yaml:"slug"`
Width string `yaml:"width"`
DesktopNavigationWidth string `yaml:"desktop-navigation-width"`
ShowMobileHeader bool `yaml:"show-mobile-header"`
HideDesktopNavigation bool `yaml:"hide-desktop-navigation"`
CenterVertically bool `yaml:"center-vertically"`
HeadWidgets widgets `yaml:"head-widgets"`
Columns []struct {
Size string `yaml:"size"`
Widgets widgets `yaml:"widgets"`
@@ -107,6 +108,12 @@ func newConfigFromYAML(contents []byte) (*config, error) {
}
for p := range config.Pages {
for w := range config.Pages[p].HeadWidgets {
if err := config.Pages[p].HeadWidgets[w].initialize(); err != nil {
return nil, formatWidgetInitError(err, config.Pages[p].HeadWidgets[w])
}
}
for c := range config.Pages[p].Columns {
for w := range config.Pages[p].Columns[c].Widgets {
if err := config.Pages[p].Columns[c].Widgets[w].initialize(); err != nil {

View File

@@ -230,6 +230,20 @@ func (p *page) updateOutdatedWidgets() {
var wg sync.WaitGroup
context := context.Background()
for w := range p.HeadWidgets {
widget := p.HeadWidgets[w]
if !widget.requiresUpdate(&now) {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
widget.update(context)
}()
}
for c := range p.Columns {
for w := range p.Columns[c].Widgets {
widget := p.Columns[c].Widgets[w]

View File

@@ -13,6 +13,7 @@
.page.content-ready > .page-content {
display: block;
animation: pageContentEntrance .3s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}
.page-column-small .size-title-dynamic {
@@ -127,10 +128,9 @@ body {
.page-columns {
display: flex;
gap: var(--widget-gap);
animation: pageColumnsEntrance .3s cubic-bezier(0.25, 1, 0.5, 1) backwards;
}
@keyframes pageColumnsEntrance {
@keyframes pageContentEntrance {
from {
opacity: 0;
transform: translateY(10px);

View File

@@ -44,6 +44,10 @@
opacity: 0.6;
}
.head-widgets {
margin-bottom: var(--widget-gap);
}
.widget-content {
container-type: inline-size;
container-name: widget;

View File

@@ -2,12 +2,20 @@
<div class="mobile-reachability-header">{{ .Page.Title }}</div>
{{ end }}
<div class="page-columns">
{{ range .Page.Columns }}
<div class="page-column page-column-{{ .Size }}">
{{ range .Widgets }}
{{ .Render }}
{{ end }}
</div>
{{ end }}
{{ if .Page.HeadWidgets }}
<div class="head-widgets">
{{- range .Page.HeadWidgets }}
{{- .Render }}
{{- end }}
</div>
{{ end }}
<div class="page-columns">
{{- range .Page.Columns }}
<div class="page-column page-column-{{ .Size }}">
{{- range .Widgets }}
{{- .Render }}
{{- end }}
</div>
{{- end }}
</div>

View File

@@ -1,5 +1,5 @@
<div class="widget widget-type-{{ .GetType }}{{ if ne "" .CSSClass }} {{ .CSSClass }}{{ end }}">
{{- if not .HideHeader}}
<div class="widget widget-type-{{ .GetType }}{{ if .CSSClass }} {{ .CSSClass }}{{ end }}">
{{- if not .HideHeader }}
<div class="widget-header">
{{- if ne "" .TitleURL }}
<h2><a href="{{ .TitleURL | safeURL }}" target="_blank" rel="noreferrer" class="uppercase">{{ .Title }}</a></h2>