Skip to content

Commit

Permalink
Refactored the build program. Ran it.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Nov 30, 2019
1 parent 53f2af8 commit 6a9d355
Show file tree
Hide file tree
Showing 732 changed files with 1,049 additions and 786 deletions.
147 changes: 91 additions & 56 deletions bin/build
Expand Up @@ -21,74 +21,109 @@ my $tt = Template->new({
ENCODING => 'utf8',
});

my @urls;
my @urls = build_constituency_pages($tt, $sch, $url);

foreach my $c ($sch->resultset('Constituency')->all) {
# next unless $c->candidates->count;
my $path = 'c/' . $c->slug_name . '.html';
$tt->process('constituency.tt', { c => $c, url => "$url/$path" }, $path,
{binmode => ':utf8'})
push @urls, build_party_pages($tt, $sch, $url);
push @urls, build_stats_page($tt, $sch, $url);
push @urls, build_static_pages($tt, $sch, $url);

build_sitemap($tt, @urls);

sub build_constituency_pages {
my ($tt, $sch, $url) = @_;
my @return;

foreach my $c ($sch->resultset('Constituency')->all) {
# next unless $c->candidates->count;
my $path = 'c/' . $c->slug_name . '.html';
$tt->process('constituency.tt', { c => $c, url => "$url/$path" }, $path,
{binmode => ':utf8'})
or die $tt->error;

push @return, "$url/$path";
}

$tt->process('constituencies.tt', {
constits => [ $sch->resultset('Constituency')->all ],
url => "$url/c/",
},
'c/index.html', {binmode => ':utf8'})
or die $tt->error;

push @urls, "$url/$path";
push @return, "$url/c/";

return @return;
}

$tt->process('constituencies.tt', {
constits => [ $sch->resultset('Constituency')->all ],
url => "$url/c/",
},
'c/index.html', {binmode => ':utf8'})
or die $tt->error;

push @urls, "$url/c/";

foreach my $p ($sch->resultset('Party')->sort_by_name->all) {
next unless $p->candidates->count;
my $path = 'p/' . $p->slugname . '.html';
$tt->process('party.tt', { p => $p, url => "$url/$path" }, $path,
{binmode => ':utf8'})
sub build_party_pages {
my ($tt, $sch, $url) = @_;
my @return;

foreach my $p ($sch->resultset('Party')->sort_by_name->all) {
next unless $p->candidates->count;
my $path = 'p/' . $p->slugname . '.html';
$tt->process('party.tt', { p => $p, url => "$url/$path" }, $path,
{binmode => ':utf8'})
or die $tt->error;

push @return, "$url/$path";
}

$tt->process('parties.tt', {
parties => [ $sch->resultset('Party')->sort_by_name->all ],
url => "$url/p/",
},
'p/index.html', {binmode => ':utf8'})
or die $tt->error;

# Add later
# push @urls, "$url/$path";
push @return, "$url/p/";

return @return;
}

$tt->process('parties.tt', {
parties => [ $sch->resultset('Party')->sort_by_name->all ],
url => "$url/p/",
},
'p/index.html', {binmode => ':utf8'})
or die $tt->error;
sub build_stats_page {
my ($tt, $sch, $url) = @_;

my $cand_rs = $sch->resultset('Candidate');
my $party_rs = $sch->resultset('Party');
my @party = $party_rs-> all;

# Add later
# push @urls, "$url/p/";

my $cand_rs = $sch->resultset('Candidate');
my $party_rs = $sch->resultset('Party');
my @party = $party_rs-> all;

@party = sort { $b->count_candidates <=> $a->count_candidates } @party;

$tt->process('stats/index.tt', {
num_cands => $cand_rs->count,
num_twit_cands => $cand_rs->filter_tweeting->count,
num_no_twit_cands => $cand_rs->filter_nontweeting->count,
party => \@party,
url => "$url/stats/",
}, 'stats/index.html', { binmode => ':utf8' })
or die $tt->error;;

push @urls, "$url/stats/";

for (qw[index about/index]) {
my ($path, $page) = split m|/|;
$path = '' if $path eq 'index';
$tt->process("$_.tt", { url => "$url/$path" }, "$_.html", { binmode => ':utf8' });

push @urls, "$url/$path";
@party = sort { $b->count_candidates <=> $a->count_candidates } @party;

$tt->process('stats/index.tt', {
num_cands => $cand_rs->count,
num_twit_cands => $cand_rs->filter_tweeting->count,
num_no_twit_cands => $cand_rs->filter_nontweeting->count,
party => \@party,
url => "$url/stats/",
}, 'stats/index.html', { binmode => ':utf8' })
or die $tt->error;;

return "$url/stats/";
}

sub build_static_pages {
my ($tt, $sch, $url) = @_;
my @returns;

for (qw[index about/index]) {
my ($path, $page) = split m|/|;
$path = '' if $path eq 'index';
$tt->process("$_.tt", { url => "$url/$path" }, "$_.html", { binmode => ':utf8' });

push @returns, "$url/$path";
}

return @returns;
}

$tt->process('sitemap.tt', { urls => \@urls }, 'sitemap.xml');
sub build_sitemap {
my ($tt, @urls) = @_;

$tt->process('sitemap.tt', { urls => \@urls }, 'sitemap.xml');

return;
}

#my @redirections = map {
# chomp;
Expand Down
2 changes: 1 addition & 1 deletion docs/about/index.html
Expand Up @@ -190,5 +190,5 @@ <h1>About this site</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:33 30-Nov-2019 -->
<!-- Built at: 11:09:44 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aberavon.html
Expand Up @@ -163,5 +163,5 @@ <h1>Aberavon</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aberconwy.html
Expand Up @@ -157,5 +157,5 @@ <h1>Aberconwy</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aberdeen-north.html
Expand Up @@ -159,5 +159,5 @@ <h1>Aberdeen North</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aberdeen-south.html
Expand Up @@ -160,5 +160,5 @@ <h1>Aberdeen South</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/airdrie-and-shotts.html
Expand Up @@ -161,5 +161,5 @@ <h1>Airdrie and Shotts</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aldershot.html
Expand Up @@ -157,5 +157,5 @@ <h1>Aldershot</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aldridge-brownhills.html
Expand Up @@ -161,5 +161,5 @@ <h1>Aldridge-Brownhills</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/altrincham-and-sale-west.html
Expand Up @@ -159,5 +159,5 @@ <h1>Altrincham and Sale West</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/alyn-and-deeside.html
Expand Up @@ -161,5 +161,5 @@ <h1>Alyn and Deeside</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/amber-valley.html
Expand Up @@ -160,5 +160,5 @@ <h1>Amber Valley</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/angus.html
Expand Up @@ -160,5 +160,5 @@ <h1>Angus</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/arfon.html
Expand Up @@ -160,5 +160,5 @@ <h1>Arfon</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/argyll-and-bute.html
Expand Up @@ -160,5 +160,5 @@ <h1>Argyll and Bute</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/arundel-and-south-downs.html
Expand Up @@ -158,5 +158,5 @@ <h1>Arundel and South Downs</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/ashfield.html
Expand Up @@ -162,5 +162,5 @@ <h1>Ashfield</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/ashford.html
Expand Up @@ -161,5 +161,5 @@ <h1>Ashford</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/ashton-under-lyne.html
Expand Up @@ -158,5 +158,5 @@ <h1>Ashton-under-Lyne</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/aylesbury.html
Expand Up @@ -157,5 +157,5 @@ <h1>Aylesbury</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/ayr-carrick-and-cumnock.html
Expand Up @@ -160,5 +160,5 @@ <h1>Ayr, Carrick and Cumnock</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/banbury.html
Expand Up @@ -157,5 +157,5 @@ <h1>Banbury</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:34 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/banff-and-buchan.html
Expand Up @@ -157,5 +157,5 @@ <h1>Banff and Buchan</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/barking.html
Expand Up @@ -161,5 +161,5 @@ <h1>Barking</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/barnsley-central.html
Expand Up @@ -163,5 +163,5 @@ <h1>Barnsley Central</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/barnsley-east.html
Expand Up @@ -161,5 +161,5 @@ <h1>Barnsley East</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/barrow-and-furness.html
Expand Up @@ -161,5 +161,5 @@ <h1>Barrow and Furness</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/basildon-and-billericay.html
Expand Up @@ -161,5 +161,5 @@ <h1>Basildon and Billericay</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/basingstoke.html
Expand Up @@ -161,5 +161,5 @@ <h1>Basingstoke</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/bassetlaw.html
Expand Up @@ -160,5 +160,5 @@ <h1>Bassetlaw</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/bath.html
Expand Up @@ -158,5 +158,5 @@ <h1>Bath</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/batley-and-spen.html
Expand Up @@ -162,5 +162,5 @@ <h1>Batley and Spen</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/battersea.html
Expand Up @@ -158,5 +158,5 @@ <h1>Battersea</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>
2 changes: 1 addition & 1 deletion docs/c/beaconsfield.html
Expand Up @@ -158,5 +158,5 @@ <h1>Beaconsfield</h1>
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools --> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56165a02d0fe210e"></script>
</body>
<!-- Built at: 09:54:23 30-Nov-2019 -->
<!-- Built at: 11:09:35 30-Nov-2019 -->
</html>

0 comments on commit 6a9d355

Please sign in to comment.