Last active
April 19, 2019 23:14
-
-
Save yuigoto/af2bd8eaeac5e8123c6c9b1df6a59f4b to your computer and use it in GitHub Desktop.
[JavaScript : Metalsmith Paginator] : Metalsmith + Handlebars pagination #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* YX : HANDLEBARS : cleanTrailingHtml | |
* ---------------------------------------------------------------------- | |
* Clears the trailing `index.html` from path strings. | |
* | |
* @author Fabio Y. Goto <lab@yuiti.com.br> | |
* @copyright 2018 Fabio Y. Goto | |
* @since 0.0.1 | |
* | |
* @param {string} string | |
* String to remove the trailing HTML file from | |
*/ | |
module.exports = (string) => { | |
// Remove using REGEX | |
return string.replace(/\/*index.html$/, ""); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* YX : HANDLEBARS : compare | |
* ---------------------------------------------------------------------- | |
* Executes a comparison operation on two values. | |
* | |
* @author Fabio Y. Goto <lab@yuiti.com.br> | |
* @copyright 2018 Fabio Y. Goto | |
* @since 0.0.1 | |
* | |
* @param {string} operation | |
* The type of operation to execute | |
* @param {*} value1 | |
* Left number to compare | |
* @param {*} value2 | |
* Right number to compare | |
*/ | |
module.exports = (operation, value1, value2) => { | |
switch (operation.trim) { | |
case "<": | |
return (value1 < value2); | |
case ">": | |
return (value1 > value2); | |
case ">=": | |
return (value1 >= value2); | |
case "<=": | |
return (value1 <= value2); | |
case "==": | |
return (value1 == value2); | |
case "===": | |
return (value1 === value2); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I gotta thank Robert Rüdiger (@ruerob) for the fixes and pointing some optimizations! 👍