Created
July 10, 2013 22:00
-
-
Save stevewithington/5970702 to your computer and use it in GitHub Desktop.
Mura CMS : Use these methods to auto-summarize any content.
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
<cfscript> | |
// drop these methods into either the Site or Theme's contentRenderer.cfc and use as necessary | |
public any function summarize(string str='', numeric count='26') { | |
var local = {}; | |
local.str = arguments.str; | |
local.count = Val(arguments.count); | |
if ( Len(Trim(local.str)) ) { | |
local.str = REReplace($.stripHTML(stripTagContent(local.str)), '[\s|\r\n?|\n]+', ' ', 'ALL'); | |
javaArray = CreateObject('java', 'java.util.Arrays'); | |
wordArray = javaArray.copyOf(local.str.Split(' '), local.count); | |
local.str = ArrayToList(wordArray, ' '); | |
}; | |
return ListFindNoCase('.,!,?', Right(local.str, 1)) ? local.str : local.str & ' …'; | |
} | |
public string function stripTagContent(string str='', string tagsToStrip='script,style,embed,object') { | |
var local = {}; | |
local.str = arguments.str; | |
for ( local.i=1; local.i lte ListLen(arguments.tagsToStrip); local.i++ ) { | |
local.listItem = ListGetAt(arguments.tagsToStrip,local.i); | |
local.str = ReReplaceNoCase(local.str,'<' & local.listItem & '.*?>.*?</' & local.listItem & '>','','all'); | |
}; | |
return local.str; | |
} | |
</cfscript> |
@davidpanzarella, yeah...this method was used on an old site done about 4 years ago now:
http://www.mitchellswabackcharities.org/. I like to use these methods so that content managers don't have to enter anything into the Summary area.
These methods are also used in my MuraMetaGenerator plugin.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have an example of this working somewhere?