Last active
November 3, 2017 18:51
-
-
Save sebnitu/75b5f77d372e1d689b5709a986f72926 to your computer and use it in GitHub Desktop.
Context Specific Assets with Jekyll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- 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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
include: | |
css: styles.css | |
js: | |
- library.js | |
- scripts.js | |
--- | |
{% include asset.html file="filename.ext" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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