diff --git a/package.json b/package.json index 211a9f5..dee5d79 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "socket.io": "^2.2.0", "socket.io-client": "^2.2.0", "striptags": "^3.1.1", + "tinycolor2": "^1.4.1", "unused-filename": "^1.0.0" } } diff --git a/public/css/styles.css b/public/css/styles.css index 67d0ee2..ff586ec 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -15,7 +15,7 @@ width: 100px; height: 300px; /* The tallest a book could be */ border-bottom: 4px solid saddlebrown; - margin: 10px 0 -4px !important; + margin: 10px 1px -4px !important; } .book-slot.is-thin { width: 80px; diff --git a/routes/get_home.js b/routes/get_home.js index e9a63d4..9c8e515 100644 --- a/routes/get_home.js +++ b/routes/get_home.js @@ -2,6 +2,7 @@ const path = require('path'); const fs = require('fs'); const snarkdown = require('snarkdown'); const fecha = require('fecha'); +const tinycolor = require('tinycolor2'); const settings = require('../settings.json'); @@ -45,6 +46,10 @@ module.exports = function (app) { footer: 'Close Take Book', }); const maxSize = settings.maxFileSize > 0 ? settings.maxFileSize : 10; + let spineColor = tinycolor('#' + id.substr(0, 6)); + if (!spineColor.isValid()) { + spineColor = tinycolor.random(); + } return app.templater.fill('./templates/elements/book.html', { id, title: bookData.title, @@ -52,8 +57,8 @@ module.exports = function (app) { thickness: (fileDetails.size > (maxSize * 0.3)) || (bookData.title.length > 28) ? 'is-thick' : (fileDetails.size < (maxSize * 0.6) ? 'is-thin' : ''), tallness: bookData.title.length > 16 ? 'is-tall' : (bookData.title.length < 8 ? 'is-short' : ''), - spineColor: '#ff0000', - textColor: '#ffffff', + spineColor: spineColor.toString(), + textColor: spineColor.isLight() ? '#000000' : '#ffffff', fileType: bookData.fileType, modal, }); @@ -63,7 +68,7 @@ module.exports = function (app) { books = '