I introduced a tag in the spirit of <toc>
. I use <title-search this_or_that_search_text>
. Processed like so:
sub WikiToHTML { ... $pageText =~ s/\<title-search\s+(.*?)\>/&PageList(&SearchTitle($1))/ige; while (@HeadingNumbers) { ... }(I'm not sure where the "macro" processing should be placed, but it works for me where I put it now)
The other two subs are defined like so:
sub PageList { my $pagename; my $pageListing; foreach $pagename (@_) { $pageListing .= ".... " if ($pagename =~ m|/|); $pageListing .= &GetPageLink($pagename) . "<br>\n"; } return $pageListing; }and
sub SearchTitle { my ($string) = @_; my ($name, @found); foreach $name (&AllPagesList()) { push(@found, $name) if ($name =~ /$string/i); } return @found; }The
SearchTitle
function assumes you use underscores in the search for pages with spaces in their names.
You might recognize the code inside PageList
there? To not do too much of the same processing in several places I did the following refactoring:
sub PrintPageList { print "<h2>", Ts('%s pages found:', ($#_ + 1)), "</h2>\n"; print &PageList(@_); }A reasonable refactoring in any case imho.
I just did a crude hack that works on my site. A more careful approach might want to make the processing of the title-search macro optional through config variables and such...
-- PEZ
See also: /EmbeddedBacklinks