From d12eb87739c2825ebe567e32df2392472f2b2561 Mon Sep 17 00:00:00 2001 From: Sam Harris Date: Thu, 19 Sep 2019 16:15:45 +0100 Subject: [PATCH] if description is over 200 char reduce it and end with "..." relates #196 (sort of) --- src/app.js | 1 - src/views/helpers/index.js | 4 +++- src/views/helpers/limitDescriptionLength.js | 6 ++++++ src/views/results.hbs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/views/helpers/limitDescriptionLength.js diff --git a/src/app.js b/src/app.js index 3d52a0c..2d22e95 100644 --- a/src/app.js +++ b/src/app.js @@ -26,7 +26,6 @@ app.engine( ); app.set("port", process.env.PORT || 3000); -// app.use(express.static("public")); app.use(controllers); module.exports = app; diff --git a/src/views/helpers/index.js b/src/views/helpers/index.js index 4b7b07d..821ab7f 100644 --- a/src/views/helpers/index.js +++ b/src/views/helpers/index.js @@ -1,7 +1,9 @@ const returnAverageRating = require("./returnAverageRating"); const returnNearestInt = require("./returnNearestInt"); +const limitDescriptionLength = require("./limitDescriptionLength"); module.exports = { returnAverageRating, - returnNearestInt + returnNearestInt, + limitDescriptionLength }; diff --git a/src/views/helpers/limitDescriptionLength.js b/src/views/helpers/limitDescriptionLength.js new file mode 100644 index 0000000..d2a36f7 --- /dev/null +++ b/src/views/helpers/limitDescriptionLength.js @@ -0,0 +1,6 @@ +module.exports = description => { + if (description.length > 200) { + return description.slice(0, 199) + "..."; + } + return description; +}; diff --git a/src/views/results.hbs b/src/views/results.hbs index c66c970..30b5dcf 100644 --- a/src/views/results.hbs +++ b/src/views/results.hbs @@ -7,7 +7,7 @@

{{this.product_name}}

-

{{this.product_description}}

+

{{limitDescriptionLength this.product_description}}

{{returnNearestInt this.product_avg_rating}}

{{/each}}