Skip to content

Instantly share code, notes, and snippets.

@QXSoftware
Created September 20, 2016 07:11
Show Gist options
  • Save QXSoftware/ba068b89e35aab1f2b357e3c26170369 to your computer and use it in GitHub Desktop.
Save QXSoftware/ba068b89e35aab1f2b357e3c26170369 to your computer and use it in GitHub Desktop.
Remove Unity3D Documentation analytic stuff
use strict;
use warnings;
sub process_html_file {
my $doc_file = $_[0];
open(DOC_FILE, "<", $doc_file) || die "Cannot open file : $!";
local $/;
my $content = <DOC_FILE>;
close(DOC_FILE);
$content =~ s#<script type=\"text/javascript\">\s*var _gaq = _gaq \|\| \[\];.+?</script>##s;
$content =~ s#<script type=\"text/javascript\"\s*src=\"docdata/toc\.js\">.+?</script>##s;
$content =~ s#<script type=\"text/javascript\"\s*src=\"docdata/global_toc\.js\">.+?</script>##s;
$content =~ s#^\s*<!--local TOC-->$##m;
$content =~ s#^\s*<!--global TOC, including other platforms-->$##m;
unlink($doc_file.".nhtml") if -f $doc_file.".nhtml";
open(DOC_FILE, ">", $doc_file) or die "Cannot open file : $!";
print DOC_FILE $content;
close(DOC_FILE);
print $doc_file, "\n";
}
sub strip_html {
my $dir_path = $_[0];
opendir(DOC_DIR, $dir_path) or die "Cannot open dir : $!";
my @items = readdir(DOC_DIR);
foreach (@items) {
my $full_path = $dir_path."/".$_;
if (-f $full_path) {
if (/\.html$/) {
process_html_file($full_path);
}
}
elsif(-d $full_path) {
if ($_ ne "." and $_ ne "..") {
strip_html($full_path);
}
}
}
close(DOC_DIR);
}
sub main {
chomp (my $docDir = $_[0]);
$docDir =~ s/\"//g;
strip_html($docDir);
}
sub usage {
print "Usage:\n",
" ".__FILE__." PATH_TO_UNITY_DOC\n\n",
" For example:\n\n",
" ".__FILE__.' C:\Program Files\Unity\Editor\Data\Documentation\en', "\n";
}
my $argc = @ARGV;
if($argc != 1) {
usage();
}
else {
main($ARGV[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment