diff options
| author | Zach DeCook <zachdecook@librem.one> | 2021-02-12 00:15:24 +0000 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2021-02-12 00:15:24 +0000 |
| commit | 085b53b12866de6c095553bf2809641994e2d4cb (patch) | |
| tree | 086074197f3ef7ea00b886a1f287accec428f838 /laravel | |
| parent | fa5a84e2b82d9295466b9587eb791bdf00de9e08 (diff) | |
| download | prosongsa-085b53b12866de6c095553bf2809641994e2d4cb.tar.gz | |
gemini: show chords based on transposition
Diffstat (limited to 'laravel')
| -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=<?= |
