Repository navigation
Expand file tree
/
Copy pathlanguage-navigation.js
More file actions
66 lines (59 loc) · 2.17 KB
/
Copy pathlanguage-navigation.js
File metadata and controls
66 lines (59 loc) · 2.17 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
(function (root, factory) {
const api = factory();
if (typeof module === 'object' && module.exports) {
module.exports = api;
}
root.WorkshopLanguageNavigation = api;
}(typeof globalThis !== 'undefined' ? globalThis : this, function () {
'use strict';
function resolveLanguage(search, storedLanguageId, getLanguage) {
const parameters = new URLSearchParams(search);
if (parameters.has('lang')) {
return getLanguage(parameters.get('lang'));
}
return getLanguage(storedLanguageId);
}
function resolveLocale(search, storedLocaleId, getLocale) {
const parameters = new URLSearchParams(search);
if (parameters.has('locale')) {
return getLocale(parameters.get('locale'));
}
return getLocale(storedLocaleId);
}
function lessonUrl(stepId, languageId, localeId) {
const parameters = new URLSearchParams({ step: stepId });
if (languageId) {
parameters.set('lang', languageId);
}
if (localeId) {
parameters.set('locale', localeId);
}
return `?${parameters.toString()}`;
}
function homeUrl(languageId, workshopId, localeId) {
const parameters = new URLSearchParams();
if (languageId) {
parameters.set('lang', languageId);
}
if (workshopId) {
parameters.set('workshop', workshopId);
}
if (localeId) {
parameters.set('locale', localeId);
}
const query = parameters.toString();
return query ? `../index.html?${query}` : '../index.html';
}
function firstLessonUrl(languageId, workshopId = 'sdlc', localeId) {
const firstStep = workshopId === 'intro'
? 'intro-00-preflight'
: workshopId === 'museum'
? 'museum-00-preflight'
: '00-preflight';
return `workshop/step.html${lessonUrl(firstStep, languageId, localeId)}`;
}
function siteRootUrl(lessonPageUrl) {
return new URL('../', lessonPageUrl);
}
return Object.freeze({ resolveLanguage, resolveLocale, lessonUrl, homeUrl, firstLessonUrl, siteRootUrl });
}));