Author: kake Date: 2012-08-17 16:36:57 +0100 (Fri, 17 Aug 2012) New Revision: 1433
Added: trunk/t/410_meta_description.t Modified: trunk/Changes trunk/MANIFEST trunk/lib/OpenGuides.pm trunk/lib/OpenGuides/Utils.pm trunk/templates/header.tt Log: Added meta descriptions to headers of map and list index pages.
Modified: trunk/Changes =================================================================== --- trunk/Changes 2012-07-29 19:58:36 UTC (rev 1432) +++ trunk/Changes 2012-08-17 15:36:57 UTC (rev 1433) @@ -5,6 +5,7 @@
0.70 ? Updated URLs for Leaflet JavaScript and CSS. + Added meta descriptions to headers of map and list index pages.
0.69 07 July 2012 The output of the "show_missing_metadata" action is now alphabetised.
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2012-07-29 19:58:36 UTC (rev 1432) +++ trunk/MANIFEST 2012-08-17 15:36:57 UTC (rev 1433) @@ -130,6 +130,7 @@ t/407_navbar_placement.t t/408_google_analytics.t t/409_custom_header.t +t/410_meta_description.t t/500_http_response_codes.t t/501_display_node.t t/502_display_diffs.t
Modified: trunk/lib/OpenGuides/Utils.pm =================================================================== --- trunk/lib/OpenGuides/Utils.pm 2012-07-29 19:58:36 UTC (rev 1432) +++ trunk/lib/OpenGuides/Utils.pm 2012-08-17 15:36:57 UTC (rev 1433) @@ -386,6 +386,49 @@ return %data; }
+=item B<get_index_page_description> + + $tt_vars{page_description} = + OpenGuides::Utils->get_index_page_description( + format => "map", + criteria => [ type => "locale", value => "croydon" ], + ); + +Returns a sentence that can be used as a summary of what's shown on an +index page. + +=cut + +sub get_index_page_description { + my ( $class, %args ) = @_; + my $desc = ( $args{format} eq "map" ) ? "Map" : "List"; + $desc .= " of all our pages"; + + my ( @cats, @locs ); + foreach my $criterion ( @{$args{criteria}} ) { + my ( $type, $name ) = ( $criterion->{type}, $criterion->{name} ); + if ( $type eq "category" ) { + $name =~ s/Category //; + push @cats, $name; + } else { + $name =~ s/Locale //; + push @locs, $name; + } + } + + if ( scalar @cats ) { + $desc .= " labelled with: " . join( ", ", @cats ); + if ( scalar @locs ) { + $desc .= ", and"; + } + } + if ( scalar @locs ) { + $desc .= " located in: " . join( ", ", @locs ); + } + $desc .= "."; + return $desc; +} + =item B<detect_redirect>
$redir = OpenGuides::Utils->detect_redirect( content => "foo" );
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2012-07-29 19:58:36 UTC (rev 1432) +++ trunk/lib/OpenGuides.pm 2012-08-17 15:36:57 UTC (rev 1433) @@ -1060,6 +1060,13 @@ $tt_vars{criteria} = @criteria; $tt_vars{not_editable} = 1; } + + $tt_vars{page_description} = + OpenGuides::Utils->get_index_page_description( + format => $args{format} || "", + criteria => @criteria, + ); + my $feed_base = $self->config->script_url . $self->config->script_name . "?action=index"; foreach my $criterion ( @criteria ) {
Added: trunk/t/410_meta_description.t =================================================================== --- trunk/t/410_meta_description.t (rev 0) +++ trunk/t/410_meta_description.t 2012-08-17 15:36:57 UTC (rev 1433) @@ -0,0 +1,86 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite not available ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not available"; +} + +plan tests => 12; + +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->use_leaflet( 1 ); +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Write a node and give it a category and locale. +OpenGuides::Test->write_data( guide => $guide, node => "Dog And Bull", + summary => "A pub.", categories => "Pubs", locales => "Croydon", + return_output => 1 ); + +# Display the category and locale indexes individually and together, +# as maps and lists, and check that the header shows up. + +# Category list. +my $output = $guide->show_index( cat => "pubs", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Category index has meta description" ); +like( $output, + qr/List of all our pages labelled with: Pubs./, + "...with suitable text." ); + +# Locale list. +$output = $guide->show_index( loc => "croydon", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Locale index has meta description" ); +like( $output, + qr/List of all our pages located in: Croydon./, + "...with suitable text." ); + +# Category + locale list. +$output = $guide->show_index( cat => "pubs", loc => "croydon", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Category+locale index has meta description" ); +like( $output, + qr/List of all our pages labelled with: Pubs, and located in: Croydon./, + "...with suitable text." ); + +# Category map. +$output = $guide->show_index( cat => "pubs", format => "map", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Category map has meta description" ); +like( $output, + qr/Map of all our pages labelled with: Pubs./, + "...with suitable text." ); + +# Locale map. +$output = $guide->show_index( loc => "croydon", format => "map", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Locale map has meta description" ); +like( $output, + qr/Map of all our pages located in: Croydon./, + "...with suitable text." ); + +# Category + locale map. +$output = $guide->show_index( cat => "pubs", loc => "croydon", format => "map", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "meta", { name => "description" }, + "Category+locale map has meta description" ); +like( $output, + qr/Map of all our pages labelled with: Pubs, and located in: Croydon./, + "...with suitable text." );
Modified: trunk/templates/header.tt =================================================================== --- trunk/templates/header.tt 2012-07-29 19:58:36 UTC (rev 1432) +++ trunk/templates/header.tt 2012-08-17 15:36:57 UTC (rev 1433) @@ -15,9 +15,13 @@ [% IF contact_email %] <link rev="made" href="mailto:[% contact_email %]" /> [% END %] - [% IF summary %] + + [% IF page_description %] + <meta name="description" content="[% page_description %]" /> + [% ELSIF summary %] <meta name="description" content="[% summary %]" /> [% END %] + [% IF (categories.size AND categories.size > 0) OR (locales.size AND locales.size > 0) %] <meta name="keywords" content="[% IF categories.size AND