Skip to content

Commit

Permalink
lint: metadata parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
roipoussiere committed Jun 5, 2023
1 parent 37f019b commit d41fb9d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion website/src/pages/learn/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions website/src/pages/learn/metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/metadata_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/swatch/list.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
);
}

Expand Down

0 comments on commit d41fb9d

Please sign in to comment.