mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 20:18:34 +00:00
swatch: look for song titles in code metadata
This commit is contained in:
parent
11733d5e05
commit
3db1c7a521
@ -1,9 +1,26 @@
|
|||||||
|
export function getMetadata(raw_code) {
|
||||||
|
// https://stackoverflow.com/a/15123777
|
||||||
|
const comment_regexp = /\/\*([\s\S]*?)\*\/|([^\\:]|^)\/\/(.*)$/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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
export function getMyPatterns() {
|
export function getMyPatterns() {
|
||||||
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
|
const my = import.meta.glob('../../../../my-patterns/**', { as: 'raw', eager: true });
|
||||||
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]) => [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