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
|
<!DOCTYPE html>
<html lang="{{ or site.Language.LanguageCode site.Language.Lang }}"
dir="{{ or site.Language.LanguageDirection `ltr` }}">
<head>
{{ partial "head.html" . }}
</head>
{{ $theme := "auto"}}
{{ with .Param "theme" }}
{{ $theme = .}}
{{ end }}
<body class="{{ $theme }}">
<div class="content">
<header>
<h1 class="center">
<a class="hover-underline" href="/">{{ .Site.Title }}</a>
</h1>
<hr>
</header>
<main class="main">
{{ block "main" . }}{{ end }}
</main>
</div>
</body>
<script>
function isAuto() {
return document.body.classList.contains("auto");
}
function setTheme() {
if (!isAuto()) {
return
}
document.body.classList.remove("auto");
let cls = "light";
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
cls = "dark";
}
document.body.classList.add(cls);
}
function invertBody() {
document.body.classList.toggle("dark");
document.body.classList.toggle("light");
}
if (isAuto()) {
window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody);
}
setTheme();
</script>
{{ if .HasShortcode "chords" }}
<script>
document.addEventListener("DOMContentLoaded", () => {
const semitones = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
const flatToSharp = { 'Db': 'C#', 'Eb': 'D#', 'Gb': 'F#', 'Ab': 'G#', 'Bb': 'A#' };
function normalize(note) {
return flatToSharp[note] || note;
}
function transposeNote(note, shift) {
note = normalize(note);
const i = semitones.indexOf(note);
return i === -1 ? note : semitones[(i + shift + 12) % 12];
}
function transposeChord(fullChord, shift) {
const match = fullChord.match(/^([A-G][#b]?)([^\/]*)(?:\/([A-G][#b]?))?$/);
if (!match) return fullChord;
let [, root, suffix, bass] = match;
const transposedRoot = transposeNote(root, shift);
const transposedBass = bass ? transposeNote(bass, shift) : null;
return transposedRoot + suffix + (transposedBass ? `/${transposedBass}` : '');
}
function renderChords() {
const pattern = /\[([A-G][#b]?[^ \[\]]*)\]/g;
document.querySelectorAll('.chord-line').forEach(line => {
line.innerHTML = line.innerHTML.replace(pattern, (_, chord) => {
return `<span class="chord-anchor"><span class="chord" data-original="${chord}">${chord}</span></span>`;
});
});
}
function transposeToKey(fromKey, toKey) {
const fromIndex = semitones.indexOf(normalize(fromKey));
const toIndex = semitones.indexOf(normalize(toKey));
const shift = fromIndex === -1 || toIndex === -1 ? 0 : (toIndex - fromIndex + 12) % 12;
document.querySelectorAll('.chord').forEach(el => {
const original = el.dataset.original;
el.textContent = transposeChord(original, shift);
});
}
// Init
renderChords();
const selector = document.getElementById('key-selector');
const originalKey = selector?.dataset.originalKey || 'C';
// Trigger initial transpose to match the default selected key
transposeToKey(originalKey, selector.value);
selector?.addEventListener("change", () => {
transposeToKey(originalKey, selector.value);
});
});
document.addEventListener("DOMContentLoaded", () => {
const toggle = document.getElementById("toggle-chords");
toggle?.addEventListener("change", () => {
document.body.classList.toggle("hide-chords", !toggle.checked);
});
});
</script>
{{ end }}
</html>
|