From ec0a4cb09dfca65ff17619dba6d12e57bf0a22b5 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Sun, 21 Oct 2018 14:40:43 +0100 Subject: [PATCH] Add page titles --- bin/build | 36 +++++++++++++++++++++++++----------- views/body.haml | 2 +- views/candidate.haml | 2 +- views/candidates.haml | 2 +- views/district.haml | 2 -- views/election.haml | 2 +- views/electionsummary.haml | 2 -- views/guides.haml | 2 +- views/layout.haml | 2 +- views/parliament.haml | 2 +- views/resultsdistrict.haml | 2 -- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/bin/build b/bin/build index f33d716..4777a00 100755 --- a/bin/build +++ b/bin/build @@ -5,10 +5,16 @@ require_relative '../lib/helpers' require 'pp' def gen_info_pages - Petrify.page('about', 'about') - Petrify.page('guides', 'guides') - Petrify.page(%w(guides how-the-parliament-election-works), 'parliament') - Petrify.page(%w(guides how-the-council-election-works), 'election') + Petrify.page('about', 'about', { page_title: "About this website" }) + Petrify.page('guides', 'guides', { page_title: "Guides"} ) + Petrify.page( + %w(guides how-the-parliament-election-works), + 'parliament', + { page_title: "How parliamentary elections work"}) + Petrify.page( + %w(guides how-the-council-election-works), + 'election', + { page_title: "How council elections work" }) end def gen_bodies_pages @@ -16,7 +22,8 @@ def gen_bodies_pages Body.each do |b| locals = { body: b, - districts: District.all(:body => b, :order => [:name]) + districts: District.all(:body => b, :order => [:name]), + page_title: b.name } locals['elections'] = repository(:default).adapter.select(" @@ -43,7 +50,8 @@ def gen_bodies_pages b.districts.each do |d| locals = { district: d, - body: b + body: b, + page_title: "#{d.name} #{d.body.district_name}, #{d.body.name}" } Petrify.page(['bodies', b.slug, b.districts_name, d.slug], 'district', locals) end @@ -52,14 +60,17 @@ end def gen_candidates_pages # Candidate index - locals = { candidates: Candidate.all(:order => [ :surname, :forenames ]) } + locals = { + candidates: Candidate.all(:order => [ :surname, :forenames ]), + page_title: "Candidates" } Petrify.page('candidates', 'candidates', locals) # Candidate pages # FIXME: What do we do about deleted candidates/redirects? Candidate.each do |c| locals = { - candidate: c + candidate: c, + page_title: c.name } locals['candidacies'] = repository(:default).adapter.select(" @@ -105,7 +116,8 @@ def gen_elections_pages election: Election.first(:body => e.body, :d => e.d), elections_for_this_body: Election.all(:body => e.body, :order => [:d]), total_seats: Candidacy.sum(:seats, :election => e), - total_votes: Candidacy.sum(:votes, :election => e) + total_votes: Candidacy.sum(:votes, :election => e), + page_title: "#{e.body.name} #{e.kind} #{long_date(e.d)}" } # There's got to be a better way to do this, either with SQL or Datamapper @@ -154,7 +166,8 @@ def gen_elections_pages total_candidates: Candidacy.count(:district => d, :election => e), total_seats: total_seats, districts_in_this_election: e.candidacies.districts, - poll: poll + poll: poll, + page_title: "#{d.name} #{d.body.district_name} results, #{d.body.name} election #{short_date(e.d)}" } locals['share_message'] = nil @@ -197,7 +210,8 @@ end def gen_homepage locals = { future_elections: Election.future, - past_elections: Election.past + past_elections: Election.past, + page_title: "" } Petrify.page('.', 'index', locals) end diff --git a/views/body.haml b/views/body.haml index 5f95173..0484bf5 100644 --- a/views/body.haml +++ b/views/body.haml @@ -1,4 +1,4 @@ -%h1= page_title = body.name +%h1= body.name %h2 Elections diff --git a/views/candidate.haml b/views/candidate.haml index a7fe8fc..022b50b 100644 --- a/views/candidate.haml +++ b/views/candidate.haml @@ -2,7 +2,7 @@ %a{ :href => "/candidates" } « All candidates -%h1= page_title = candidate.name +%h1= candidate.name %h2 Elections contested diff --git a/views/candidates.haml b/views/candidates.haml index 2c9343f..6acaeec 100644 --- a/views/candidates.haml +++ b/views/candidates.haml @@ -1,4 +1,4 @@ -%h1= page_title = "Candidates" +%h1= "Candidates" %nav.letter_index - ("A".."Z").each do |letter| diff --git a/views/district.haml b/views/district.haml index a4bf1be..aaffe53 100644 --- a/views/district.haml +++ b/views/district.haml @@ -1,5 +1,3 @@ -- page_title = "#{district.name} #{district.body.district_name}, #{district.body.name}" - %nav %a{ :href => "/bodies/#{district.body.slug}" } «  diff --git a/views/election.haml b/views/election.haml index 7fbd89f..0593ecb 100644 --- a/views/election.haml +++ b/views/election.haml @@ -1,7 +1,7 @@ %nav %a{ :href => '/guides'} « Guides -%h1= @page_title = "How council elections work" +%h1 How council elections work %p Every four years you get to choose your local councillors and help to decide who runs diff --git a/views/electionsummary.haml b/views/electionsummary.haml index 4d5702f..f7e7907 100644 --- a/views/electionsummary.haml +++ b/views/electionsummary.haml @@ -1,5 +1,3 @@ -- page_title = "#{election.body.name} #{election.kind} #{long_date(election.d)}" - %nav %a{ :href => "/bodies/#{election.body.slug}" } « diff --git a/views/guides.haml b/views/guides.haml index b0e1bb5..1c6b5dd 100644 --- a/views/guides.haml +++ b/views/guides.haml @@ -1,4 +1,4 @@ -%h1= @page_title = "Guides" +%h1 Guides %ul %li diff --git a/views/layout.haml b/views/layout.haml index 38ebf6a..99acfe4 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -1,7 +1,7 @@ !!!5 %html %head - %title= @page_title ? @page_title + " - Sutton Elections" : "Sutton Elections - Your guide to voting and election results in the London Borough of Sutton" + %title= page_title ? page_title + " · Sutton Elections" : "Sutton Elections · Your guide to voting and election results in the London Borough of Sutton" %link{ :rel => 'stylesheet', :type => 'text/css', :href => '/style.css' } %meta{ :name => 'referrer', :content => 'no-referrer' } %meta{ :name => 'viewport', :content => 'width=device-width, initial-scale=1' } diff --git a/views/parliament.haml b/views/parliament.haml index 365e5e7..c39e48a 100644 --- a/views/parliament.haml +++ b/views/parliament.haml @@ -1,7 +1,7 @@ %nav %a{ :href => '/guides'} « Guides -%h1= @page_title = "How parliamentary elections work" +%h1 How parliamentary elections work %p In parliament elections you can vote for your local member of parliament (MP) and help to decide who governs the UK. diff --git a/views/resultsdistrict.haml b/views/resultsdistrict.haml index 3708e01..809e8ea 100644 --- a/views/resultsdistrict.haml +++ b/views/resultsdistrict.haml @@ -1,5 +1,3 @@ -- page_title = "#{district.name} #{district.body.district_name} results, #{body.name} election #{short_date(election.d)}" - %nav - if districts_in_this_election.size > 1 - district_index = districts_in_this_election.index(district)