Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created July 10, 2013 22:00
Show Gist options
  • Save stevewithington/5970702 to your computer and use it in GitHub Desktop.
Save stevewithington/5970702 to your computer and use it in GitHub Desktop.
Mura CMS : Use these methods to auto-summarize any content.
<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 & ' &hellip;';
}
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
Copy link

Do you have an example of this working somewhere?

@stevewithington
Copy link
Author

@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