Only resolve .so includes when it's the only thing in a man page

Leaving the rest to be formatted as links to the included man page
instead.

Primary reason for this change is to make it possible to cache formatted
man pages, as they now no longer depend on anything except the raw
source of the page itself.
This commit is contained in:
Yorhel 2025-05-25 14:02:07 +02:00
parent a14f7b9bac
commit 59a7a16c2a
3 changed files with 25 additions and 25 deletions

View file

@ -706,27 +706,6 @@ sub man_nav_($man, $url, $toc, $htmllang) {
}
# Replace .so's in man source with the contents (if available in the same
# package) or with a reference to the other man page.
sub soelim($verid, $src) {
# tix comes with* a custom(?) macro package. But it looks okay even without loading that.
# (* It actually doesn't, the tcllib package appears to have that file, but doesn't '.so' it)
$src =~ s/^\.so man.macros$//mg;
# Other .so's should be handled by html()
$src =~ s{^\.so (.+)$}{
my $path = $1;
my $name = (reverse split /\//, $path)[0];
my($man) = $verid ? man_pref_name $name, SQL 'v.id =', $verid : ();
$man->{name}
# Recursive soelim, but the second call gets $verid=0 so we don't keep checking the database
? soelim(0, fu->SQL('SELECT content FROM contents WHERE id =', $man->{content})->val)
: ".in -10\n.sp\n\[\[\[MANNEDINCLUDE$path\]\]\]"
}emg;
$src;
}
sub man_page($man, $url) {
fu->set_lastmod($man->{released});
@ -739,7 +718,17 @@ sub man_page($man, $url) {
fu->done;
}
my $fmt = ManUtils::html ManUtils::fmt soelim $man->{verid}, $content;
# Find out of this is a redirect-type man page, i.e. one containing only a single .so and no other content.
my $follow;
if (length($content) < 2048 && (() = $content =~ /^\.so/mg) == 1) {
my $data = $content =~ s/^\.\\".*//rmg;
if ($data =~ m{^\s*\.so (?:[^\s]*/)?([^\s/]+)\s*$}s) {
($follow) = man_pref_name $1, SQL 'v.id =', $man->{verid};
$content = fu->SQL('SELECT content FROM contents WHERE id =', $follow->{content})->val if $follow;
}
}
my $fmt = ManUtils::html ManUtils::fmt $content;
if($url->{fmt} eq 'txt') {
# TODO: The 'txt' format is kind of broken right now as it includes our HTML formatting codes.
# This feature is a WIP and not advertised at the moment, anyway.
@ -752,7 +741,6 @@ sub man_page($man, $url) {
# Prefix links to other man pages with the current system, to ensure we
# grab the most relevant man page.
# XXX: This is a hack, prefixing is better done directly in ManUtils.
my $sys = sysbyid->{$man->{system}}{short};
$fmt =~ s{<a href="/}{<a href="/man/$sys/}g;
@ -776,6 +764,13 @@ sub man_page($man, $url) {
li_ sub { a_ href => "/loc/$hash", 'locations' };
}
};
em_ sub {
txt_ 'Displaying the included man page: ';
a_ href => $url->set(
man => $follow->{name}, section => $follow->{section},
system => sysbyid->{$man->{system}}{short}, shorthash => shorthash_to_hex $follow->{shorthash}
), "$follow->{name}($follow->{section})";
} if $follow;
pre_ @htmllang, sub { lit_ $fmt };
};
}