Skip to content

Instantly share code, notes, and snippets.

@danfascia
Created February 17, 2019 20:14
Show Gist options
  • Save danfascia/a1101d5375fe45abea0ed06fde470a81 to your computer and use it in GitHub Desktop.
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
/**
* 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