Email conversation
From | Guillaume Larocque |
To | Me |
Subject | Remove title from feed parser and limiting the number of characters in feeds |
Date | 25 January 2007 22:11 |
Hi, I have just been able to successfully implement your atom feed parser in
a website I am building and it works great! Considering my limited (read
absent) knowledge of javascript, I have two simple questions. 1) Is there a
way to prevent the parser from changing the title of a web page (in which a
feed is displayed) to the feed title? 2) Is there a way to limit the number
of characters, or words, that are parsed from the xml file and simply add
(...) with a link to the rest? I have already been able to limit the number
of feeds, but can't figure out how to limit the length of each feed or
alternatively to just display the feed header without the feed items'
content.
Many thanks for your great work!
Guillaume
From | Me |
To | Guillaume Larocque |
Subject | Re: Remove title from feed parser and limiting the number of characters in feeds |
Date | 27 January 2007 11:19 |
Guillaume,
> 1) Is there a way to prevent the parser from changing the title of a web
> page
Remove this line:
document.title = feedInfo['title'] ? ( 'News feed: ' + feedInfo['title'] ) :
'Untitled newsfeed';
> 2) Is there a way to limit the number of characters, or words, that are
> parsed from the xml file and simply add (...) with a link to the rest?
Limiting the length is quite easy. These lines write it:
oFeedStr += y['description']?('<div class="descr">'+y['description']+'<\/div>'):'';
oFeedStr += y['content']?('<div class="conte">'+y['content']+'<\/div>'):'';
All you have to do is use a substring for each:
oFeedStr += y['description']?('<div class="descr">'+
y['description'].substring(0,1000);
+'<\/div>'):'';
etc. (Note that this can break any HTML in the feed item though)
Making it link is much harder. You would have to add a 'more' link to the
end, which remembers the full text and displays it somehow. It is not a
simple change, as the script is not currently designed to be used that way -
it is designed for one-off displaying.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/