metadata: add quotes syntax for titles
This commit is contained in:
parent
185318a70c
commit
51e8174689
5 changed files with 102 additions and 40 deletions
|
|
@ -2,10 +2,16 @@ const ALLOW_MANY = ['by', 'url', 'genre', 'license'];
|
|||
|
||||
export function getMetadata(raw_code) {
|
||||
const comment_regexp = /\/\*([\s\S]*?)\*\/|\/\/(.*)$/gm;
|
||||
const comments = [...raw_code.matchAll(comment_regexp)].map((c) => (c[1] || c[2] || '').trim());
|
||||
const tags = {};
|
||||
|
||||
for (const match of raw_code.matchAll(comment_regexp)) {
|
||||
const tag_matches = (match[1] || match[2] || '').trim().split('@').slice(1);
|
||||
const [prefix, title] = (comments[0] || '').split('"');
|
||||
if (prefix.trim() === '' && title !== undefined) {
|
||||
tags['title'] = title;
|
||||
}
|
||||
|
||||
for (const comment of comments) {
|
||||
const tag_matches = comment.split('@').slice(1);
|
||||
for (const tag_match of tag_matches) {
|
||||
let [tag, tag_value] = tag_match.split(/ (.*)/s);
|
||||
tag = tag.trim();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue