Gossamer Forum
Home : Products : Gossamer Links : Discussions :

truncating/cropping long urls - old thread

Quote Reply
truncating/cropping long urls - old thread
This is an old mod revisited! Basically, i show URLs in my search results. However, some of them are very long and so I want Links to crop them, by adding "..." instead of the rest of the url, i.e.:

This
http://www.alongdomainname.com/folder1/folder2
becomes
http://www.alongdomainname.com/folder1/fol...

This was talked about and fixed for LinksSQL1.x in this thread which might be good to read: http://gossamer-threads.com/p/96410

What do you think? Can we do this with LinksSQL2?

Jeffb

Quote Reply
Re: truncating/cropping long urls - old thread In reply to
Yep...put the codes in the sub site_html_link routine in the SiteHTML.pm module file.

Regards,

Eliot Lee
Quote Reply
Re: truncating/cropping long urls - old thread In reply to
Thanks. Didn't realise it was that easy Shocked For anyone else who wants to do this, here is a guide. First, edit the SiteHTML.pm file. Find this line witin the sub site_html_link routine:
Code:
(defined $rec->{'isPopular'} and ($rec->{'isPopular'} eq 'Yes')) ? ($rec->{'isPopular'} = 1) : ($rec->{'isPopular'} = 0);
The all you need to do is add these lines below the line mentioned above. To crop the URL at different lengths just change the two 45s. Then just add <%URL_S%> in your link.html template.

Code:

if (length($rec->{URL}) > 45) {
$rec->{URL_S} = substr ($rec->{URL}, 0, 45) . '... ';
}
else {
$rec->{URL_S} = $rec->{URL};
}
Hey Elliot what about the numbered links mod?

Jeffb.

Quote Reply
Re: truncating/cropping long urls - old thread In reply to
Or better to keep your changes out of Links SQL, go to Build->Template Globals and add:

Short_URL =

Code:
sub {
my $tags = shift;
if (length $tags->{URL} > 45) {
return substr($tags->{URL},0,45) . '...';
}
else {
return $tags->{URL};
}
}
and then use <%Short_URL%> where you want it to appear. This way when you want to upgrade your changes won't be lost.

Cheers,

Alex

--
Gossamer Threads Inc.