Skip to content

Commit 20d8b28

Browse files
Tim Bannisterkbhawkey
andcommitted
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 <[email protected]>
1 parent 65e4bed commit 20d8b28

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

data/announcements/scheduled.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# For an example of the format, see commented structure below.
3+
#
4+
# 🛈 Changes require approval from @kubernetes/steering-committee
5+
6+
# The order matters: if two schedules overlaps, the announcement
7+
# that comes FIRST in the following list takes precedence.
8+
#
9+
#announcements:
10+
# - startTime: 2020-01-01T00:00:00
11+
# # startTime is optional
12+
# endTime: 2021-04-01T00:00:00
13+
# # endTime is required
14+
# style: >-
15+
# color: #fff; background: #000;
16+
# # style is optional; if using, set both color and background
17+
# # choose a dark color for the background
18+
# title: "Sample 1 announcement"
19+
# # title is optional
20+
# message: |
21+
# Message *one*.
22+
# [Hyperlink](https://en.wikipedia.org/wiki/Hyperlink).
23+
# # message is required. You can use Markdown.
24+
# - name: Sample 2
25+
# startTime: 2020-01-01T00:00:00
26+
# endTime: 2021-04-01T00:00:00
27+
# message: |
28+
# Message *two*.
29+
30+
# leave the "announcements" key in place
31+
announcements:

layouts/partials/announcement.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
{{ if .Page.Param "announcement" }}
2-
<section lang="en" id="announcement" style="background-color:{{ .Page.Param "announcement_bg" }}">
3-
<aside>
4-
<div class="content announcement main-section" data-nosnippet>
5-
6-
<h4 class="announcement">
7-
{{ T "announcement_title" | markdownify }}
8-
</h4>
9-
<p class="announcement">{{ T "announcement_message" | markdownify }}</p>
10-
11-
</div>
12-
</aside>
13-
</section>
1+
{{ $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])$" }}
2+
{{ $announcementShown := false }}
3+
{{ range $.Site.Data.announcements }}
4+
{{ range .announcements }}
5+
{{ if or ( eq .endTime nil ) ( eq .message nil ) }}
6+
{{ errorf "Invalid announcement: %#v" . }}
7+
{{ end }}
8+
{{ if and (ne .startTime nil ) (lt ( len ( findRE $dateRegExp .startTime ) ) 1 ) }}
9+
{{ errorf "Invalid announcement start time: %#v" .startTime }}
10+
{{ end }}
11+
{{ if lt ( len ( findRE $dateRegExp .endTime ) ) 1 }}
12+
{{ errorf "Invalid announcement end time: %#v" .endTime }}
13+
{{ end }}
14+
{{ if or (eq .startTime nil ) (lt ( time .startTime ) now ) }}
15+
{{- if or (eq .endTime nil ) (gt ( time .endTime ) now ) -}}
16+
{{- if not $announcementShown -}}
17+
{{- $announcementShown = true -}}
18+
<section lang="en" id="announcement" style="background-color: #3371e3; color: #fff; {{ .style | safeCSS }}">
19+
<aside>
20+
<div class="content announcement main-section" data-nosnippet>
21+
{{ if .title }}
22+
<h4 class="announcement">
23+
{{ .title | markdownify }}
24+
</h4>
25+
{{ end }}
26+
<p class="announcement">{{ .message | markdownify }}</p>
27+
</div>
28+
</aside>
29+
</section>
30+
{{- end -}}
31+
{{- end -}}
32+
{{- end -}}
33+
{{ end }}
1434
{{ end }}
Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
{{ if .Page.Param "announcement" }}
2-
<section lang="en" id="fp-announcement" style="background-color:{{ .Page.Param "announcement_bg" }}">
3-
<aside >
4-
<div class="content announcement main-section" data-nosnippet>
5-
6-
<h3>
7-
{{ T "announcement_title" | markdownify }}
8-
</h3>
9-
<p>{{ T "announcement_message" | markdownify }}</p>
10-
11-
</div>
12-
</aside>
13-
</section>
1+
{{ $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])$" }}
2+
{{ $announcementShown := false }}
3+
{{ range $.Site.Data.announcements }}
4+
{{ range .announcements }}
5+
{{ if or ( eq .endTime nil ) ( eq .message nil ) }}
6+
{{ errorf "Invalid announcement: %#v" . }}
7+
{{ end }}
8+
{{ if and (ne .startTime nil ) (lt ( len ( findRE $dateRegExp .startTime ) ) 1 ) }}
9+
{{ errorf "Invalid announcement start time: %#v" .startTime }}
10+
{{ end }}
11+
{{ if lt ( len ( findRE $dateRegExp .endTime ) ) 1 }}
12+
{{ errorf "Invalid announcement end time: %#v" .endTime }}
13+
{{ end }}
14+
{{ if or (eq .startTime nil ) (lt ( time .startTime ) now ) }}
15+
{{- if or (eq .endTime nil ) (gt ( time .endTime ) now ) -}}
16+
{{- if not $announcementShown -}}
17+
{{- $announcementShown = true -}}
18+
<section lang="en" id="fp-announcement" style="background-color: #3371e3; color: #fff; {{ .style | safeCSS }}">
19+
<aside>
20+
<div class="content announcement main-section" data-nosnippet>
21+
{{ if .title }}
22+
<h4 class="announcement">
23+
{{ .title | markdownify }}
24+
</h4>
25+
{{ end }}
26+
<p class="announcement">{{ .message | markdownify }}</p>
27+
</div>
28+
</aside>
29+
</section>
30+
{{- end -}}
31+
{{- end -}}
32+
{{- end -}}
33+
{{ end }}
1434
{{ end }}

0 commit comments

Comments
 (0)