| | | Forum Newbie
       
Group: Forum Members Last Login: 1/31/2006 1:02:43 PM Posts: 6, Visits: 13 |
| On my current website the default page is just a picture of me and my wife with little or no content. I have seen some personal websites integrate blogger.com content on their website. Has anyone done this sort of thing?
~Spy |
| | | | 
Forum Administrator
       
Group: Power Users Last Login: 2 days ago @ 8:01:14 AM Posts: 157, Visits: 1,009 |
| I use Blogger.com to manage the content of my blog site http://www.thecave.com/. In a nutshell, Blogger works by generating HTML based on a template. The generated file is then posted via FTP to your web server.
For my web site I have Blogger generate an XML file instead of HTML. This is accomplished by changing the template to generate XML instead of HTML. For example, here is the template I use:
<?xml version="1.0" encoding="UTF-8" ?> <weblog xmlns="http://www.thecave.com/2003/weblog"> <entries> <Blogger> <entry> <id><$BlogItemNumber$></id> <title><BlogItemTitle><$BlogItemTitle$></BlogItemTitle></title> <body><![CDATA[<$BlogItemBody$>]]></body> <pubDate><$BlogItemDateTime$></pubDate> <author> <name><$BlogItemAuthor$></name> <email><$BlogItemAuthorEmail$></email> </author> <archiveFileName><$BlogItemArchiveFileName$></archiveFileName> </entry> </Blogger> </entries> </weblog>
The generated XML file is posted to my web server every time I tell Blogger to publish.
My blog site is written in ASP.NET/C#. Using the XmlSerializer I deserialize the contents of the Blogger generated file into .NET objects. Using an ASP Repeater, I bind the collection of blog items to the repeater which then renders the HTML for display within the browser.
Here is the C# class that each blog item is deserialized to:
#region Copyright (c) 2004-2005 White Peak Software Inc /************************************************************************************ ' ' Copyright (c) 2004-2005 White Peak Software Inc ' ' This software is provided 'as-is', without any express or implied warranty. In no ' event will the authors be held liable for any damages arising from the use of this ' software. ' ' Permission is granted to anyone to use this software for any purpose, including ' commercial applications, and to alter it and redistribute it freely, subject to the ' following restrictions: ' ' 1. The origin of this software must not be misrepresented; you must not claim that ' you wrote the original software. If you use this software in a product, an ' acknowledgment (see the following) in the product documentation is required. ' ' Portions Copyright 2004-2005 White Peak Software Inc ' ' 2. Altered source versions must be plainly marked as such, and must not be ' misrepresented as being the original software. ' ' 3. This notice may not be removed or altered from any source distribution. ' '***********************************************************************************/ #endregion using System; using System.Text.RegularExpressions; using System.Xml.Serialization;
namespace thecave.Web.Blog { /// /// WeblogItem describes a single weblog entry. /// public class WeblogItem { private string _id; private Author _author; private string _title; private string _body; private DateTime _date; private string _archiveFileName; private string _summary = null; private string _permlink = null; private string _encodedTitle = null; private BlogmentDocument _blogment = null;
[XmlElement( "id" )] public string Id{ get{ return _id; } set{ _id = value; } }
[XmlElement( "title" )] public string Title{ get{ return _title; } set{ _title = value; } }
[XmlElement( "body" )] public string Body{ get{ return _body; } set{ _body = value; } }
[XmlElement( ElementName="pubDate", DataType="string" ) ] public string Date { get{ return _date.ToString(); } set{ _date = DateTime.Parse( value ); } }
[XmlIgnore()] public DateTime PublishDate{ get{ return _date; } }
[XmlIgnore()] public string EncodedTitle { get { if( _encodedTitle == null ) { if( _title.Length > 0 ) { _encodedTitle = _title.Replace(" ", "_").ToLower(); } else { _encodedTitle = _id; } _encodedTitle = StripInvalidCharacters(_encodedTitle); } return _encodedTitle; } }
[XmlIgnore()] public string PermLink { get { if( _permlink == null ) { _permlink = String.Format("archive/{0}/{1:00}/{2:00}/{3}.aspx", _date.Year, _date.Month, _date.Day, EncodedTitle ); } return _permlink; } }
[XmlIgnore()] public BlogmentDocument Blogment { get { if( _blogment == null ) { _blogment = new BlogmentDocument(_id); } return _blogment; } }
[XmlElement( "author" )] public Author Author { get { // Create on demand. if( _author == null ) { _author = new Author(); } return _author; } set{ _author = value; } }
[XmlElement( "archiveFileName" )] public string ArchiveFileName { get{ return _archiveFileName; } set{ _archiveFileName = value; } }
[XmlIgnore] public string Summary { get { if( null == _summary ) { _summary = BodyToSummary(); } return _summary; } }
public WeblogItem() {}
private string BodyToSummary() { string summary = ""; int npos; npos = _body.IndexOf( "<br />>" ); if(npos > 0 ) { summary = _body.Substring( 0, npos ); } else { summary = _body; }
// Limit the number of characters to 200. int maxChars = 200; maxChars = Math.Min( maxChars, summary.Length ); npos = summary.IndexOf( ".", maxChars ); if( npos < 0 ) { if( summary.Length > maxChars ) { summary = summary.Substring(0, maxChars); } } else { summary = summary.Substring(0,npos + 1); }
return summary; }
private string StripInvalidCharacters(string value) { const string pattern = @"[\W]|aspx$"; Regex regexTitle = new Regex(pattern); return regexTitle.Replace(value,""); }
} }
Although the code is written specifically for my web site, I'm more than happy to share it with others. Just let me know if you want the code and I will send it to you.
-KIRBY
White Peak Software Inc
www.whitepeaksoftware.com |
| | | | 
Forum Administrator
       
Group: Power Users Last Login: 2 days ago @ 8:01:14 AM Posts: 157, Visits: 1,009 |
| Ryan, a future blogger, emailed me a few questions about blogger.com. I decided to post the questions/answers here to share with others.
................
Do you know if there is any other way to incorporate the xml code into a html page?
There are other ways such as using XSLT and if you want to support IE only you can use a little known approach called XML Data Islands, but I strongly recommend against data islands as you would be limiting site visitors to IE.
When you changed the template does that create readable XML code?
Yes, assuming your template is readable. The generated code matches your template.
Do you necessarily have to upload a file to your server separately? I have a friend that hosts my page, but he uses a version of openwebmail to allow us to securely transfer files, so actual FTP ing is disabled.
Blogger.com supports FTP and SFTP (Secure FTP) for file transfers. I recommend using SFTP as it is more secure. Individual entries can be sent out via email, which may work for you. However, I have not played with this feature. Lastly, Blogger.com also supports uploading to their hosting site BlogSpot.com.
-KIRBY
White Peak Software Inc
www.whitepeaksoftware.com |
| | | | 
Forum Administrator
       
Group: Power Users Last Login: 2 days ago @ 8:01:14 AM Posts: 157, Visits: 1,009 |
| Here is the C# source code I wrote that reads the weblog xml described in this thread and populates the object model. The object model can be used to display weblog entries found in the xml as seen on my blog site www.thecave.com.
You are free to distribute and use this source code. This is an unsupported library. However, I will try my best to answer any questions regarding the source code posted to this discussion forums.
Please read the readme.txt file in the attached archive for more information.
Cheers, -KIRBY
White Peak Software Inc
www.whitepeaksoftware.com
|
| | | | 
Forum Administrator
       
Group: Power Users Last Login: 2 days ago @ 8:01:14 AM Posts: 157, Visits: 1,009 |
| | |
|
|