From 481c9f067cbba45623d5f995349acdeb9b3ea275 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 27 Feb 2021 11:47:29 +1300 Subject: [PATCH] Fix title issue (#1251) * Maximum title length set to 100 characters. * Reverse unnecessary change that was incorrectly included in previous commit. * Reduced code change to one addition on a single line. * Revert "Reduced code change to one addition on a single line." This reverts commit 2a355cf115e62f9894eac011bb6bd0aaacb156ad. * Use newer syntax to shorten Co-authored-by: Trevor Buckner --- .eslintrc.js | 2 +- server/homebrew.api.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6d763454c..e8618b8c7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { root : true, parserOptions : { - ecmaVersion : 9, + ecmaVersion : 2021, sourceType : 'module', ecmaFeatures : { jsx : true diff --git a/server/homebrew.api.js b/server/homebrew.api.js index e88a3ef88..02f88c937 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -11,9 +11,12 @@ const Markdown = require('../shared/naturalcrit/markdown.js'); // }); // }; +const MAX_TITLE_LENGTH = 100; + const getGoodBrewTitle = (text)=>{ const tokens = Markdown.marked.lexer(text); - return title = (tokens.find((token)=>token.type == 'heading' || token.type == 'paragraph') || { text: 'No Title' }).text; + return (tokens.find((token)=>token.type == 'heading' || token.type == 'paragraph')?.text || 'No Title') + .slice(0, MAX_TITLE_LENGTH); }; const newBrew = (req, res)=>{