lint: metadata parsing

This commit is contained in:
Roipoussiere 2023-06-05 21:15:59 +02:00
parent 372e33c066
commit 98a89aea11
4 changed files with 5 additions and 4 deletions

View File

@ -68,7 +68,7 @@ Try uncommenting this line by deleting `//` and refreshing the pattern.
You can also use the keyboard shortcut `cmd-/` to toggle comments on and off.
You might noticed that some comments in the REPL samples include some words starting with a "@", like `@title` or `@license`.
Those are just a convention to define some information about the music. We will talk about it in the *metadata* section.
Those are just a convention to define some information about the music. We will talk about it in the _metadata_ section.
# Strings

View File

@ -21,6 +21,7 @@ Like other comments, those are ignored by Strudel, but it can be used by other t
It is for instance used by the [swatch tool](https://github.com/tidalcycles/strudel/tree/main/my-patterns) to display pattern titles in the [examples page](https://strudel.tidalcycles.org/examples/).
Available tags are:
- `@title`: music title
- `@by`: music author(s), separated with comma, eventually followed with a link in `<>` (ex: `@author john doe <https://example.com>`)
- `@license`: music license

View File

@ -2,13 +2,13 @@ export function getMetadata(raw_code) {
// https://stackoverflow.com/a/15123777
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/gm;
const tag_regexp = /@([a-z]*):? (.*)/gm
const tag_regexp = /@([a-z]*):? (.*)/gm;
const tags = {};
for (const match of raw_code.matchAll(comment_regexp)) {
const comment = match[1] ? match[1] : '' + match[3] ? match[3] : '';
for (const tag_match of comment.trim().matchAll(tag_regexp)) {
tags[tag_match[1]] = tag_match[2].trim()
tags[tag_match[1]] = tag_match[2].trim();
}
}

View File

@ -5,7 +5,7 @@ export function getMyPatterns() {
return Object.fromEntries(
Object.entries(my)
.filter(([name]) => name.endsWith('.txt'))
.map(([name, raw]) => [ getMetadata(raw)['title'] || name.split('/').slice(-1), raw ]),
.map(([name, raw]) => [getMetadata(raw)['title'] || name.split('/').slice(-1), raw]),
);
}