Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twelve Days support #39

Merged
merged 5 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions danceradvent/lib/danceradvent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,19 @@ get '/:year' => sub {

my $articles = _articles_viewable(params->{year});

# Fetch the itles of all the posts so the template can provide a list
# of named posts. Exclude the today's article, to keep the mistery ;)
# Fetch the titles of all the posts so the template can provide a list
# of named posts. Exclude the today's article, to keep the mystery ;)
my $today = DateTime->today();
my @all_entries
= grep { $_->{issued} != $today } _get_entries(params->{year});

# If this year doesn't have an article for day 1, but does for day 13, then
# it's a cut-down "Twelve Days of Dancer" year where we didn't have enough
# articles to fill the whole thing, so we use a different template in that
# case.
my $template = _article_exists(params->{year}, 1)
? 'index' : 'index-twelvedays';

# Assemble a list of other years which have viewable articles for links:
my @other_years;
for my $year (config->{start_year} .. (localtime)[5] + 1900) {
Expand All @@ -77,7 +84,7 @@ get '/:year' => sub {
grep { $_->{viewable} } @{ _articles_viewable($year) };
}

return template 'index' => {
return template $template => {
year => params->{year},
articles => $articles,
all_entries => \@all_entries,
Expand Down Expand Up @@ -152,6 +159,13 @@ sub _articles_viewable {

my @articles;

# If this year is a twelve days of Dancer cut-down year, i.e. we have no
# article for the 1st but do for the 13th, then exclude the previous 12
# days:
if (!_article_exists($year, 1) && _article_exists($year, 13)) {
@days = grep { $_ >= 13 } @days;
}

for my $day (@days) {

push @articles, {
Expand Down
45 changes: 45 additions & 0 deletions danceradvent/views/index-twelvedays.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

<h1>Perl Dancer Advent Calendar [% year %]</h1>

<h2>The Twelve Days of Dancer</h2>

<p>
Happy Christmas, and welcome to the Dancer team's advent calendar for
[% year %]! We've gone for a cut-down "twelve days of Dancer" approach due to
a shortage of quality posts and time - we'd rather put out fewer, better
articles than just a load of filler.
</p>

[% IF other_years.size %]
<p>Other years:
[% FOR otheryear IN other_years %]
<a href="/[% otheryear %]">[% otheryear %]</a>
[% END %]
</p>
[% END %]


<div class="advent-calendar">
[% FOR a IN articles %]
[% IF a.viewable -%]
<a class="advent-day" href="/[% year %]/[% a.day %]">[% a.day %]</a>
[%- ELSE -%]
<span class="advent-day">&nbsp;</span>
[%- END %]
[% END %]
</div>


[% IF all_entries.size %]
<h2>Full article list</h2>
<p>
Here's a full list of the previous posts with their titles:
</p>
<ol>
[% FOR a IN all_entries %]
<li><a href="[% year %]/[% a.issued.day %]">[% a.title %]</a></li>
[% END %]
</ol>
[% END %]