Blog module with Excerpt feature

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/29/2008 12:41:02 PM
Gravatar
Total Posts 13
Partner

Blog module with Excerpt feature

In my scenario I have a Blog with multiple items activated. I am using it like a news list (more or less).

I wanted an excerpt feature for the Blog module like in HTML content Module in order to show a shorter list.

I noticed that the Blog module already has an "Excerpt" but apparently it is not used.
I tried to bind the div "blogtext" to this column and the result was not really good; the "Excerpt"
field contains also the HTML sorrounding the text and it is brutish truncated leaving HTML tags open.

My dirty solution is the following:
 

In BlogEdit.aspx.cs, function btnUpdate_Click(...) I made the following changes:
...
if (edContent.Text.Length > 200)
{
string ExcerptString = Regex.Replace(edContent.Text, "<[^>]+?>", "");
blog.Excerpt = ExcerptString.Substring(0,200) + "...";
}
...
and I added the necessary reference to regular expression at the top of the file.

In BlogModule.ascx, I bound the div "blogtext" to the field "Excerpt" instead of "Description" :
...
<div class="blogtext"><%# DataBinder.Eval(Container.DataItem,"Excerpt") %></div>
...

It works enough.. but I'm looking for something better...

 

 

 

8/30/2008 3:06:43 AM
Gravatar
Total Posts 13
Partner

Re: Blog module with Excerpt feature

Oops... there is a bug in my stick of code posted above; I tried to extract a substring of 200 chars from a string that may have less than 200 characters because of cuts by Regex.

here there is a less worse implementation :

In BlogEdit.aspx.cs, function btnUpdate_Click(...)
...
string ExcerptString = Regex.Replace(edContent.Text, "<[^>]+?>", "");
ExcerptString = ExcerptString.Replace("\r\n", "").Trim();

if (ExcerptString.Length > 300)
{
      int iTrunc = ExcerptString.IndexOf(' ', 300);
      ExcerptString = ExcerptString.Substring(0, iTrunc>-1 ? iTrunc:300 );
}
blog.Excerpt = ExcerptString + " " + "<a href=" + txtItemUrl.Text.Replace("~/", String.Empty) + ">...</a>";
...

bye

Wal

8/31/2008 5:53:54 AM
Gravatar
Total Posts 18439

Re: Blog module with Excerpt feature

Hi Walter,

I will look into writing a function that can create an excerpt on the fly, I don't want to revive that legacy field in the blog.

Please be aware that if you are working with the source code I recommend you do not make changes in the mojoPortal projects but put all customizations in external projects. If you propose a change that makes it back into the project thats fine, but if you want to make changes that will not be integrated back in, you should do it in your own projects, otherwise you are forking the code and it will be difficult to get updates without losing your custom changes. So for example if you propose a change to the blog that I don't agree with but you still want to do it, then you should clone the blog into your own custom projects, changing the namespace, changing the table prefix from mp_ to something else. I had to do this once before myself when I had a customer that wanted a blog with some custom functionality.

I think you mentioned in another post about using the blog like a news list. Have you tried putting a blog on a different page and then add an RSS feed to the home page and consume the feed from your blog into the RSS feature. I think the RSS feature could use some improvements but is a better tool for this job. I think it may have a setting already for just showing links or maybe we can add the calculated excerpt there.

Best,

Joe

8/31/2008 6:02:49 AM
Gravatar
Total Posts 18439

Re: Blog module with Excerpt feature

I just create a function for creating an excerpt, it will be in svn trunk by tonight if you want to test it out. It will be in mojoPortal.Framework.UIHelper

public static string CreateExcerpt(string content, int excerptLength)
{
string result = SecurityHelper.RemoveMarkup(content);
if (result.Length <= excerptLength) { return result; }
result = result.Substring(0, excerptLength);
if (!result.EndsWith(" "))
{
if (result.IndexOf(" ") > -1)
{
result = result.Substring(0, result.LastIndexOf(" "));
}
}

return result;
}

Its probably not perfect but it should be a good start.

Best,

Joe

8/31/2008 3:22:22 PM
Gravatar
Total Posts 13
Partner

Re: Blog module with Excerpt feature

[quote]  ...Please be aware that if you are working with the source code I recommend you do not make changes in the mojoPortal projects but put all customizations in external projects. If you propose a change that makes it back into the project thats fine, but if you want to make changes that will not be integrated back in, you should do it in your own projects, otherwise you are forking the code and it will be difficult to get updates without losing your custom changes. ... [/quote]

Hi Joe,
you are absolutely right...

I tried a shortcut working directly in mojo projects after some attempts with the custom News module by Asad Samar..

 I spent a lot of time creating the Data Access Layer for SQLite (which is missing in News Module), but after having finished I discovered that the excerpt feature didn't work. So, I was frustrated

Actually I do not have a complete picture of all that is necessary to create a custom project/module..
exploring the code and your tutorials I will create a step by step scheme.  

 

[quote]
...
I think you mentioned in another post about using the blog like a news list. Have you tried putting a blog on a different page and then add an RSS feed to the home page and consume the feed from your blog into the RSS feature. I think the RSS feature could use some improvements but is a better tool for this job. I think it may have a setting already for just showing links or maybe we can add the calculated excerpt there.
[/quote]

nice, I'll try, many thanks for the suggestion
I'll try also your CreateExcerpt() function.

PS: sorry for my poor english, I hope is sufficiently understandable

You must sign in to post in the forums. This thread is closed to new posts.