mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 13:38:40 +00:00
lint: metadata parsing
This commit is contained in:
parent
372e33c066
commit
98a89aea11
@ -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 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`.
|
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
|
# Strings
|
||||||
|
|
||||||
|
|||||||
@ -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/).
|
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:
|
Available tags are:
|
||||||
|
|
||||||
- `@title`: music title
|
- `@title`: music title
|
||||||
- `@by`: music author(s), separated with comma, eventually followed with a link in `<>` (ex: `@author john doe <https://example.com>`)
|
- `@by`: music author(s), separated with comma, eventually followed with a link in `<>` (ex: `@author john doe <https://example.com>`)
|
||||||
- `@license`: music license
|
- `@license`: music license
|
||||||
|
|||||||
@ -2,13 +2,13 @@ export function getMetadata(raw_code) {
|
|||||||
// https://stackoverflow.com/a/15123777
|
// https://stackoverflow.com/a/15123777
|
||||||
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/gm;
|
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/gm;
|
||||||
|
|
||||||
const tag_regexp = /@([a-z]*):? (.*)/gm
|
const tag_regexp = /@([a-z]*):? (.*)/gm;
|
||||||
const tags = {};
|
const tags = {};
|
||||||
|
|
||||||
for (const match of raw_code.matchAll(comment_regexp)) {
|
for (const match of raw_code.matchAll(comment_regexp)) {
|
||||||
const comment = match[1] ? match[1] : '' + match[3] ? match[3] : '';
|
const comment = match[1] ? match[1] : '' + match[3] ? match[3] : '';
|
||||||
for (const tag_match of comment.trim().matchAll(tag_regexp)) {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export function getMyPatterns() {
|
|||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(my)
|
Object.entries(my)
|
||||||
.filter(([name]) => name.endsWith('.txt'))
|
.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]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user