Structuring a `lyrics` field in Sanity Studio for proper display
14 replies
Last updated: Mar 4, 2023
K
I’m trying to make a new document to appear in Sanity Studio, which is
I can’t use blockContent, because it will include a big space between each line (since newline indicates paragraph). Ideally, I can end up with an easy way to add lyrics like this in the Sanity Studio editor, without having to manually click
song. The
songdocument has a
lyricsfield. I’m trying to think of the best way to structure this field so that it displays lyrics properly, a la:
Thunderbolts and lightning, very, very frightening me Galileo, Galileo Galileo, Galileo Galileo, Figaro - magnificoo I'm just a poor boy nobody loves me He's just a poor boy from a poor family, Spare him his life from this monstrosity Easy come, easy go, will you let me go
+each time to add a new “lyric line” so that the formatting stays proper. Are there any guidelines on how to structure poetry/lyrics?
Mar 4, 2023, 2:53 PM
D
user T
why not make it an array of blocks? then you have each paragraph in a new block?Mar 4, 2023, 2:57 PM
K
My current thought was to do something like this:
Then define a `lyricsBlock`:
And finally, define a
But this solution leads to the aforementioned problem, where I need to manually click
export default { name: 'song', title: 'Song', type: 'document', fields: [ { name: 'title', title: 'Title', type: 'string', }, { name: 'lyrics', title: 'Lyrics', type: 'lyricsBlock', }, ], }
export default { type: 'object', name: 'lyricsBlock', title: 'Lyrics Block', fields: [ { type: 'array', name: 'lyrics', of: [{ type: 'lyrics' }], validation: (Rule) => Rule.required(), }, ], }
lyrics, which would be each line:
export default { type: 'object', name: 'lyrics', title: 'Lyrics', fields: [ { type: 'text', title: 'Text', name: 'text', validation: (Rule) => Rule.required(), }, ], }
+to add a new line
Mar 4, 2023, 2:57 PM
K
user R
I tried that, but there was no new line between each line of the lyrics. All the text got put on the same lineMar 4, 2023, 2:58 PM
D
I think im missing you, by “new line” do you mean at the “end” of
very, very frightning me?
Mar 4, 2023, 2:59 PM
D
then having the
Galileoon a new line
Mar 4, 2023, 3:00 PM
K
yes exactly
Mar 4, 2023, 3:00 PM
K
Thunderbolts and lightning, very, very frightening me Galileo, Galileo
Mar 4, 2023, 3:00 PM
D
Ahhh 💡 , what about using
\n?
Mar 4, 2023, 3:00 PM
K
Let me try
Mar 4, 2023, 3:01 PM
R
have you tried hitting
command+returninstead of a regular return in the block editor? that renders a hard line break aka
\n
Mar 4, 2023, 3:40 PM
R
here’s a possibly related issue https://github.com/nuxt-modules/sanity/issues/61
Mar 4, 2023, 3:42 PM
K
command+return just toggles the editor to be large/small
Mar 4, 2023, 4:32 PM
R
sorry, i think shift+enter/return is what i meant!
Mar 4, 2023, 4:33 PM
K
let me try! Will have to get back to this a little later. thanks for the suggestions 🙂
Mar 4, 2023, 4:34 PM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.