Implement announcements as data-driven content
This change allows announcements to have an expiry date and / or a “do not show until” date. Separating this out also leaves room for future changes to enforce a set of approvers. Co-Authored-By: Karen Bradshaw <kbhawkey@gmail.com>
This commit is contained in:
@@ -1,14 +1,34 @@
|
||||
{{ if .Page.Param "announcement" }}
|
||||
<section lang="en" id="announcement" style="background-color:{{ .Page.Param "announcement_bg" }}">
|
||||
<aside>
|
||||
<div class="content announcement main-section" data-nosnippet>
|
||||
|
||||
<h4 class="announcement">
|
||||
{{ T "announcement_title" | markdownify }}
|
||||
</h4>
|
||||
<p class="announcement">{{ T "announcement_message" | markdownify }}</p>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
</section>
|
||||
{{ $dateRegExp := "^[0-9]{4}-1[0-2]|0[1-9]-(?:3[01]|0[1-9]|[12][0-9])T(?:2[0-3]|[01][0-9]):(?:[0-5][0-9]):(?:60|[0-5][0-9])$" }}
|
||||
{{ $announcementShown := false }}
|
||||
{{ range $.Site.Data.announcements }}
|
||||
{{ range .announcements }}
|
||||
{{ if or ( eq .endTime nil ) ( eq .message nil ) }}
|
||||
{{ errorf "Invalid announcement: %#v" . }}
|
||||
{{ end }}
|
||||
{{ if and (ne .startTime nil ) (lt ( len ( findRE $dateRegExp .startTime ) ) 1 ) }}
|
||||
{{ errorf "Invalid announcement start time: %#v" .startTime }}
|
||||
{{ end }}
|
||||
{{ if lt ( len ( findRE $dateRegExp .endTime ) ) 1 }}
|
||||
{{ errorf "Invalid announcement end time: %#v" .endTime }}
|
||||
{{ end }}
|
||||
{{ if or (eq .startTime nil ) (lt ( time .startTime ) now ) }}
|
||||
{{- if or (eq .endTime nil ) (gt ( time .endTime ) now ) -}}
|
||||
{{- if not $announcementShown -}}
|
||||
{{- $announcementShown = true -}}
|
||||
<section lang="en" id="announcement" style="background-color: #3371e3; color: #fff; {{ .style | safeCSS }}">
|
||||
<aside>
|
||||
<div class="content announcement main-section" data-nosnippet>
|
||||
{{ if .title }}
|
||||
<h4 class="announcement">
|
||||
{{ .title | markdownify }}
|
||||
</h4>
|
||||
{{ end }}
|
||||
<p class="announcement">{{ .message | markdownify }}</p>
|
||||
</div>
|
||||
</aside>
|
||||
</section>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,14 +1,34 @@
|
||||
{{ if .Page.Param "announcement" }}
|
||||
<section lang="en" id="fp-announcement" style="background-color:{{ .Page.Param "announcement_bg" }}">
|
||||
<aside >
|
||||
<div class="content announcement main-section" data-nosnippet>
|
||||
|
||||
<h3>
|
||||
{{ T "announcement_title" | markdownify }}
|
||||
</h3>
|
||||
<p>{{ T "announcement_message" | markdownify }}</p>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
</section>
|
||||
{{ $dateRegExp := "^[0-9]{4}-1[0-2]|0[1-9]-(?:3[01]|0[1-9]|[12][0-9])T(?:2[0-3]|[01][0-9]):(?:[0-5][0-9]):(?:60|[0-5][0-9])$" }}
|
||||
{{ $announcementShown := false }}
|
||||
{{ range $.Site.Data.announcements }}
|
||||
{{ range .announcements }}
|
||||
{{ if or ( eq .endTime nil ) ( eq .message nil ) }}
|
||||
{{ errorf "Invalid announcement: %#v" . }}
|
||||
{{ end }}
|
||||
{{ if and (ne .startTime nil ) (lt ( len ( findRE $dateRegExp .startTime ) ) 1 ) }}
|
||||
{{ errorf "Invalid announcement start time: %#v" .startTime }}
|
||||
{{ end }}
|
||||
{{ if lt ( len ( findRE $dateRegExp .endTime ) ) 1 }}
|
||||
{{ errorf "Invalid announcement end time: %#v" .endTime }}
|
||||
{{ end }}
|
||||
{{ if or (eq .startTime nil ) (lt ( time .startTime ) now ) }}
|
||||
{{- if or (eq .endTime nil ) (gt ( time .endTime ) now ) -}}
|
||||
{{- if not $announcementShown -}}
|
||||
{{- $announcementShown = true -}}
|
||||
<section lang="en" id="fp-announcement" style="background-color: #3371e3; color: #fff; {{ .style | safeCSS }}">
|
||||
<aside>
|
||||
<div class="content announcement main-section" data-nosnippet>
|
||||
{{ if .title }}
|
||||
<h4 class="announcement">
|
||||
{{ .title | markdownify }}
|
||||
</h4>
|
||||
{{ end }}
|
||||
<p class="announcement">{{ .message | markdownify }}</p>
|
||||
</div>
|
||||
</aside>
|
||||
</section>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user