mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
Rework detection of user brews to look up themeid in static themes list before assuming is a user brew.
Ended up being a fairly straightforward change. A few ternaries got smooshed or inverted. Passes builtin and local tests. Need to compare on the test instance.
This commit is contained in:
@@ -89,13 +89,13 @@ const api = {
|
||||
|
||||
if(brews) {
|
||||
for await (const brew of brews) {
|
||||
userThemes.Brew[`#${brew.shareId}`] = {
|
||||
userThemes.Brew[brew.shareId] = {
|
||||
name : brew.title,
|
||||
renderer : 'V3',
|
||||
baseTheme : '',
|
||||
baseSnippets : false,
|
||||
author : brew.authors[0],
|
||||
path : `#${brew.shareId}`,
|
||||
path : brew.shareId,
|
||||
thumbnail : brew.thumbnail.length > 0 ? brew.thumbnail : '/assets/naturalCritLogoWhite.svg'
|
||||
};
|
||||
}
|
||||
@@ -285,7 +285,7 @@ const api = {
|
||||
const brew = req.brew;
|
||||
splitTextStyleAndMetadata(brew);
|
||||
res.setHeader('Content-Type', 'text/css');
|
||||
const themePath = req.brew.theme[0] != '#' ? `/css/${req.brew.renderer}/${req.brew.theme}` : `/css/${req.brew.theme.slice(1)}`;
|
||||
const themePath = themes[_.upperFirst(req.brew.renderer)].hasOwnProperty(req.brew.theme) ? `/css/${req.brew.renderer}/${req.brew.theme}` : `/css/${req.brew.theme}`;
|
||||
// Drop Parent theme if it has already been loaded.
|
||||
// This assumes the continued use of the V3/5ePHB and V3/Blank themes for the app.
|
||||
const parentThemeImport = ((req.brew.theme != '5ePHB') && (req.brew.theme != 'Blank')) ? `@import url(\"${themePath}\");\n\n`:'';
|
||||
@@ -296,7 +296,7 @@ const api = {
|
||||
const brew = req.brew;
|
||||
splitTextStyleAndMetadata(brew);
|
||||
res.setHeader('Content-Type', 'text/css');
|
||||
const themePath = req.brew.theme[0] != '#' ? `/css/${req.brew.renderer}/${req.brew.theme}` : `/css/${req.brew.theme.slice(1)}`;
|
||||
const themePath = themes[_.upperFirst(req.brew.renderer)].hasOwnProperty(req.brew.theme) ? `/css/${req.brew.renderer}/${req.brew.theme}` : `/css/${req.brew.theme}`;
|
||||
const parentThemeImport = `@import url(\"${themePath}\");\n\n`;
|
||||
const themeLocationComment = `/* From Brew: ${req.protocol}://${req.get('host')}/share/${req.brew.shareId} */\n\n`;
|
||||
return res.status(200).send(req.brew.renderer == 'legacy' ? '' : `${parentThemeImport}${themeLocationComment}`);
|
||||
|
||||
@@ -604,7 +604,7 @@ brew`);
|
||||
describe('getBrewThemeWithUserParent', ()=>{
|
||||
it('should collect parent theme and brew style - returning as css with user-theme parent imported.', async ()=>{
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', shareId: 'iAmAUserTheme', theme: '#IamATheme', style: 'I Have a style!' }));
|
||||
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', shareId: 'iAmAUserTheme', theme: 'IamATheme', style: 'I Have a style!' }));
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {}, get: ()=>{return 'localhost';}, protocol: 'https' };
|
||||
const next = jest.fn();
|
||||
|
||||
Reference in New Issue
Block a user