Header is only valid if it's the very first thing in the file - even one blank line before the first '---' breaks Jekyll - so you can simplify and tighten up this logic.