Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Context Specific Assets with Jekyll
{%- capture type -%}
{%- if page.layout == "post" -%}
posts
{%- elsif page.collection -%}
{{ page.collection }}
{%- else -%}
pages
{%- endif -%}
{%- endcapture -%}
{%- capture context -%}
{%- if page.layout == "post" -%}
{{ page.path | split:"/" | last | split:"." | first }}
{%- else -%}
{{ page.title | slugify }}
{%- endif -%}
{%- endcapture -%}
{{ site.url }}{{ site.baseurl }}/assets/{{ type }}/{{ context }}/{{ include.file }}
---
include:
css: styles.css
js:
- library.js
- scripts.js
---
{% include asset.html file="filename.ext" %}
{% if page.include.css %}
{% for file in page.include.css %}
<link rel="stylesheet" href="{% include asset.html file=file %}">
{% endfor %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment