Seasonal posts

code • January 29, 2015

After flipping through past posts, I realized that my lush green static map didn’t match wintery posts. For example, Christmas day hike. It’s winter, nothing is green. Everything is white and then gray and then cold and then sometimes sad. So I needed a map style to match winter (minus the sad).

Summer and spring map style Winter map style

Default style on the left, winter style on the right. (Read more about my Jekyll-generated Mapbox static maps.)

At first I created an in-post variable that could swap out my default map ID {% if page.mapid %}, but that would need upkeep. I decided to evaluate the post’s month and assign a map ID based on the season – the post’s month.

First, I needed to capture the post’s month. (It seems like I can only grab this value as a string.)

{% capture month %}{{ | date: "%m"}}{% endcapture %}

Next, I evaluated the month – December, January, February, and March will receive the winter map ID from my config, while other months will receive my default map ID.

{% if month == "12" or month == "01" or month == "02" or month == "03" %}
{% else %}
  {{ site.mapid }}
{% endif %}

I dropped this statement in my static map call and that was it! All my past winter month posts switched to my winter map ID. A fall map style may come in handy, but I’ll stick with just two for right now. See the full code.

By the way, for my map styles I’m using Mapbox Outdoors and Winter Wonderland both with small tweaks to remove the labels.

Keep reading code