Skip to content

Instantly share code, notes, and snippets.

@sebnitu
Last active November 3, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebnitu/75b5f77d372e1d689b5709a986f72926 to your computer and use it in GitHub Desktop.
Save sebnitu/75b5f77d372e1d689b5709a986f72926 to your computer and use it in GitHub Desktop.
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