]> git.proxmox.com Git - pve-docs.git/commitdiff
scan-adoc-refs: factor out register_title
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 10 Oct 2016 06:25:43 +0000 (08:25 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 10 Oct 2016 07:11:44 +0000 (09:11 +0200)
and try to substitute macros and urls.

scan-adoc-refs

index 6563c3534c10041e5f28e050698a13a54a4e582e..96f518294bbb8706780b854cca131b97b12d09a7 100755 (executable)
@@ -89,6 +89,17 @@ sub register_blockid {
     }
 }
 
+sub register_title {
+    my ($filename, $env, $doctype, $title) = @_;
+
+    # fixme: what about other macros?
+    $title =~ s/\{pve\}/Proxmox VE/g;
+    $title =~ s!http://\S+\[(.*?)\]!$1!g;
+
+    $fileinfo->{titles}->{$env}->{$filename} = $title;
+    $fileinfo->{doctype}->{$env}->{$filename} = $doctype;
+}
+
 sub scan_adoc_file {
     my ($filename) = @_;
 
@@ -123,17 +134,13 @@ sub scan_adoc_file {
            next if defined($title);
 
            if ($line =~ m/^=====+$/) {
-               $fileinfo->{titles}->{$e}->{$filename} = $env_last_line->{$e};
-               $fileinfo->{doctype}->{$e}->{$filename} = 0;
+               register_title($filename, $e, 0, $env_last_line->{$e});
            } elsif ($line =~ m/^-----+$/) {
-               $fileinfo->{titles}->{$e}->{$filename} = $env_last_line->{$e};
-               $fileinfo->{doctype}->{$e}->{$filename} = 1;
+               register_title($filename, $e, 1, $env_last_line->{$e});
            } elsif ($line =~ m/^= +(\S.*?)( +=)?$/) {
-               $fileinfo->{titles}->{$e}->{$filename} = $1;
-               $fileinfo->{doctype}->{$e}->{$filename} = 0;
+               register_title($filename, $e, 0, $1);
            } elsif ($line =~ m/^== +(\S.*?)( +==)?$/) {
-               $fileinfo->{titles}->{$e}->{$filename} = $1;
-               $fileinfo->{doctype}->{$e}->{$filename} = 1;
+               register_title($filename, $e, 1, $1);
            }
 
            $env_last_line->{$e} = $line;
@@ -206,7 +213,6 @@ foreach my $e (@$start_env) {
        my $fn = resolve_link_target($e, $blockid_hash->{$blockid});
        if ($e eq 'wiki') {
            my $title = $fileinfo->{titles}->{$e}->{$fn};
-           $title =~ s/\{pve\}/Proxmox VE/g;
            $title =~ s/\s/_/g;
            die "found not title for '$fn' in env '$e'" if !$title;
            $fileinfo->{blockid_target}->{$e}->{$blockid} = "link:/wiki/$title#$blockid";