diff --git a/.circleci/config.yml b/.circleci/config.yml index f18f84943..abd8faacc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ orbs: jobs: build: docker: - - image: cimg/node:20.17.0 + - image: cimg/node:20.18.0 - image: mongo:4.4 working_directory: ~/homebrewery diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 50237b914..1f786fd93 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -6,6 +6,7 @@ const _ = require('lodash'); const cx = require('classnames'); import { loadHistory } from '../../utils/versionHistory.js'; +import { brewSnippetsToJSON } from '../../../../shared/helpers.js'; //Import all themes const ThemeSnippets = {}; @@ -114,6 +115,9 @@ const Snippetbar = createClass({ oldSnippets = _.keyBy(compiledSnippets, 'groupName'); } + const userSnippetsasJSON = brewSnippetsToJSON(this.props.brew.title, this.props.brew.snippets, this.props.snippetsBundle); + compiledSnippets.push(userSnippetsasJSON); + return compiledSnippets; }, diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index 744e187a6..a98b16717 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -61,6 +61,7 @@ const EditPage = createClass({ currentEditorCursorPageNum : 1, currentBrewRendererPageNum : 1, displayLockMessage : this.props.brew.lock || false, + snippetsBundle : {}, themeBundle : {} }; }, @@ -440,6 +441,7 @@ const EditPage = createClass({ reportError={this.errorReported} renderer={this.state.brew.renderer} userThemes={this.props.userThemes} + snippets={this.props.snippets} snippetBundle={this.state.themeBundle.snippets} updateBrew={this.updateBrew} onCursorPageChange={this.handleEditorCursorPageChange} diff --git a/package.json b/package.json index 94d0122ab..3fe3ce5a6 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "description": "Create authentic looking D&D homebrews using only markdown", "version": "3.16.0", "engines": { - "npm": "^10.2.x", - "node": "^20.17.x" + "npm": "^10.8.x", + "node": "^20.18.x" }, "repository": { "type": "git", diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 213b341ca..2abbf9485 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -170,6 +170,12 @@ const api = { `\`\`\`\n\n` + `${text}`; } + if(brew.snippets !== undefined) { + text = `\`\`\`snippets\n` + + `${brew.snippets || ''}\n` + + `\`\`\`\n\n` + + `${text}`; + } const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']); text = `\`\`\`metadata\n` + `${yaml.dump(metadata)}\n` + diff --git a/shared/helpers.js b/shared/helpers.js index ac684b06f..e75dcdb28 100644 --- a/shared/helpers.js +++ b/shared/helpers.js @@ -1,6 +1,65 @@ const _ = require('lodash'); const yaml = require('js-yaml'); const request = require('../client/homebrew/utils/request-middleware.js'); +const dedent = require('dedent'); + +// Convert the templates from a brew to a Snippets Structure. +const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets)=>{ + const textSplit = /^\\page/gm; + const mpAsSnippets = []; + // Snippets from Themes first. + if(themeBundleSnippets) { + for (let themes of themeBundleSnippets) { + const userSnippets = []; + for (let snips of themes.snippets.split(textSplit)) { + const name = snips.split('\n')[0]; + if(name.length != 0) { + userSnippets.push({ + name : name, + icon : '', + gen : snips.split('\n').slice(0), + }); + } + } + if(userSnippets.length > 0) { + mpAsSnippets.push({ + name : themes.name, + icon : '', + gen : '', + subsnippets : userSnippets + }); + } + } + } + // Local Snippets + if(userBrewSnippets) { + const userSnippets = []; + for (let snips of userBrewSnippets.split(textSplit)) { + let name = mp.split('\n')[0]; + if(name.length != 0) { + userSnippets.push({ + name : name, + icon : '', + gen : snips.split('\n').slice(0), + }); + } + } + if(userSnippets.length) { + mpAsSnippets.push({ + name : menuTitle, + icon : '', + subsnippets : userSnippets + }); + } + } + + return { + groupName : 'Brew Snippets', + icon : 'fas fa-th-list', + view : 'text', + snippets : mpAsSnippets + }; +}; const splitTextStyleAndMetadata = (brew)=>{ brew.text = brew.text.replaceAll('\r\n', '\n'); @@ -55,4 +114,5 @@ module.exports = { splitTextStyleAndMetadata, printCurrentBrew, fetchThemeBundle, + brewSnippetsToJSON };