From: Alan T. DeKok Date: Tue, 29 Jan 2019 16:03:19 +0000 (-0500) Subject: fix it so that relative file links work X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa2da6479a25afe824bbd74a447664e14ff2a91b;p=thirdparty%2Ffreeradius-server.git fix it so that relative file links work --- diff --git a/Makefile b/Makefile index ef5574aefde..5ad59029278 100644 --- a/Makefile +++ b/Makefile @@ -363,7 +363,7 @@ asciidoc/%.adoc: raddb/%.md asciidoc/%.adoc: raddb/% @echo ADOC $^ @mkdir -p $(dir $@) - @./scripts/asciidoc/conf2adoc -a ${top_srcdir}/asciidoc < $^ > $@ + @./scripts/asciidoc/conf2adoc -a ${top_srcdir}/asciidoc -o $@ < $^ asciidoc/%.html: asciidoc/%.adoc @echo HTML $^ diff --git a/scripts/asciidoc/conf2adoc b/scripts/asciidoc/conf2adoc index 436f1c96345..afeb12d4e5a 100755 --- a/scripts/asciidoc/conf2adoc +++ b/scripts/asciidoc/conf2adoc @@ -6,13 +6,14 @@ # # use File::Basename; +use File::Spec; use Getopt::Std; $was_raw = 0; $raw = 0; $blank = 0; -getopts('a:'); +getopts('a:o:'); $script_dir = dirname(__FILE__); $filename = "$script_dir/links.txt"; @@ -39,7 +40,13 @@ $links{"mods-available/"} = "$opt_a/mods-available/README.adoc"; sub process_file { my $input = shift; - my $output = shift; + my $output_file = shift; + + if (!defined $output_file) { + $output = STDOUT; + } else { + open $output, ">$output_file" or die "Failed creating $output_file: $!\n"; + } while (<$input>) { # @@ -147,6 +154,21 @@ sub process_file { if ($links{$key} =~ /^http/) { $link = "`link:" . $links{$key} . "[" . $key . "]`"; + + } elsif ($links{$key} =~ /^$opt_a/) { + # + # Link to the *relative* path for the file. + # Note that we're passed "-a foo/asciidoc", + # and also an output file of "asciidoc/bar.adoc" + # So we need to strip out one level of "asciidoc/" + # + my $absdir = dirname($opt_a . "/" . $output_file); + $absdir =~ s,asciidoc/asciidoc,asciidoc/,; + + my $relative = File::Spec->abs2rel($links{$key}, $absdir); + + $link = "link:" . $relative . "[" . $key . "]"; + } else { $link = "<<" . $links{$key} . "," . $key . ">>"; } @@ -192,4 +214,4 @@ if (!defined $opt_a) { $opt_a = ""; } -process_file(STDIN, STDOUT); +process_file(STDIN, $opt_o);