From: blake Date: Tue, 12 May 2020 22:32:35 +0000 (-0500) Subject: Docs: Introducing the site generator generate_docs.pl X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=512f453ca763406115a2cdda920d1e5714282eb2;p=working%2FEvergreen.git Docs: Introducing the site generator generate_docs.pl --- diff --git a/docs-antora/generate_docs.pl b/docs-antora/generate_docs.pl new file mode 100644 index 0000000000..0ca827272e --- /dev/null +++ b/docs-antora/generate_docs.pl @@ -0,0 +1,233 @@ +#!/usr/bin/perl +# --------------------------------------------------------------- +# Copyright © 2020 MOBIUS +# Blake Graham-Henderson +# +# 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. +# --------------------------------------------------------------- + + +use Getopt::Long; +use Cwd; +use File::Path; +use Data::Dumper; + +my $base_url; +my $tmp_space; +my $html_output; +my $antoraui_git; +my $antora_version; +my $help; + + + +GetOptions ( +"base-url=s" => \$base_url, +"tmp-space=s" => \$tmp_space, +"html-output=s" => \$html_output, +"antora-ui-repo=s" => \$antoraui_git, +"antora-version=s" => \$antora_version, +"help" => \$help +); + +sub help +{ + print < '.$file) or $ret=0; + binmode(OUTPUT, ":utf8"); + print OUTPUT "$contents\n"; + close(OUTPUT); + return $ret; +} + +sub replace_yml +{ + my $replacement = shift; + my $yml_path = shift; + my $file = shift; + my @path = split(/\//,$yml_path); + my @lines = @{read_file($file)}; + my $depth = 0; + my $ret = ''; + while(@lines[0]) + { + my $line = shift @lines; + if(@path[0]) + { + my $preceed_space = $depth * 2; + my $exp = '\s{'.$preceed_space.'}'; + $exp = '[^\s#]' if $preceed_space == 0; + # print "testing $exp\n"; + if($line =~ m/^$exp.*/) + { + if($line =~ m/^\s*@path[0].*/) + { + $depth++; + if(!@path[1]) + { + # print "replacing '$line'\n"; + my $t = @path[0]; + $line =~ s/^(.*?$t[^\s]*).*$/\1 $replacement/g; + # print "now: '$line'\n"; + } + shift @path; + } + } + } + $line =~ s/[\n\t]*$//g; + $ret .= "$line\n"; + } + + return $ret; +} + +sub exec_system_cmd +{ + my $cmd = shift; + print "executing $cmd\n"; + system($cmd) == 0 + or die "system @args failed: $?"; +} + +sub read_file +{ + my $file = shift; + my $trys=0; + my $failed=0; + my @lines; + #print "Attempting open\n"; + if(-e $file) + { + my $worked = open (inputfile, '< '. $file); + if(!$worked) + { + print "******************Failed to read file*************\n"; + } + binmode(inputfile, ":utf8"); + while (!(open (inputfile, '< '. $file)) && $trys<100) + { + print "Trying again attempt $trys\n"; + $trys++; + sleep(1); + } + if($trys<100) + { + #print "Finally worked... now reading\n"; + @lines = ; + close(inputfile); + } + else + { + print "Attempted $trys times. COULD NOT READ FILE: $file\n"; + } + close(inputfile); + } + else + { + print "File does not exist: $file\n"; + } + return \@lines; +} + +exit; \ No newline at end of file