Backend for songs.zachdecook.com
gemini: show chords based on transposition
| -rw-r--r-- | laravel/app/Song.php | 5 | ||||
| -rwxr-xr-x | laravel/public/song.gmi.php | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 102a0ca..46472c4 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -36,9 +36,10 @@ class Song extends Model // TODO: Validate that this is plain. return trim($this->key, "m"); } - public function getChordsAttribute() + public function getChordsAttribute($txt = null) { - $txt = str_replace(['(',')',"\n"]," ",$this->text); + $txt = $txt ?? $this->text; + $txt = str_replace(['(',')',"\n", "\r"]," ",$txt); $words = array_flip(explode(' ', $txt)); $allChords = json_decode(file_get_contents("public/js/chordsdata/chords.json"), TRUE); $chords = array_intersect_key($allChords, $words); diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php index 2535ca2..edf9b2a 100755 --- a/laravel/public/song.gmi.php +++ b/laravel/public/song.gmi.php @@ -25,12 +25,12 @@ printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return; => <?= $song->id ?>?q Transpose from <?= $song->plain_key ?> -``` -<?= $song->textTranspose(getenv('QUERY_STRING')??'') ?> +```chord sheet +<?= $txt = $song->textTranspose(getenv('QUERY_STRING')??'') ?> ``` -<?php foreach($song->chords as $symbol => $tabs): ?> -=> /chord.svg/<?=$symbol?>?<?=$tabs[0]?> <?= $symbol ?> chord symbol +<?php foreach($song->getChordsAttribute($txt) as $symbol => $tabs): ?> +=> /chord.svg/<?=$symbol?>?<?=$tabs[0]?> <?= $symbol ?> (<?=$tabs[0]?>) <?php endforeach; ?> => mailto:zachdecook+songs@gmail.com?subject=<?= |