From 20d8b28e1bed1f018279ec8c6fb251814694a1e2 Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Tue, 22 Dec 2020 21:57:33 +0000 Subject: [PATCH] Implement announcements as data-driven content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- data/announcements/scheduled.yaml | 31 +++++++++++++ layouts/partials/announcement.html | 46 ++++++++++++++------ layouts/partials/frontpage-announcement.html | 46 ++++++++++++++------ 3 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 data/announcements/scheduled.yaml diff --git a/data/announcements/scheduled.yaml b/data/announcements/scheduled.yaml new file mode 100644 index 0000000000..b6e41d5c1d --- /dev/null +++ b/data/announcements/scheduled.yaml @@ -0,0 +1,31 @@ +--- +# For an example of the format, see commented structure below. +# +# 🛈 Changes require approval from @kubernetes/steering-committee + +# The order matters: if two schedules overlaps, the announcement +# that comes FIRST in the following list takes precedence. +# +#announcements: +# - startTime: 2020-01-01T00:00:00 +# # startTime is optional +# endTime: 2021-04-01T00:00:00 +# # endTime is required +# style: >- +# color: #fff; background: #000; +# # style is optional; if using, set both color and background +# # choose a dark color for the background +# title: "Sample 1 announcement" +# # title is optional +# message: | +# Message *one*. +# [Hyperlink](https://en.wikipedia.org/wiki/Hyperlink). +# # message is required. You can use Markdown. +# - name: Sample 2 +# startTime: 2020-01-01T00:00:00 +# endTime: 2021-04-01T00:00:00 +# message: | +# Message *two*. + +# leave the "announcements" key in place +announcements: diff --git a/layouts/partials/announcement.html b/layouts/partials/announcement.html index 2ec2e96e35..b1d68292db 100644 --- a/layouts/partials/announcement.html +++ b/layouts/partials/announcement.html @@ -1,14 +1,34 @@ -{{ if .Page.Param "announcement" }} -
- -
+{{ $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 -}} +
+ +
+ {{- end -}} + {{- end -}} + {{- end -}} + {{ end }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/frontpage-announcement.html b/layouts/partials/frontpage-announcement.html index 5dce29e035..e70a387301 100644 --- a/layouts/partials/frontpage-announcement.html +++ b/layouts/partials/frontpage-announcement.html @@ -1,14 +1,34 @@ -{{ if .Page.Param "announcement" }} -
- -
+{{ $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 -}} +
+ +
+ {{- end -}} + {{- end -}} + {{- end -}} + {{ end }} {{ end }} \ No newline at end of file