--- # use liquid tags and filters to remove non-license comments and blank lines outside of
tags # simplified from jekyll-compress-html: https://github.com/penibelst/jekyll-compress-html --- {% capture _LINE_FEED %} {% endcapture %} {%- capture _content -%}{{- content -}}{%- endcapture -%} {% comment %} Remove unimportant comments {% endcomment %} {% comment %} Use for important comments that should not be stripped {% endcomment %} {%- assign _comments = "" | split: "|" -%} {%- capture _comment_befores -%}.{{ _content }}{%- endcapture -%} {%- assign _comment_befores = _comment_befores | split: _comments.first -%} {%- for _comment_before in _comment_befores -%} {%- if forloop.first -%}{% continue %}{%- endif -%} {%- capture _comment_outside -%} {% if _carry %}{{ _comments.first }}{% endif %}{{ _comment_before }} {%- endcapture -%} {%- capture _comment -%} {%- unless _carry -%}{{ _comments.first }}{%- endunless -%} {{ _comment_outside | split: _comments.last | first }} {%- if _comment_outside contains _comments.last -%} {{ _comments.last }} {%- assign _carry = false -%} {%- else -%} {%- assign _carry = true -%} {%- endif -%} {%- endcapture -%} {%- assign _content = _content | remove_first: _comment -%} {%- endfor -%} {% comment %} Remove blank lines outside of pre blocks {% endcomment %} {%- assign _pre_befores = _content | split: "" -%} {%- assign _pres_after = "" -%} {%- unless _pres.size == 0 -%} {%- assign _lines = _pres.last | split: _LINE_FEED -%} {%- capture _pres_content -%}{% for _line in _lines %}{%- assign _trimmed = _line | split: " " | join: " " -%}{% if _trimmed != empty or forloop.last %}{% unless forloop.first %}{{ _LINE_FEED }}{% endunless %}{{ _line }}{% endif %}{% endfor %}{%- endcapture -%} {%- assign _pres_after = _pres_content -%} {%- endunless -%} {%- capture _content -%} {{- _content -}} {%- if _pre_before contains "" %}{%- endif -%} {%- unless _pre_before contains "" and _pres.size == 1 %}{{ _pres_after }}{%- endunless -%} {%- endcapture -%} {%- endfor -%} {{- _content -}}