## # WWW.pm: World Wide Web package # # Copyright (C) 1996 Paul J. Lucas # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## package WWW; use Exporter(); @ISA = qw( Exporter ); @EXPORT = qw( $description::chars $description::words extract_description extract_meta hyperlink ); sub private_extract { my $path_name = shift; if ( $path_name ne $extract::path_name ) { open( FILE, $path_name ) or die "can not open $path_name\n"; read( FILE, $extract::text, $description::chars ); close FILE; $extract::text =~ s/\s+/ /g; # turn into one big long string $extract::path_name = $path_name; } } ############################################################################### # # SYNOPSIS # sub extract_description # # DESCRIPTION # # Extract a description from a file by looking at an initial chunk of # text. If the file is HTML and it has a META description (or Dublin # Code DC.description) tag, use that description. Also extract text # from ALT attributes. Strip all HTML tags and return the number of # words requested. # # SEE ALSO # # Dave Raggett, Arnaud Le Hors, and Ian Jacobs. "Notes on helping # search engines index your Web site," HTML 4.0 Specification, Appendix # B: "Performance, Implementation, and Design Notes," World Wide Web # Consortium, April 1998. # http://www.w3.org/TR/REC-html40/appendix/notes.html#recs # # ---. "Objects, Images, and Applets: How to specify alternate text," # HTML 4.0 Specification, section 13.8, World Wide Web Consortium, # April 1998. # http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8 # # Dublin Core Directorate. "The Dublin Core: A Simple Content # Description Model for Electronic Resources." # http://purl.oclc.org/dc/ # ############################################################################### { my $path_name = shift; private_extract( $path_name ); my $s = $extract::text; for ( $extract::path_name ) { /\.[a-z]?html?$/i && do { # file is HTML my $m = extract_meta( $extract::path_name, 'description' ); return $m if $m; $m = extract_meta( $extract::path_name, 'DC.description' ); return $m if $m; # Zap HTML comments and a partial, trailing comment, if any. $s =~ s///g; $s =~ s/