0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

My god it works

This commit is contained in:
David Bolack
2024-02-27 20:20:43 -06:00
parent 56851f2c2d
commit 7384cdc241
3 changed files with 44 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ const { Meta } = require('vitreum/headtags');
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
const Markdown = require('naturalcrit/markdown.js');
const Themes = require('themes/themes.json');
const staticThemes = require('themes/themes.json');
const BREWKEY = 'homebrewery-new';
const STYLEKEY = 'homebrewery-new-style';
@@ -30,11 +30,12 @@ const PrintPage = createClass({
getInitialState : function() {
return {
brew : {
text : this.props.brew.text || '',
style : this.props.brew.style || undefined,
renderer : this.props.brew.renderer || 'legacy',
theme : this.props.brew.theme || '5ePHB',
lang : this.props.brew.lang || 'en'
text : this.props.brew.text || '',
style : this.props.brew.style || undefined,
renderer : this.props.brew.renderer || 'legacy',
theme : this.props.brew.theme || '5ePHB',
lang : this.props.brew.lang || 'en',
userThemes : this.props.brew.userThemes
}
};
},
@@ -90,17 +91,43 @@ const PrintPage = createClass({
},
render : function(){
const rendererPath = this.state.brew.renderer == 'V3' ? 'V3' : 'Legacy';
const themePath = this.state.brew.theme ?? '5ePHB';
const baseThemePath = Themes[rendererPath][themePath].baseTheme;
let rendererPath = this.state.brew.renderer == 'V3' ? 'V3' : 'Legacy';
let baseRendererPath = this.state.brew.renderer == 'V3' ? 'V3' : 'Legacy';
const blankRendererPath = this.state.brew.renderer == 'V3' ? 'V3' : 'Legacy';
if(this.state.brew.theme[0] === '#') {
rendererPath = 'Brew';
}
let themePath = this.state.brew.theme ?? '5ePHB';
console.log(`this.state.brew.userThemes`);
console.log(this.state.brew);
console.log(`this.state.brew.userThemes`);
const Themes = { ...staticThemes, ...this.state.brew.userThemes };
let baseThemePath = Themes[rendererPath][themePath]?.baseTheme;
// Override static theme values if a Brew theme.
if(themePath[0] == '#') {
themePath = themePath.slice(1);
rendererPath = '';
} else {
rendererPath += '/';
}
if(baseThemePath && baseThemePath[0] == '#') {
baseThemePath = baseThemePath.slice(1);
baseRendererPath = '';
} else {
baseRendererPath += '/';
}
return <div>
<Meta name='robots' content='noindex, nofollow' />
<link href={`/themes/${rendererPath}/Blank/style.css`} rel='stylesheet'/>
<link href={`/css/${blankRendererPath}/Blank`} rel='stylesheet'/>
{baseThemePath &&
<link href={`/themes/${rendererPath}/${baseThemePath}/style.css`} rel='stylesheet'/>
<link href={`/css/${baseRendererPath}${baseThemePath}`} rel='stylesheet'/>
}
<link href={`/themes/${rendererPath}/${themePath}/style.css`} rel='stylesheet'/>
<link href={`/css/${rendererPath}${themePath}`} rel='stylesheet'/>
{/* Apply CSS from Style tab */}
{this.renderStyle()}
<div className='pages' ref='pages' lang={this.state.brew.lang}>

View File

@@ -348,7 +348,6 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r
await HomebrewModel.increaseView({ shareId: brew.shareId });
}
};
req.brew.userThemes = await getUsersBrewThemes(req.account.username, req.brew.editId);
sanitizeBrew(req.brew, 'share');
splitTextStyleAndMetadata(req.brew);
return next();
@@ -356,7 +355,6 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r
//Print Page
app.get('/print/:id', asyncHandler(getBrew('share')), async (req, res, next)=>{
req.brew.userThemes = await getUsersBrewThemes(req.account.username, req.brew.editId);
sanitizeBrew(req.brew, 'share');
splitTextStyleAndMetadata(req.brew);
next();

View File

@@ -158,7 +158,11 @@ const api = {
throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05', accessType: accessType, brewId: id };
}
const userID = accessType === 'edit' ? req.account.username : stub.authors.split(',')[0];
console.log(`print`);
console.log(accessType);
console.log(stub);
console.log(`print`);
const userID = accessType === 'edit' ? req.account.username : stub.authors[0];
// Clean up brew: fill in missing fields with defaults / fix old invalid values
const userThemes = await getUsersBrewThemes(userID, id);