#!/usr/bin/perl
#window checkHTML timeout=180
use strict;
my $gScriptParentFolder = '/Applications/';
my $g_htmllint_path = "${gScriptParentFolder}/htmllint/htmllint";
my $g_checklink_path = "${gScriptParentFolder}/checklink.pl";
my $gLintOption = '-lc -local -noaccessibility';
#-noreligious -nopedantic -noaccessibility
#チェックが厳しくない方が早い?
my @gResultArray;
my @gErrorCharArray = ( '○', '×' );
my @gHeadingErrorCharArray = ( '#', '※' );
#
&run();
#
sub run
{
my $folder = "./";
my $fileName = $ARGV[0];
if( $ARGV[0] =~ m!(.*)/(.+?)$! )
{
$folder = $1;
$fileName = $2;
}
my $errStr = '';
$errStr .= $gErrorCharArray[ &checkLint( $fileName ) ];
$errStr .= $gErrorCharArray[ &checkLink( $fileName ) ];
print "【$errStr : $fileName】\n";
print "$folder/$fileName\n";
print @gResultArray;
print "--\n";
}
sub checkLint
{
my $inFileName = shift;
my $result = `perl $g_htmllint_path $gLintOption $inFileName`;
my $err = 0;
my @result;
my ( $score ) = $result =~ /このHTMLは (\d+)点です/;
if( $score == 100 )
{
push( @result, "lint 100点∩( ・ω・)∩\n" );
$err = 0;
}
else
{
push( @result, "★ lint このHTMLは $score点です\n" );
push( @result, $result );
$err = 1;
}
push( @gResultArray, @result );
return $err
}
sub checkLink
{
my $inFileName = shift;
my $result = `perl $g_checklink_path $inFileName`;
my @lines = split( "\n", $result );
my @result;
my $err = 0;
my $line;
while( defined( $line = shift( @lines ) ) )
{
if( $line eq 'List of broken links and redirects:' )
{
my $deadCount = 0;
foreach( @lines )
{
if( /^ To do: The link is broken./ )
{
$deadCount++;
}
}
push( @result, "★ link デッドリンク $deadCount個\n" );
push( @result, "$line\n", join( "\n", @lines ), "\n" );
$err = 1;
last;
}
}
if( $err == 0 )
{
push( @result, "link デッドリンク無し(゚ ヮ゚*)ノ\n" );
}
push( @gResultArray, @result );
return $err;
}