0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-18 12:12:43 +00:00

Merge branch 'master' of https://github.com/naturalcrit/homebrewery into nav-fixes

This commit is contained in:
Víctor Losada Hernández
2024-03-06 18:55:02 +01:00
13 changed files with 944 additions and 762 deletions

View File

@@ -20,7 +20,7 @@ const PAGE_HEIGHT = 1056;
const INITIAL_CONTENT = dedent` const INITIAL_CONTENT = dedent`
<!DOCTYPE html><html><head> <!DOCTYPE html><html><head>
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" /> <link href="//use.fontawesome.com/releases/v6.5.1/css/all.css" rel="stylesheet" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
<link href='/homebrew/bundle.css' rel='stylesheet' /> <link href='/homebrew/bundle.css' rel='stylesheet' />
<base target=_blank> <base target=_blank>

View File

@@ -160,21 +160,21 @@ const Editor = createClass({
} }
} }
// Superscript // Subscript & Superscript
if(line.includes('\^')) { if(line.includes('^')) {
const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; let startIndex = line.indexOf('^');
let match; const superRegex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/gy;
while ((match = regex.exec(line)) != null) { const subRegex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/gy;
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 1 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 1 }, { className: 'superscript' });
}
}
// Subscript while (startIndex >= 0) {
if(line.includes('^^')) { superRegex.lastIndex = subRegex.lastIndex = startIndex;
const regex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/g; let isSuper = false;
let match; let match = subRegex.exec(line) || superRegex.exec(line);
while ((match = regex.exec(line)) != null) { if (match) {
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 2 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 2 }, { className: 'subscript' }); isSuper = !subRegex.lastIndex;
codeMirror.markText({ line: lineNumber, ch: match.index }, { line: lineNumber, ch: match.index + match[0].length }, { className: isSuper ? 'superscript' : 'subscript' });
}
startIndex = line.indexOf('^', Math.max(startIndex + 1, subRegex.lastIndex, superRegex.lastIndex));
} }
} }

View File

@@ -1,4 +1,4 @@
@import "naturalcrit/styles/colors.less"; @import 'naturalcrit/styles/colors.less';
@navbarHeight : 28px; @navbarHeight : 28px;
@@ -29,9 +29,12 @@
z-index : 2; z-index : 2;
display : flex; display : flex;
justify-content : space-between; justify-content : space-between;
}
.navSection { .navSection {
display : flex; display : flex;
align-items : center; align-items : center;
&:last-child .navItem { border-left : 1px solid #666666; }
}
// "NaturalCrit" logo // "NaturalCrit" logo
.navLogo { .navLogo {
display : block; display : block;
@@ -62,7 +65,6 @@
} }
} }
} }
&:last-child .navItem { border-left : 1px solid #666666; }
.navItem { .navItem {
#backgroundColorsHover; #backgroundColorsHover;
.animate(background-color); .animate(background-color);
@@ -154,7 +156,7 @@
align-content : baseline; align-content : baseline;
justify-content : flex-start; justify-content : flex-start;
width : 440px; width : 440px;
max-height : ~"calc(100vh - 28px)"; max-height : ~'calc(100vh - 28px)';
padding : 0 10px 5px; padding : 0 10px 5px;
margin : 0 auto; margin : 0 auto;
background-color : #333333; background-color : #333333;
@@ -237,7 +239,6 @@
} }
.navDropdownContainer { .navDropdownContainer {
position : relative; position : relative;
min-width: 120px;
.navDropdown { .navDropdown {
position : absolute; position : absolute;
top : 28px; top : 28px;
@@ -248,10 +249,9 @@
overflow : hidden auto; overflow : hidden auto;
.navItem { .navItem {
position : relative; position : relative;
display : flex; display : block;
justify-content : space-between;
align-items : center;
width : 100%; width : 100%;
padding : 8px 5px;
border : 1px solid #888888; border : 1px solid #888888;
border-bottom : 0; border-bottom : 0;
animation-name : glideDropDown; animation-name : glideDropDown;
@@ -266,7 +266,7 @@
position : relative; position : relative;
box-sizing : border-box; box-sizing : border-box;
display : block; display : block;
max-height : ~"calc(100vh - 28px)"; // I don't think is correct syntax, but leaving it in for now... (Gazook89) max-height : ~'calc(100vh - 28px)';
padding : 8px 5px 13px; padding : 8px 5px 13px;
overflow : hidden auto; overflow : hidden auto;
color : white; color : white;
@@ -331,7 +331,6 @@
} }
} }
} }
}
// this should likely be refactored into .navDropdownContainer // this should likely be refactored into .navDropdownContainer
.save-menu { .save-menu {
@@ -344,9 +343,3 @@
} }
} }
} }
}

View File

@@ -1,12 +1,64 @@
const React = require('react'); const React = require('react');
const _ = require('lodash');
const Nav = require('naturalcrit/nav/nav.jsx'); const Nav = require('naturalcrit/nav/nav.jsx');
const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); // Importing the function from helpers.js
module.exports = function(props){ const BREWKEY = 'homebrewery-new';
return <Nav.item const STYLEKEY = 'homebrewery-new-style';
const METAKEY = 'homebrewery-new-meta';
const NewBrew = () => {
const handleFileChange = (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const fileContent = e.target.result;
const newBrew = {
text: fileContent,
style: ''
};
if(fileContent.startsWith('```metadata')) {
splitTextStyleAndMetadata(newBrew); // Modify newBrew directly
localStorage.setItem(BREWKEY, newBrew.text);
localStorage.setItem(STYLEKEY, newBrew.style);
localStorage.setItem(METAKEY, JSON.stringify(_.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang'])));
window.location.href = '/new';
} else {
alert('This file is invalid, please, enter a valid file');
}
};
reader.readAsText(file);
}
};
return (
<Nav.dropdown>
<Nav.item
className='new'
color='purple'
icon='fa-solid fa-plus-square'>
new
</Nav.item>
<Nav.item
className='fromBlank'
href='/new' href='/new'
newTab={true} newTab={true}
color='purple' color='purple'
icon='fas fa-plus-square'> icon='fa-solid fa-file'>
new from blank
</Nav.item>; </Nav.item>
<Nav.item
className='fromFile'
color='purple'
icon='fa-solid fa-upload'
onClick={() => { document.getElementById('uploadTxt').click(); }}>
<input id="uploadTxt" className='newFromLocal' type="file" onChange={handleFileChange} style={{ display: 'none' }} />
from file
</Nav.item>
</Nav.dropdown>
);
}; };
module.exports = NewBrew;

View File

@@ -12,7 +12,7 @@ const template = async function(name, title='', props = {}){
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" /> <meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" />
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" /> <link href="//use.fontawesome.com/releases/v6.5.1/css/all.css" rel="stylesheet" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
<link href=${`/${name}/bundle.css`} rel='stylesheet' /> <link href=${`/${name}/bundle.css`} rel='stylesheet' />
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" /> <link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />

922
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -80,9 +80,9 @@
] ]
}, },
"dependencies": { "dependencies": {
"@babel/core": "^7.23.9", "@babel/core": "^7.24.0",
"@babel/plugin-transform-runtime": "^7.23.9", "@babel/plugin-transform-runtime": "^7.24.0",
"@babel/preset-env": "^7.23.9", "@babel/preset-env": "^7.24.0",
"@babel/preset-react": "^7.23.3", "@babel/preset-react": "^7.23.3",
"@googleapis/drive": "^8.7.0", "@googleapis/drive": "^8.7.0",
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
@@ -92,7 +92,7 @@
"create-react-class": "^15.7.0", "create-react-class": "^15.7.0",
"dedent-tabs": "^0.10.3", "dedent-tabs": "^0.10.3",
"expr-eval": "^2.0.2", "expr-eval": "^2.0.2",
"express": "^4.18.2", "express": "^4.18.3",
"express-async-handler": "^1.2.0", "express-async-handler": "^1.2.0",
"express-static-gzip": "2.1.7", "express-static-gzip": "2.1.7",
"fs-extra": "11.2.0", "fs-extra": "11.2.0",
@@ -106,13 +106,13 @@
"marked-smartypants-lite": "^1.0.2", "marked-smartypants-lite": "^1.0.2",
"markedLegacy": "npm:marked@^0.3.19", "markedLegacy": "npm:marked@^0.3.19",
"moment": "^2.30.1", "moment": "^2.30.1",
"mongoose": "^8.2.0", "mongoose": "^8.2.1",
"nanoid": "3.3.4", "nanoid": "3.3.4",
"nconf": "^0.12.1", "nconf": "^0.12.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-frame-component": "^4.1.3", "react-frame-component": "^4.1.3",
"react-router-dom": "6.22.1", "react-router-dom": "6.22.2",
"sanitize-filename": "1.6.3", "sanitize-filename": "1.6.3",
"superagent": "^8.1.2", "superagent": "^8.1.2",
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git" "vitreum": "git+https://git@github.com/calculuschild/vitreum.git"
@@ -120,7 +120,7 @@
"devDependencies": { "devDependencies": {
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-plugin-jest": "^27.9.0", "eslint-plugin-jest": "^27.9.0",
"eslint-plugin-react": "^7.33.2", "eslint-plugin-react": "^7.34.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-expect-message": "^1.1.3", "jest-expect-message": "^1.1.3",
"postcss-less": "^6.0.0", "postcss-less": "^6.0.0",

View File

@@ -17,21 +17,8 @@ const asyncHandler = require('express-async-handler');
const { DEFAULT_BREW } = require('./brewDefaults.js'); const { DEFAULT_BREW } = require('./brewDefaults.js');
const splitTextStyleAndMetadata = (brew)=>{ const { splitTextStyleAndMetadata } = require('../shared/helpers.js');
brew.text = brew.text.replaceAll('\r\n', '\n');
if(brew.text.startsWith('```metadata')) {
const index = brew.text.indexOf('```\n\n');
const metadataSection = brew.text.slice(12, index - 1);
const metadata = yaml.load(metadataSection);
Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang']));
brew.text = brew.text.slice(index + 5);
}
if(brew.text.startsWith('```css')) {
const index = brew.text.indexOf('```\n\n');
brew.style = brew.text.slice(7, index - 1);
brew.text = brew.text.slice(index + 5);
}
};
const sanitizeBrew = (brew, accessType)=>{ const sanitizeBrew = (brew, accessType)=>{
brew._id = undefined; brew._id = undefined;

22
shared/helpers.js Normal file
View File

@@ -0,0 +1,22 @@
const _ = require('lodash');
const yaml = require('js-yaml');
const splitTextStyleAndMetadata = (brew) => {
brew.text = brew.text.replaceAll('\r\n', '\n');
if (brew.text.startsWith('```metadata')) {
const index = brew.text.indexOf('```\n\n');
const metadataSection = brew.text.slice(12, index - 1);
const metadata = yaml.load(metadataSection);
Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang']));
brew.text = brew.text.slice(index + 5);
}
if (brew.text.startsWith('```css')) {
const index = brew.text.indexOf('```\n\n');
brew.style = brew.text.slice(7, index - 1);
brew.text = brew.text.slice(index + 5);
}
};
module.exports = {
splitTextStyleAndMetadata
};

View File

@@ -78,7 +78,7 @@ module.exports = function(props){
return dedent` return dedent`
{{toc,wide {{toc,wide
# Table Of Contents # Contents
${markdown} ${markdown}
}} }}

View File

@@ -402,15 +402,9 @@
} }
} }
.pageNumber { .pageNumber {
position : absolute;
right : 2px; right : 2px;
bottom : 22px; bottom : 22px;
width : 50px;
font-size : 0.9em;
color : var(--HB_Color_Footnotes); color : var(--HB_Color_Footnotes);
text-align : center;
text-indent : 0;
&.auto::after { content : counter(phb-page-numbers); }
} }
.footnote { .footnote {
position : absolute; position : absolute;

View File

@@ -8,7 +8,7 @@
} }
@page { margin : 0; } @page { margin : 0; }
body { counter-reset : phb-page-numbers; } body { counter-reset : page-numbers; }
* { -webkit-print-color-adjust : exact; } * { -webkit-print-color-adjust : exact; }
//***************************** //*****************************
@@ -47,7 +47,7 @@ body { counter-reset : phb-page-numbers; }
height : 279.4mm; height : 279.4mm;
padding : 1.4cm 1.9cm 1.7cm; padding : 1.4cm 1.9cm 1.7cm;
overflow : hidden; overflow : hidden;
counter-increment : phb-page-numbers; counter-increment : page-numbers;
background-color : var(--HB_Color_Background); background-color : var(--HB_Color_Background);
text-rendering : optimizeLegibility; text-rendering : optimizeLegibility;
contain : size; contain : size;
@@ -166,7 +166,6 @@ body { counter-reset : phb-page-numbers; }
margin : 0; margin : 0;
font-size : 120px; font-size : 120px;
text-transform : uppercase; text-transform : uppercase;
mix-blend-mode : overlay;
opacity : 30%; opacity : 30%;
transform : rotate(-45deg); transform : rotate(-45deg);
p { margin-bottom : none; } p { margin-bottom : none; }
@@ -460,3 +459,22 @@ body { counter-reset : phb-page-numbers; }
.homebreweryIcon.red { background-color : red; } .homebreweryIcon.red { background-color : red; }
.homebreweryIcon.gold { background-image : linear-gradient(to top left, brown 22.5%, gold 40%, white 60%, gold 67.5%, brown 82.5%); } .homebreweryIcon.gold { background-image : linear-gradient(to top left, brown 22.5%, gold 40%, white 60%, gold 67.5%, brown 82.5%); }
} }
//*****************************
//* Page Number
//*****************************/
.page {
.pageNumber {
position : absolute;
right : 30px;
bottom : 30px;
width : 50px;
font-size : 0.9em;
text-align : center;
&.auto::after { content : counter(page-numbers); }
}
&:nth-child(even) {
.pageNumber { left : 30px; }
}
}

View File

@@ -374,17 +374,9 @@
} }
.pageNumber{ .pageNumber{
font-family : FrederickaTheGreat; font-family : FrederickaTheGreat;
position : absolute;
right : 3cm; right : 3cm;
bottom : 1.25cm; bottom : 1.25cm;
width : 50px;
font-size : 0.9em;
color : var(--HB_Color_HeaderText); color : var(--HB_Color_HeaderText);
text-align : center;
text-indent : 0;
&.auto::after {
content : counter(phb-page-numbers);
}
} }
.footnote{ .footnote{
position : absolute; position : absolute;