Skip to content

Commit 71e96f0

Browse files
committed
fix(calendar): remove hardcoded api key and inject via env var
- Removes the hardcoded Google Calendar API key from JS. - Injects the key via 'GOOGLE_CALENDAR_API_KEY' environment variable. - Adds a fallback to 'site.Params.google_calendar_api_key' in hugo.yaml. - Sets a default 'PLACEHOLDER_VALUE' in hugo.yaml. - Implements graceful degradation: if the key is missing or is the placeholder, the calendar displays a 'not available' message instead of crashing. Closes #45
1 parent 2101398 commit 71e96f0

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

hugo.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ frontmatter:
6666

6767
# Everything below this are Site Params
6868
params:
69+
google_calendar_api_key: 'PLACEHOLDER_VALUE'
6970
# This is used instead of the built-in top level `copyright` to utilize
7071
# Docsy's partial which adds the copyright year automatically
7172
copyright: The Kubernetes Authors

layouts/calendar/baseof.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<script src='{{ .Site.BaseURL }}/js/fullcalendar/main.min.js'></script>
77
<script src='{{ .Site.BaseURL }}/js/calendar.js'></script>
88
<script>
9-
renderCalendar();
9+
{{ $apiKey := getenv "GOOGLE_CALENDAR_API_KEY" | default .Site.Params.google_calendar_api_key | default "" }}
10+
renderCalendar('{{ $apiKey }}');
1011
</script>
1112
</head>
1213
<body class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}">

static/js/calendar.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ function openEvent(event) {
44
return false;
55
};
66

7-
function renderCalendar() {
7+
function renderCalendar(apiKey) {
88
document.addEventListener('DOMContentLoaded', function() {
99
var calendarEl = document.getElementById('calendar');
10+
11+
if (!apiKey || apiKey === 'PLACEHOLDER_VALUE') {
12+
console.warn('Google Calendar API key is missing. Calendar will not render.');
13+
calendarEl.innerHTML = '<div style="padding: 20px; border: 1px solid #ccc; background: #f9f9f9; text-align: center;">Community Calendar is not available in this environment (missing API Key).</div>';
14+
return;
15+
}
16+
1017
var calendar = new FullCalendar.Calendar(calendarEl, {
11-
googleCalendarApiKey: 'AIzaSyDn_UhFPLDgxouI5nc8hOULFY25EjwGR44',
18+
googleCalendarApiKey: apiKey,
1219
events: {
1320
googleCalendarId: 'calendar@kubernetes.io'
1421
},

0 commit comments

Comments
 (0)