[drupal-devel] [bug] Teaser always truncated at 600 characters

Goba drupal-devel at drupal.org
Mon Aug 22 11:36:14 UTC 2005


Issue status update for 
http://drupal.org/node/28211
Post a follow up: 
http://drupal.org/project/comments/add/28211

 Project:      Drupal
 Version:      cvs
 Component:    node.module
 Category:     bug reports
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  neale
 Updated by:   Goba
-Status:       patch (code needs review)
+Status:       patch (code needs work)

Neale, your code does not reflect the intentions in Drupal. The problem
with this patch is that it forces a truncate call on the body,
regardless of content, and then reduces the teaser size even more, to
the first paragraph, first sentence, etc. Problems with your approach
are:



* If the first paragraph is too short, it will be the teaser,
regardless of the set size.
* If there are no paragraph or break tags in the truncated teaser part,
the first sentence will be used (regardless of how short is it).
* On the other hand, if the first paragraph is too long, and the
closing tag is out of the initial truncated part, you will end up with
broken HTML.

Now all these are not the intention of the teaser generation code.
Having the exact set length or shorter is sacrificed for having valid
HTML, and complete content. While the current Drupal code might produce
too long teasers, your code can easily end up producing too short ones.
A teaser for this text with your patch would be: /Neale, your code does
not reflect the intentions in Drupal./




Goba



Previous comments:
------------------------------------------------------------------------

Thu, 04 Aug 2005 19:18:23 +0000 : neale

Attachment: http://drupal.org/files/issues/diff_27 (1.16 KB)

The truncation code in node_teaser doesn't make any sense to me:



<?php
 foreach ($breakpoints as $point => $charnum) {
   if ($length = strpos($body, $point, $size)) {
     return substr($body, 0, $length + $charnum);
   }
 }
?>




I don't understand: why is the offset given to strpos the maximum
teaser size?  This would cause teasers to only be nicely split if they
are enough longer than the max. teaser size to have one of the special
characters.  But this guarantees the teaser will either be abruptly
truncated, or over the max. teaser size!  In fact, this is what I'm
seeing on my installation.


Attached is a patch that makes it work the way I think it was intended.
 At least, it makes more sense to me.




------------------------------------------------------------------------

Sun, 21 Aug 2005 19:49:15 +0000 : killes at www.drop.org

changing version and status.







More information about the drupal-devel mailing list