0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

Move Snippets store to metadata block.

Note this still stores the snippets as a string for the passed about brew object.
This commit is contained in:
David Bolack
2025-04-07 23:22:47 -05:00
parent 8e8f520eaa
commit d0c3765f8f
2 changed files with 2 additions and 11 deletions

View File

@@ -170,12 +170,6 @@ const api = {
mergeBrewText : (brew)=>{
let text = brew.text;
if(brew.snippets !== undefined) {
text = `\`\`\`snippets\n` +
`${yaml.dump(brewSnippetsToJSON('brew_snippets', brew.snippets, null, false))}` +
`\`\`\`\n\n` +
`${text}`;
}
if(brew.style !== undefined) {
text = `\`\`\`css\n` +
`${brew.style || ''}\n` +
@@ -183,6 +177,7 @@ const api = {
`${text}`;
}
const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']);
metadata.snippets = brewSnippetsToJSON('brew_snippets', brew.snippets, null, false);
text = `\`\`\`metadata\n` +
`${yaml.dump(metadata)}\n` +
`\`\`\`\n\n` +

View File

@@ -91,6 +91,7 @@ const splitTextStyleAndMetadata = (brew)=>{
const metadataSection = brew.text.slice(11, index + 1);
const metadata = yaml.load(metadataSection);
Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang']));
brew.snippets = yamlSnippetsToText(_.pick(metadata, ['snippets']).snippets);
brew.text = brew.text.slice(index + 6);
}
if(brew.text.startsWith('```css')) {
@@ -98,11 +99,6 @@ const splitTextStyleAndMetadata = (brew)=>{
brew.style = brew.text.slice(7, index + 1);
brew.text = brew.text.slice(index + 6);
}
if(brew.text.startsWith('```snippets')) {
const index = brew.text.indexOf('\n```\n\n');
brew.snippets = yamlSnippetsToText(yaml.load(brew.text.slice(11, index + 1))).slice(0, -1);
brew.text = brew.text.slice(index + 6);
}
// Handle old brews that still have empty strings in the tags metadata
if(typeof brew.tags === 'string') brew.tags = brew.tags ? [brew.tags] : [];