Repository navigation
Expand file tree
/
Copy pathhomepage.js
More file actions
286 lines (255 loc) · 11 KB
/
Copy pathhomepage.js
File metadata and controls
286 lines (255 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
(function () {
'use strict';
const storageKey = 'copilot-sdk-workshop.language';
const localeStorageKey = 'copilot-sdk-workshop.locale';
const sdkDocsUrl = 'https://github.com/github/copilot-sdk';
const picker = document.getElementById('languagePicker');
const localeSelector = document.getElementById('localeSelector');
const languageSelector = document.getElementById('languageSelector');
const languageInputs = [...document.querySelectorAll('input[name="language"]')];
const startLink = document.getElementById('startWorkshopLink');
const docsLink = document.getElementById('sdkDocsLink');
const docsLabel = document.getElementById('sdkDocsLabel');
const summary = document.getElementById('languageSummary');
const installCommand = document.getElementById('installCommand');
const runtimeNote = document.getElementById('runtimeNote');
const workshopInputs = [...document.querySelectorAll('input[name="workshop"]')];
const targetAppLink = document.getElementById('targetAppLink');
const previewTitle = document.getElementById('previewTitle');
const preview = document.getElementById('workshopPreview');
const startGuidance = document.getElementById('startGuidance');
let selectedWorkshopId = null;
const workshops = {
intro: {
name: 'SDK 101',
previewTitle: 'start-intro',
preview: `Client → streaming hello world
→ select a podcast episode
→ approve an RSS tool
→ headline and launch post
[tool] get_github_podcast_episode
30 minutes · six languages
Complete setup before the session.`,
guidance: 'Learn SDK basics in 30 minutes. Install, authenticate, and download starter dependencies beforehand.'
},
sdlc: {
name: 'Accessibility reviewer',
previewTitle: 'accessibility-reviewer',
preview: `URL → Playwright inspection
→ WCAG lookup
→ structured report
[tool] playwright-browser_navigate
[tool] accessibility_rule_lookup
Finding
The name input has no accessible name.`,
guidance: 'Build an SDLC developer tool in a 115-minute workshop, then celebrate and keep building.'
},
museum: {
name: 'Museum Exhibit Studio',
previewTitle: 'museum-exhibit-studio',
preview: `Approved facts → curator session
→ exhibit validation
→ visitor-ready copy
Available tools: []
System message: replace
# Journey to the Moon
## Narrative
## Visitor questions`,
guidance: 'Build a non-SDLC curator tool in a 90-minute workshop, then celebrate and keep building.'
}
};
function getUi() {
return getSelectedLocale().ui;
}
function getWorkshopText(workshopId) {
return getUi().workshops[workshopId] ?? workshops[workshopId];
}
function getText(ui, key) {
return key.split('.').reduce((value, part) => value?.[part], ui);
}
function applyLocale(locale) {
const ui = locale.ui;
document.title = ui.title;
document.querySelectorAll('[data-i18n]').forEach(element => {
const value = getText(ui, element.dataset.i18n);
if (value !== undefined) element.textContent = value;
});
document.querySelectorAll('[data-i18n-attr]').forEach(element => {
const value = getText(ui, element.dataset.i18nAttr);
if (value !== undefined) {
element.setAttribute(
element.dataset.i18nAttr === 'description' ? 'content' : 'aria-label', value);
}
});
document.documentElement.lang = locale.htmlLang;
}
function getStoredLanguageId() {
try {
return window.localStorage.getItem(storageKey);
} catch (error) {
return null;
}
}
function storeLanguageId(languageId) {
try {
window.localStorage.setItem(storageKey, languageId);
} catch (error) {
// Local storage can be unavailable in private browsing contexts.
}
}
function getStoredLocaleId() {
try {
return window.localStorage.getItem(localeStorageKey);
} catch (error) {
return null;
}
}
function storeLocaleId(localeId) {
try {
window.localStorage.setItem(localeStorageKey, localeId);
} catch (error) {
// Local storage can be unavailable in private browsing contexts.
}
}
function getSelectedLocale() {
return WorkshopLocales.getLocale(localeSelector.value) ?? WorkshopLocales.defaultLocale;
}
function updateSelection(languageId) {
const language = WorkshopLanguages.getLanguage(languageId);
const hasLanguage = language !== null;
const workshop = selectedWorkshopId ? getWorkshopText(selectedWorkshopId) : null;
const ui = getUi();
const ready = workshop !== null && hasLanguage;
picker.disabled = workshop === null;
document.querySelectorAll('.language-option').forEach(option => {
option.classList.toggle('selected', option.dataset.language === language?.id);
});
startLink.classList.toggle('disabled', !ready);
startLink.setAttribute('aria-disabled', String(!ready));
startLink.href = ready
? WorkshopLanguageNavigation.firstLessonUrl(
language.id, selectedWorkshopId, WorkshopLocales.queryId(getSelectedLocale().id))
: workshop ? '#language-picker' : '#workshop-picker';
startLink.textContent = ready
? ui.startNamed.replace('{name}', workshop.shortName)
: ui.startSelected;
targetAppLink.hidden = selectedWorkshopId !== 'sdlc';
if (!hasLanguage) {
docsLink.href = sdkDocsUrl;
docsLabel.textContent = ui.sdkDocs;
summary.textContent = workshop
? ui.chooseLanguageFor.replace('{name}', workshop.name)
: ui.languageSummary;
installCommand.textContent = '';
runtimeNote.textContent = '';
startGuidance.textContent = workshop?.guidance ??
ui.startGuidance;
return;
}
docsLink.href = language.docsUrl;
docsLabel.textContent = ui.sdkDocsNamed.replace('{language}', language.displayName);
summary.textContent = workshop
? ui.workshopUsesLanguage
.replace('{name}', workshop.name)
.replace('{language}', language.displayName)
: ui.chooseWorkshopContinue;
installCommand.textContent = selectedWorkshopId === 'intro'
? 'git clone https://github.com/github/copilot-sdk-workshop.git'
: language.installCommand;
runtimeNote.textContent = selectedWorkshopId === 'intro'
? ui.introRuntimeNote.replace('{language}', language.id)
: ui.runtimeNotes[language.id];
startGuidance.textContent = workshop?.guidance ?? ui.chooseWorkshopContinue;
}
function selectWorkshop(workshopId) {
selectedWorkshopId = workshops[workshopId] ? workshopId : null;
document.querySelectorAll('.workshop-option').forEach(option => {
option.classList.toggle('selected', option.dataset.workshop === selectedWorkshopId);
});
const workshop = selectedWorkshopId ? getWorkshopText(selectedWorkshopId) : null;
const ui = getUi();
previewTitle.textContent = workshop?.previewTitle ?? ui.previewEmptyTitle;
preview.textContent = workshop?.preview ?? ui.previewEmpty;
updateSelection(languageInputs.find(input => input.checked)?.value ?? null);
if (workshop) {
languageInputs[0].focus();
}
}
WorkshopLocales.locales.forEach(locale => {
const option = document.createElement('option');
option.value = locale.id;
option.textContent = locale.displayName;
localeSelector.append(option);
});
const initialLocale = WorkshopLanguageNavigation.resolveLocale(
window.location.search,
getStoredLocaleId(),
WorkshopLocales.getLocale
) ?? WorkshopLocales.defaultLocale;
localeSelector.value = initialLocale.id;
applyLocale(initialLocale);
localeSelector.addEventListener('change', () => {
const locale = getSelectedLocale();
storeLocaleId(locale.id);
const url = new URL(window.location.href);
const localeQueryId = WorkshopLocales.queryId(locale.id);
if (localeQueryId) url.searchParams.set('locale', localeQueryId);
else url.searchParams.delete('locale');
window.history.replaceState({}, '', url.href);
applyLocale(locale);
const workshop = selectedWorkshopId ? getWorkshopText(selectedWorkshopId) : null;
previewTitle.textContent = workshop?.previewTitle ?? locale.ui.previewEmptyTitle;
preview.textContent = workshop?.preview ?? locale.ui.previewEmpty;
updateSelection(languageInputs.find(input => input.checked)?.value ?? null);
});
// The picker and the settings menu choose the same language, so each mirrors the other.
function chooseLanguage(languageId) {
const language = WorkshopLanguages.getLanguage(languageId);
if (!language) {
return;
}
languageInputs.forEach(input => {
input.checked = input.value === language.id;
});
languageSelector.value = language.id;
storeLanguageId(language.id);
updateSelection(language.id);
}
languageInputs.forEach(input => {
input.addEventListener('change', () => chooseLanguage(input.value));
});
languageSelector.addEventListener('change', () => chooseLanguage(languageSelector.value));
workshopInputs.forEach(input => {
input.addEventListener('change', () => selectWorkshop(input.value));
});
startLink.addEventListener('click', event => {
if (startLink.getAttribute('aria-disabled') === 'true') {
event.preventDefault();
if (!selectedWorkshopId) {
workshopInputs[0].focus();
} else {
languageInputs[0].focus();
languageInputs[0].reportValidity();
}
}
});
const initialLanguage = WorkshopLanguageNavigation.resolveLanguage(
window.location.search,
getStoredLanguageId(),
WorkshopLanguages.getLanguage
);
if (initialLanguage) {
const matchingLanguage = languageInputs.find(input => input.value === initialLanguage.id);
matchingLanguage.checked = true;
storeLanguageId(initialLanguage.id);
}
languageSelector.value = initialLanguage?.id ?? '';
const requestedWorkshop = new URLSearchParams(window.location.search).get('workshop');
const matchingWorkshop = workshopInputs.find(input => input.value === requestedWorkshop);
if (matchingWorkshop) {
matchingWorkshop.checked = true;
selectWorkshop(matchingWorkshop.value);
} else {
updateSelection(initialLanguage?.id ?? null);
}
}());