From b9002a2bc2fd8ee833eb1c272966c7f339c08aec Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 1 Jan 2011 22:39:36 +0100 Subject: [PATCH] inline: improve feed title and description management Move feed title generation outside of genfeed(), and allow it to be customized by an appropriate parameter to the inline directive. The feed description is also extended to base it on the page description (if present), and defaulting to a configurable union of wiki name and page title otherwise (rather than hard-coding it to the wiki name). --- IkiWiki/Plugin/inline.pm | 33 +++++++++++++++++++++++++------ doc/ikiwiki/directive/inline.mdwn | 6 +++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 77634066b..5dc4fb68c 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -86,6 +86,13 @@ sub getsetup () { safe => 1, rebuild => 0, }, + feed_desc_fmt => { + type => "string", + example => '%1$s\'s %2$s', + description => "format string for the default feed description, using the wiki name and page title as parameters", + safe => 1, + rebuild => 1, + }, } sub checkconfig () { @@ -169,12 +176,25 @@ sub preprocess_inline (@) { if (! exists $params{feedshow} && exists $params{show}) { $params{feedshow}=$params{show}; } - my $desc; + + my ($page, $desc, $feedtitle); + $page = $params{page}; + if (exists $params{title}) { + $feedtitle = $params{title}; + } elsif ($page =~ m!^/?index(?:$|\.)!) { + $feedtitle = $config{wikiname}; + } else { + $feedtitle = pagetitle(basename($page)); + } if (exists $params{description}) { $desc = $params{description} - } - else { + } elsif ($pagestate{$page}{meta} && $pagestate{$page}{meta}{description}) { + $desc = $pagestate{$page}{meta}{description}; + } elsif ($page =~ m!^/?index(?:$|\.)!) { $desc = $config{wikiname}; + } else { + my $descfmt = defined $config{feed_desc_fmt} ? $config{feed_desc_fmt} : '%1$s\'s %2$s'; + $desc = sprintf($descfmt, $config{wikiname}, $feedtitle); } my $actions=yesno($params{actions}); if (exists $params{template}) { @@ -447,7 +467,7 @@ sub preprocess_inline (@) { if (! $params{preview}) { writefile($rssp, $config{destdir}, genfeed("rss", - $config{url}."/".$rssp, $desc, $params{guid}, $params{page}, @feedlist)); + $config{url}."/".$rssp, $feedtitle, $desc, $params{guid}, $params{page}, @feedlist)); $toping{$params{destpage}}=1 unless $config{rebuild}; $feedlinks{$params{destpage}}.=qq{}; } @@ -457,7 +477,7 @@ sub preprocess_inline (@) { will_render($params{destpage}, $atomp); if (! $params{preview}) { writefile($atomp, $config{destdir}, - genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{page}, @feedlist)); + genfeed("atom", $config{url}."/".$atomp, $feedtitle, $desc, $params{guid}, $params{page}, @feedlist)); $toping{$params{destpage}}=1 unless $config{rebuild}; $feedlinks{$params{destpage}}.=qq{}; } @@ -596,6 +616,7 @@ sub absolute_urls ($$) { sub genfeed ($$$$$@) { my $feedtype=shift; my $feedurl=shift; + my $feedtitle=shift; my $feeddesc=shift; my $guid=shift; my $page=shift; @@ -669,7 +690,7 @@ sub genfeed ($$$$$@) { my $template=template_depends($feedtype."page.tmpl", $page, blind_cache => 1); $template->param( - title => $page ne "index" ? pagetitle($page) : $config{wikiname}, + title => $feedtitle, wikiname => $config{wikiname}, pageurl => $url, content => $content, diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn index 22c18d9a1..5a2b911d0 100644 --- a/doc/ikiwiki/directive/inline.mdwn +++ b/doc/ikiwiki/directive/inline.mdwn @@ -50,7 +50,9 @@ directive. These are the commonly used ones: * `archive` - If set to "yes", only list page titles and some metadata, not full contents. * `description` - Sets the description of the rss feed if one is generated. - Defaults to the name of the wiki. + By default this is built from the page description (if present), or + using "wikiname's pagetitle" otherwise. The latter can be configured + by setting `feed_desc_fmt` to the wanted format string. * `skip` - Specify a number of pages to skip displaying. Can be useful to produce a feed that only shows archived pages. * `postform` - Set to "yes" to enable a form to post new pages to a @@ -85,6 +87,8 @@ Here are some less often needed parameters: only shows post titles or the `microblog` template, optimised for microblogging. Note that you should still set `archive=yes` if your custom template does not include the page content. +* `title` - specifies the feed title. By default, the page title is + used, but it can be overridden with this parameter. * `raw` - Rather than the default behavior of creating a blog, if raw is set to "yes", the page will be included raw, without additional markup around it, as if it were a literal part of the source of the -- 2.32.0.93.g670b81a890