From 243038474e3aad1e0f780ab726dcd4cdc46e4294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Fri, 17 May 2024 21:23:31 +0200 Subject: [PATCH 01/36] Initial commit --- server/app.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/app.js b/server/app.js index e04df77a6..45de67f65 100644 --- a/server/app.js +++ b/server/app.js @@ -195,6 +195,26 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ res.status(200).send(brew.text); }); + +app.get('/metadata/:id', asyncHandler(getBrew('share')), (req, res) => { + const { brew } = req; + sanitizeBrew(brew, 'share'); + + const fields = [ 'title', 'pageCount', 'description', 'authors', 'lang', + 'published', 'views', 'shareId', 'createdAt', 'updatedAt', + 'lastViewed', 'thumbnail', 'tags' + ]; + + const metadata = fields.reduce((acc, field) => { + if (brew[field] !== undefined) acc[field] = brew[field]; + return acc; + }, {}); + console.log(metadata); + res.status(200).json(metadata); +}); + + + //User Page app.get('/user/:username', async (req, res, next)=>{ const ownAccount = req.account && (req.account.username == req.params.username); From bcef4006dcf7745c3ea9fa450c2eea046fc45c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Fri, 19 Jul 2024 08:58:19 +0200 Subject: [PATCH 02/36] Remove console.log statement in /metadata/:id route handler --- server/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/app.js b/server/app.js index 45de67f65..f810a6ae4 100644 --- a/server/app.js +++ b/server/app.js @@ -209,7 +209,6 @@ app.get('/metadata/:id', asyncHandler(getBrew('share')), (req, res) => { if (brew[field] !== undefined) acc[field] = brew[field]; return acc; }, {}); - console.log(metadata); res.status(200).json(metadata); }); From 51f758bf47345d47db72c093d1cf2ab479ad0b7d Mon Sep 17 00:00:00 2001 From: David Bolack Date: Thu, 15 Aug 2024 17:15:49 -0500 Subject: [PATCH 03/36] Rework page counters for skipping and resets. Solves #513 This adds the .skipCounting and .resetCounting classes for causing a page number to not be incremented or to reset the number at 1. The ToC Snippet is corrected to match the displayed page numbers while correctly tracking the page ids. --- .../V3/5ePHB/snippets/tableOfContents.gen.js | 49 ++++++++++++++----- themes/V3/Blank/style.less | 14 ++++-- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 3aea01735..dbd0794d5 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -1,14 +1,41 @@ const _ = require('lodash'); const dedent = require('dedent-tabs').default; -const getTOC = (pages)=>{ +const getTOC = ()=>{ - const recursiveAdd = (title, page, targetDepth, child, curDepth=0)=>{ + const iframe = document.getElementById('BrewRenderer'); + const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; + const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); + const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; + + const res = []; + + const pageMap = []; + + const walkPages = ()=>{ + let current = 0; + let skip = 0; + let reset = 0; + const pages = iframeDocument.querySelectorAll('.page'); + _.each(pages, (page)=>{ + current++; + if(page.querySelectorAll('.skipCounting').length > 0) { + skip += 1; + } else if(page.querySelectorAll('.resetCounting').length > 0) { + reset = current - 1; + skip = 0; + } + pageMap[current] = current - reset - skip; + }); + }; + + const recursiveAdd = (title, page, anchor, targetDepth, child, curDepth=0)=>{ if(curDepth > 5) return; // Something went wrong. if(curDepth == targetDepth) { child.push({ title : title, page : page, + anchor : anchor, children : [] }); } else { @@ -16,26 +43,23 @@ const getTOC = (pages)=>{ child.push({ title : null, page : page, + anchor : anchor, children : [] }); } - recursiveAdd(title, page, targetDepth, _.last(child).children, curDepth+1,); + recursiveAdd(title, page, anchor, targetDepth, _.last(child).children, curDepth+1,); } }; - const res = []; - - const iframe = document.getElementById('BrewRenderer'); - const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; - const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); - const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; + walkPages(); _.each(headings, (heading)=>{ + const pageAnchor = heading.closest('.page').id; const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); if(ToCExclude != 'exclude') { - recursiveAdd(heading.textContent.trim(), onPage, headerDepth.indexOf(heading.tagName), res); + recursiveAdd(heading.textContent.trim(), pageMap[onPage], pageAnchor, headerDepth.indexOf(heading.tagName), res); } }); return res; @@ -46,7 +70,7 @@ const ToCIterate = (entries, curDepth=0)=>{ const levelPad = ['- ###', ' - ####', ' - ', ' - ', ' - ', ' - ']; const toc = []; if(entries.title !== null){ - toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page}}}](#p${entries.page})`); + toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page}}}](#${entries.anchor})`); } if(entries.children.length) { _.each(entries.children, (entry, idx)=>{ @@ -60,8 +84,7 @@ const ToCIterate = (entries, curDepth=0)=>{ }; module.exports = function(props){ - const pages = props.brew.text.split('\\page'); - const TOC = getTOC(pages); + const TOC = getTOC(); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(ToCIterate(g1).join('\n')); return r; diff --git a/themes/V3/Blank/style.less b/themes/V3/Blank/style.less index 0f779c38b..84bd5ded5 100644 --- a/themes/V3/Blank/style.less +++ b/themes/V3/Blank/style.less @@ -12,7 +12,7 @@ } @page { margin : 0; } -body { counter-reset : page-numbers; } +body { counter-reset : page-numbers 0; } * { -webkit-print-color-adjust : exact; } //***************************** @@ -51,7 +51,6 @@ body { counter-reset : page-numbers; } height : 279.4mm; padding : 1.4cm 1.9cm 1.7cm; overflow : hidden; - counter-increment : page-numbers; background-color : var(--HB_Color_Background); text-rendering : optimizeLegibility; contain : size; @@ -481,4 +480,13 @@ body { counter-reset : page-numbers; } &:nth-child(even) { .pageNumber { left : 30px; } } -} + + .resetCounting { + counter-set : page-numbers 1; + } + + &:not(:has(.skipCounting)) { + counter-increment : page-numbers; + } + +} \ No newline at end of file From 03f8fc83ee09b258fcc0a1cac68f035ddb013096 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 28 Aug 2024 21:33:32 -0500 Subject: [PATCH 04/36] Add snippets for page Numbering updates Adds options to add skipCounting and ResetCounting classes --- themes/V3/Blank/snippets.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/themes/V3/Blank/snippets.js b/themes/V3/Blank/snippets.js index 8437dab2e..934739dac 100644 --- a/themes/V3/Blank/snippets.js +++ b/themes/V3/Blank/snippets.js @@ -32,6 +32,16 @@ module.exports = [ icon : 'fas fa-sort-numeric-down', gen : '{{pageNumber,auto}}\n' }, + { + name : 'Skip Page Number Increment this Page', + icon : 'fas fa-forward', + gen : '{{skipCounting}}\n' + }, + { + name : 'Restart Numbering', + icon : 'fas fa-fast-backward', + gen : '{{resetCounting}}\n' + }, { name : 'Footer', icon : 'fas fa-shoe-prints', From 6f837980eb7be2758bbb8f7fe8a1c482e8e9bae5 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 31 Aug 2024 13:54:52 -0500 Subject: [PATCH 05/36] All Snippet entries that have subsnippets but not generators. --- client/homebrew/editor/snippetbar/snippetbar.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index af493c961..0cf5b0cce 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -70,7 +70,9 @@ const Snippetbar = createClass({ mergeCustomizer : function(oldValue, newValue, key) { if(key == 'snippets') { const result = _.reverse(_.unionBy(_.reverse(newValue), _.reverse(oldValue), 'name')); // Join snippets together, with preference for the child theme over the parent theme - return _.filter(result, 'gen'); //Only keep snippets with a 'gen' property. + return _.filter(result, function(snip) { + return(snip.hasOwnProperty('gen') || snip.hasOwnProperty('subsnippets')); + }); } }, From 49e072f03f349e5a4aac29b384caa5d50bdce54a Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Wed, 4 Sep 2024 13:54:55 -0500 Subject: [PATCH 06/36] Add button to toggle Preview tools Toggles a state variable to either visible or hidden which is used to set a related class on the toolbar. The hiding is done with CSS, just reducing the width of the toolbar and the opacity of the tools. --- .../homebrew/brewRenderer/toolBar/toolBar.jsx | 6 +++-- .../brewRenderer/toolBar/toolBar.less | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/client/homebrew/brewRenderer/toolBar/toolBar.jsx b/client/homebrew/brewRenderer/toolBar/toolBar.jsx index fb3b62067..5c0a0c2ba 100644 --- a/client/homebrew/brewRenderer/toolBar/toolBar.jsx +++ b/client/homebrew/brewRenderer/toolBar/toolBar.jsx @@ -11,6 +11,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ const [zoomLevel, setZoomLevel] = useState(100); const [pageNum, setPageNum] = useState(currentPage); + const [toolsVisible, setToolsVisible] = useState(true); useEffect(()=>{ onZoomChange(zoomLevel); @@ -66,8 +67,9 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ return deltaZoom; }; - return ( -
+ return ( +
+ {/*v=====----------------------< Zoom Controls >---------------------=====v*/}
+ {/*v=====----------------------< Zoom Controls >---------------------=====v*/}