You're right, there is a bit more involved, but it's not too hard. I was bed-bound when I replied before; this is a bit more thought-out. I had done this for another mod I posted
here. The changes in
red in the code below are adapted from that, but to only do what you want (lowercase). The changes in
blue will add a suffix to the category URLs. [First, undo what was changed in the other post.]
In
nph-build.cgi:
sub build_category_pages {
# --------------------------------------------------------
# This routine builds all the category pages. Each category uses
# the same template which is defined in &site_html_category.
my $build_single = shift;
my ($cat, $url, $dir, @related, $relation, $page_num, $next_page, $numlinks);
local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);
local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev);
# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys %category) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)
next CATEGORY if ($build_single and ($build_single ne $cat));
my $suffix = '_directory'; $url = "$build_root_url/" . &urlencode($cat) . "
$suffix/";
$url =~ tr/[A-Z]/[a-z]/; $use_html ?
print qq|Building Category: <A HREF="$url" TARGET="_blank">$cat</A>\n| :
print qq|Building Category: $cat\n|;
print "\tSubcategories: " . ($#{$subcategories{$cat}} + 1) . "\n";
print "\tLinks: " . (($#{$links{$cat}}+1) / ($#db_cols+1)) . "\n";
# Let's make sure the directory exists, build it if it doesn't.
$dir = &build_dir ($cat);
print "\tDirectory: $dir\n";
print "\tFilename : $dir/$build_index\n";
# We set up all the variables people can use in &site_html.pl.
($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];
# Calculate the related entries and put in a <LI> list.
@related = split(/\Q$db_delim\E/, $related); $related = "";
foreach $relation (@related) {
$related .= qq|<li><a href="$build_root_url/|;
$related .= &urlencode($relation);
$related =~ tr/[A-Z]/[a-z]/; $related .= qq|
$suffix/$build_index">|;
$related .= &build_clean($relation);
$related .= "</a></li>";
}
....
sub build_new_page {
# --------------------------------------------------------
# Creates a "What's New" page. Set $build_span_pages to 1 in links.cfg
# and it will create a seperate page for each date.
... edited for space ... CATEGORY: foreach $category (sort keys %{$link_output{$date}}) {
$category_clean = &build_clean ($category);
my $category2;
$category2 = ($rec{'Category'}); $category2 =~ tr/[A-Z]/[a-z]/; $link_results .= qq|<P><A HREF="$build_root_url/
$category2/$build_index">$category_clean</A>\n|;
$link_results .= ${$link_output{$date}}{$category};
}
sub build_cool_page {
# --------------------------------------------------------
# Creates a "What's Cool" page.
local ($total, $percent, $link_results, $title_linked);
my (%link_output, $category_clean);
if ($build_cool_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
$total = 0;
CATEGORY: foreach $category (sort keys %cool_links) {
LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
%tmp = &array_to_hash ($i, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
}
}
foreach $category (sort keys %cool_links) {
$category_clean = &build_clean ($category);
my $category2;
$category2 = ($rec{'Category'});
$category2 =~ tr/[A-Z]/[a-z]/; $link_results .= qq|<P><A HREF="$build_root_url/
$category2/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
}
$title_linked = &build_linked_title ("Cool");
open (COOL, ">$build_cool_path/$build_index") or cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!");
print "\tCool Links: $total\n";
($db_popular_cutoff < 1) ?
($percent = $db_popular_cutoff * 100 . "%") :
($percent = $db_popular_cutoff);
print COOL &site_html_cool(@cool_links);
close COOL;
}
sub build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.
my $input = shift;
my (@dirs, $dir, $output, $path, $last);
my $suffix = '_directory'; @dirs = split (/\//, $input);
$last = &build_clean(pop @dirs);
$output = qq| <A HREF="$build_root_url/">Top</A> :|;
foreach $dir (@dirs) {
$path .= "/$dir
$suffix";
$path =~ tr/[A-Z]/[a-z]/;
$dir = &build_clean ($dir);
$output .= qq| <A HREF="$build_root_url$path/">$dir</A> :|;
}
$output .= " $last";
return $output;
}
=======
In
search.cgi, change:
sub build_linked_title {
# --------------------------------------------------------
# A little different then the one found in nph-build.cgi as it also
# links up the last field as well.
my ($input) = shift;
my ($dir, $output, $path, $last);
foreach $dir ((split m!/!, $input)) {
$path .= "/$dir
$suffix";
$path =~ tr/[A-Z]/[a-z]/; $dir = &build_clean ($dir);
$output .= qq|<A HREF="$build_root_url$path/">$dir</A>:|;
}
=======
>> Try it without these next parts, see if it works OK. I changes the mod so hopefully it will not affect as much. In
db_utils.pl:
sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode =~ s/\%2F/\//g;
$toencode =~ tr/[A-Z]/[a-z]/; #May not be required
return $toencode;
}
========
This mod makes the New, Cool , and Rate pages build with lowercase letters, so a few more changes are in order. All
templates need to be changed so that they have lowercase letters. Here is the original code:
<a class="menulink" href="<%build_root_url%>/New">What's New</a> |
<a class="menulink" href="<%build_root_url%>/Cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/Ratings">Top Rated</a> |
and the updated code:
<a class="menulink" href="<%build_root_url%>/
new">What's New</a> |
<a class="menulink" href="<%build_root_url%>/
cool">What's Cool</a> |
<a class="menulink" href="<%build_root_url%>/
ratings">Top Rated</a> |
Then, in
links.cfg, change the uppercase N, C, and R to lowercase:
# PATH and URL of What's New page. No Trailing slash.
# $build_new_path = "$build_root_path/new";
$build_new_path = "$build_root_path/
new";
$build_new_url = "$build_root_url/new";
# PATH and URL of What's Cool page. No Trailing slash.
$build_cool_path = "$build_root_path/
cool";
$build_cool_url = "$build_root_url/
cool";
# PATH and URL of What's Rating page. No Trailing slash.
$build_ratings_path = "$build_root_path/
ratings";
$build_ratings_url = "$build_root_url/
ratings";
<< End of try without...
======
I may have missed something, especially for the suffix mod, as I did not really test it. You could probably not put the
my $suffix = '_directory'; part into each routine, and instead just put that line in links.cfg. Just seems easier to troubleshoot things when you don't have to hunt around for bits of code. (Now where did I put that "$suffix =" ???)
Hope this works!
Leonard
aka PerlFlunkie