}
} #}}}
+# Massage the recorded state of internal links so that:
+# - it matches the actually generated links, rather than the links as written
+# in the pages' source
+# - backlinks are consistent in all cases
sub scan (@) { #{{{
my %params=@_;
my $page=$params{page};
elsif (! istranslatable($page) && ! istranslation($page)) {
foreach my $destpage (@{$links{$page}}) {
if (istranslatable($destpage)) {
- map {
- push @{$links{$page}}, $destpage . '.' . $_;
- } (keys %{$config{po_slave_languages}});
+ # make sure any destpage's translations has
+ # $page in its backlinks
+ push @{$links{$page}},
+ values %{otherlanguages($destpage)};
}
}
}
if ($template->query(name => "istranslatable")) {
$template->param(istranslatable => istranslatable($page));
}
+ if ($template->query(name => "HOMEPAGEURL")) {
+ $template->param(homepageurl => homepageurl($page));
+ }
if ($template->query(name => "otherlanguages")) {
$template->param(otherlanguages => [otherlanguagesloop($page)]);
map add_depends($page, $_), (values %{otherlanguages($page)});
resettranslationscache();
# Trigger a wiki refresh.
require IkiWiki::Render;
+ # without preliminary saveindex/loadindex, refresh()
+ # complains about a lot of uninitialized variables
+ IkiWiki::saveindex();
+ IkiWiki::loadindex();
IkiWiki::refresh();
IkiWiki::saveindex();
}
} #}}}
+# As we're previewing or saving a page, the content may have
+# changed, so tell the next filter() invocation it must not be lazy.
sub editcontent () { #{{{
my %params=@_;
- # as we're previewing or saving a page, the content may have
- # changed, so tell the next filter() invocation it must not be lazy
+
unsetalreadyfiltered($params{page}, $params{page});
return $params{content};
} #}}}
# | Injected functions
# `----
+# Implement po_link_to=current
sub mybestlink ($$) { #{{{
my $page=shift;
my $link=shift;
my $res=$origsubs{'bestlink'}->($page, $link);
- if (length $res) {
- if ($config{po_link_to} eq "current"
- && istranslatable($res)
- && istranslation($page)) {
- return $res . "." . lang($page);
- }
- else {
- return $res;
- }
+ if (length $res
+ && $config{po_link_to} eq "current"
+ && istranslatable($res)
+ && istranslation($page)) {
+ return $res . "." . lang($page);
}
- return "";
+ return $res;
} #}}}
sub mybeautify_urlpath ($) { #{{{
my $page=shift;
my $ext=shift;
- if (istranslation($page)) {
+ if (istranslation($page) || istranslatable($page)) {
my ($masterpage, $lang) = (masterpage($page), lang($page));
if (! $config{usedirs} || $masterpage eq 'index') {
return $masterpage . "." . $lang . "." . $ext;
return $masterpage . "/index." . $lang . "." . $ext;
}
}
- elsif (istranslatable($page)) {
- if (! $config{usedirs} || $page eq 'index') {
- return $page . "." . $config{po_master_language}{code} . "." . $ext;
- }
- else {
- return $page . "/index." . $config{po_master_language}{code} . "." . $ext;
- }
- }
return $origsubs{'targetpage'}->($page, $ext);
} #}}}
# workaround hard-coded /index.$config{htmlext} in IkiWiki::urlto()
if (! length $to
&& $config{po_link_to} eq "current"
- && istranslation($from)
&& istranslatable('index')) {
return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}");
}
my $file=$pagesources{$page};
- if (! defined $file
- || (defined pagetype($file) && pagetype($file) eq 'po')
- || $file =~ /\.pot$/) {
- return 0;
- }
+ return 0 unless defined $file;
+ return 0 if (defined pagetype($file) && pagetype($file) eq 'po');
+ return 0 if $file =~ /\.pot$/;
return pagespec_match($page, $config{po_translatable_pages});
} #}}}
my $page=shift;
my $file=$pagesources{$page};
- if (! defined $file) {
- return IkiWiki::FailReason->new("no file specified");
- }
- if (! defined $file
- || ! defined pagetype($file)
- || ! pagetype($file) eq 'po'
- || $file =~ /\.pot$/) {
- return 0;
- }
+ return 0 unless (defined $file
+ && defined pagetype($file)
+ && pagetype($file) eq 'po');
+ return 0 if $file =~ /\.pot$/;
my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
- if (! defined $masterpage || ! defined $lang
- || ! (length($masterpage) > 0) || ! (length($lang) > 0)
- || ! defined $pagesources{$masterpage}
- || ! defined $config{po_slave_languages}{$lang}) {
- return 0;
- }
+ return 0 unless (defined $masterpage && defined $lang
+ && length $masterpage && length $lang
+ && defined $pagesources{$masterpage}
+ && defined $config{po_slave_languages}{$lang});
return ($masterpage, $lang) if istranslatable($masterpage);
} #}}}
sub islanguagecode ($) { #{{{
my $code=shift;
+
return ($code =~ /^[a-z]{2}$/);
} #}}}
sub pofiles ($) { #{{{
my $masterfile=shift;
+
return map pofile($masterfile, $_), (keys %{$config{po_slave_languages}});
} #}}}
} @ret;
} #}}}
+sub homepageurl (;$) { #{{{
+ my $page=shift;
+
+ return urlto('', $page);
+} #}}}
# ,----
# | PageSpec's