Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow <head> and footer scripts to be changed via config #1241

Merged
merged 7 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Truncate archive item titles' that overflow with an ellipsis. [#1213](https://github.com/mmistakes/minimal-mistakes/issues/1213)
- Test strict Front Matter in `/test` site. [#1236](https://github.com/mmistakes/minimal-mistakes/pull/1236)
- Rename `gems` key to `plugins`. [#1239](https://github.com/mmistakes/minimal-mistakes/pull/1239)
- Add feature to include or override scripts in `<head>` and before `</body>` using `head_scripts` and `footer_scipts` arrays in `_config.yml`.

### Bug Fixes

Expand Down
13 changes: 12 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@
height: 100%;
}
</style>
<![endif]-->
<![endif]-->

{% if site.head_scripts %}
{% for script in site.head_scripts %}
{% if script contains "://" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just "//" to allow for protocol-relative URLs (below too): https://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just/27999789

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protocol less URLs are now considered an anti-pattern. It's preferable to use https when available.

https://www.paulirish.com/2010/the-protocol-relative-url/

Copy link
Contributor

@ohadschn ohadschn Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, that's exactly what I answered on that very same SO thread :) Just thought you'd might want to support it, but I suppose there's really no need, any CDN today would have HTTPS...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. And I'm not sure if // might filter out something it shouldn't be. I doubt anyone would have a path with that, but seems possible.

Copy link
Contributor

@ohadschn ohadschn Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I had the same concern, theoretically https://github.com/mmistakes//minimal-mistakes works too. I think even https://github.com/mmistakes://minimal-mistakes could work but since Liquid doesn't contain any startswith method that I can tell, not much can be done anyway.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Keeping things consistent with the rest of the "external URL" checks in the theme. You may be over thinking things a tad, simple is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overthinking is my middle name 😅

{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | absolute_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
{% endfor %}
{% endif %}
13 changes: 12 additions & 1 deletion _includes/scripts.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<script src="{{ '/assets/js/main.min.js' | absolute_url }}"></script>
{% if site.footer_scripts %}
{% for script in site.footer_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | absolute_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
{% endfor %}
{% else %}
<script src="{{ '/assets/js/main.min.js' | absolute_url }}"></script>
{% endif %}

{% include analytics.html %}
{% include /comments-providers/scripts.html %}
15 changes: 14 additions & 1 deletion docs/_docs/17-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "JavaScript"
permalink: /docs/javascript/
excerpt: "Instructions for customizing and building the theme's scripts."
last_modified_at: 2016-11-03T11:35:42-04:00
last_modified_at: 2017-09-11T12:38:43-04:00
---

The theme's [`assets/js/main.min.js`] script is built from several vendor, jQuery plugins, and other scripts found in [`assets/js/`](https://github.com/mmistakes/minimal-mistakes/tree/master/assets/js).
Expand All @@ -29,6 +29,19 @@ To modify or add your own scripts include them in [`assets/js/_main.js`](https:/

If you add additional scripts to `assets/js/plugins/` and would like them concatenated with the others, be sure to update the `uglify` script in [`package.json`](https://github.com/mmistakes/minimal-mistakes/blob/master/package.json). Same goes for scripts that you remove.

You can also add scripts to the `<head>` or closing `</body>` elements by adding paths to following arrays in `_config.yml`.

```
head_scripts:
- /assets/js/your-custom-head-script.js
- https://code.jquery.com/jquery-3.2.1.min.js
footer_scripts:
- /assets/js/your-custom-footer-script.js
```

**Note:** If you assign `footer_scripts` the theme's `/assets/js/main.min.js` file will be deactivated. This script includes jQuery and various other plugins that you'll need to find replacements for them or include separately.
{: .notice--warning}

---

## Build Process
Expand Down
1 change: 1 addition & 0 deletions docs/_docs/18-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ last_modified_at: 2017-09-11T12:14:10-04:00
- Truncate archive item titles' that overflow with an ellipsis. [#1213](https://github.com/mmistakes/minimal-mistakes/issues/1213)
- Test strict Front Matter in `/test` site. [#1236](https://github.com/mmistakes/minimal-mistakes/pull/1236)
- Rename `gems` key to `plugins`. [#1239](https://github.com/mmistakes/minimal-mistakes/pull/1239)
- Add feature to include or override scripts in `<head>` and before `</body>` using `head_scripts` and `footer_scipts` arrays in `_config.yml`.

### Bug Fixes

Expand Down
13 changes: 12 additions & 1 deletion docs/_includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@
height: 100%;
}
</style>
<![endif]-->
<![endif]-->

{% if site.head_scripts %}
{% for script in site.head_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | absolute_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
{% endfor %}
{% endif %}
13 changes: 12 additions & 1 deletion docs/_includes/scripts.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<script src="{{ '/assets/js/main.min.js' | absolute_url }}"></script>
{% if site.footer_scripts %}
{% for script in site.footer_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | absolute_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
{% endfor %}
{% else %}
<script src="{{ '/assets/js/main.min.js' | absolute_url }}"></script>
{% endif %}

{% include analytics.html %}
{% include /comments-providers/scripts.html %}