summaryrefslogtreecommitdiff
path: root/layouts/_default/baseof.html
blob: bdb4b0390725d77dbf6ce508c76fb18a8e79ea2b (plain)
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
<!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();

  document.addEventListener("DOMContentLoaded", () => {
  const setlistTab = document.getElementById("setlist-tab");
  const setlistSidebar = document.getElementById("setlist-sidebar");
  const setlistEl = document.getElementById("setlist");
  const addButton = document.getElementById("add-to-setlist");

  // Load setlist from localStorage
  let setlist = JSON.parse(localStorage.getItem("setlist")) || [];

  function saveSetlist() {
    localStorage.setItem("setlist", JSON.stringify(setlist));
  }

  function renderSetlist() {
  setlistEl.innerHTML = "";
  setlist.forEach((song) => {
    const li = document.createElement("li");

    const link = document.createElement("a");
    link.href = song.url;
    link.textContent = song.title;
    link.style.flex = "1";

    const key = document.createElement("span");
    key.textContent = `[${song.key}] `;
    key.style.marginLeft = "6px";
    key.style.color = "#555";

    const removeBtn = document.createElement("button");
    removeBtn.textContent = "−";
    removeBtn.addEventListener("click", () => {
      setlist = setlist.filter((s) => s.url !== song.url);
      saveSetlist();
      renderSetlist();
    });

    li.appendChild(key);
    li.appendChild(link);
    li.appendChild(removeBtn);
    setlistEl.appendChild(li);
  });
}

  // Toggle sidebar
  setlistTab.addEventListener("click", () => {
    setlistSidebar.classList.toggle("hidden");
  });

  // Add current song
  addButton.addEventListener("click", () => {
  const title = document.title.split(" | ")[0]; // Adjust to your site's title format
  const url = window.location.href;
  const keySelector = document.getElementById("key-selector");
  const transposedKey = keySelector?.value || "C";

  const exists = setlist.some((s) => s.url === url);
  if (!exists) {
    // Add ?key=E or &key=E if query already exists
    const urlObj = new URL(url);
    urlObj.searchParams.set("key", transposedKey);
    setlist.push({ title, url: urlObj.toString(), key: transposedKey });
    saveSetlist();
    renderSetlist();
  }
});

  renderSetlist();
});
  

</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';

// Read override from URL query
const urlParams = new URLSearchParams(window.location.search);
const selectedKey = urlParams.get('key') || selector?.value || originalKey;

// Set selector to match the query key (if present)
if (selector && selectedKey) {
  selector.value = selectedKey;
}

  // 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");

  if (!toggle) return;

  // ✅ Restore saved state
  const savedState = localStorage.getItem("chords-toggle");
  if (savedState !== null) {
    const isChecked = savedState === "true";
    toggle.checked = isChecked;
    document.body.classList.toggle("hide-chords", !isChecked);
  }

  // ✅ Save on change
  toggle.addEventListener("change", () => {
    localStorage.setItem("chords-toggle", toggle.checked);
    document.body.classList.toggle("hide-chords", !toggle.checked);
  });
});
</script>
{{ end }}


</html>