Skip to content

Commit dd66a75

Browse files
committed
🔨 Use new utility for song txt export
1 parent fc88b7f commit dd66a75

1 file changed

Lines changed: 3 additions & 30 deletions

File tree

‎frontend/src/views/SongShow.vue‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276

277277
<script setup lang="ts">
278278
import { injectStrict, hkBackKey, hkChordsKey, hkDownKey, hkForwardKey, hkPresentKey, hkResetKey, hkUpKey, noActiveModalKey, setlistsKey, songsKey, userKey, versionKey } from '@/keys';
279-
import { keyScale, isChordLine, parsedContent, download, openLyricsXML, firstParam, isSlide } from '@/utils.js';
279+
import { keyScale, isChordLine, parsedContent, songPlainTextContent, download, openLyricsXML, firstParam, isSlide } from '@/utils.js';
280280
import type { SetlistSong } from '@backend/models';
281281
import { logicAnd, logicOr } from '@vueuse/math';
282282
import { notify } from '@kyvg/vue3-notification';
@@ -439,36 +439,9 @@ const songExists = computed(() => {
439439
const exportTxt = () => {
440440
const s = song.value;
441441
if (!s) return;
442-
// add header
443-
var content = s.title
444-
+ ' [' + keyScale[(12 + keyScale.indexOf(s.key ?? '') + (key.value % 12)) % 12] + ']'
445-
+ '\n\n';
446-
var lines = s.content.split(EOL);
447-
// process lines
448-
for (var i = 0; i < lines.length; i++) {
449-
var line = lines[i];
450-
// handle chord line
451-
if (!chords.value && isChordLine(line)) continue;
452-
// handle verse marker indentation
453-
if (line.trim().toLowerCase().indexOf('--v') >= 0 && !isNaN(parseInt(line.trim().charAt(3)))) {
454-
// if next line is chord line, prepend number to the line after
455-
if (isChordLine(lines[i+1])) {
456-
lines[i+2] = line.trim().charAt(3) + '. ' + lines[i+2];
457-
// add 3 spaces to next line to sync chords with text again
458-
lines[i+1] = ' ' + lines[i+1];
459-
} else {
460-
lines[i+1] = line.trim().charAt(3) + '. ' + lines[i+1];
461-
}
462-
}
463-
// handle marker
464-
if (line.trim().indexOf('--') >= 0) continue;
465-
// keep line for export
466-
content += line + EOL;
467-
}
468-
content += EOL + s.authors?.join(', ') + EOL + EOL
469-
+ '© ' + (s.year ? s.year + ' ' : '') + s.publisher.replace(/(?:\r\n|\r|\n)/g, '; ');
442+
const tuning = keyScale[(12 + keyScale.indexOf(s.key ?? '') + (key.value % 12)) % 12];
470443
// start download
471-
download(content, songId + '.txt');
444+
download(songPlainTextContent(s, tuning, chords.value), songId + '.txt');
472445
// toast success message
473446
notify({
474447
title: t('toast.exportedText'),

0 commit comments

Comments
 (0)