Created
February 17, 2019 20:14
-
-
Save danfascia/a1101d5375fe45abea0ed06fde470a81 to your computer and use it in GitHub Desktop.
11ty filter to split a string {{content}} into an excerpt (i.e. all stuff before <!--more-->) and the remainder (i.e. stuff after that tag...). Source: https://hawksworx.com
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
/** | |
* Split the content into excerpt and remainder | |
* | |
* @param {String} str | |
* @param {String [excerpt | remainder]} section | |
* | |
* If excerpt or nothing is passed as an argument, we return what was before the split marker. | |
* If remainder is passed as an argument, we return the rest of the post | |
* | |
*/ | |
module.exports = function(str, section) { | |
var content = new String(str); | |
var delimit = "<!--more-->"; | |
var parts = content.split(delimit); | |
var which = section == 'remainder' ? 1 : 0; | |
if(parts.length) { | |
return parts[which]; | |
} else { | |
return str | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment