-
-
Save jensgro/5b370d0ecb2352bd0c8d0921f67c5028 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 hidden or 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