Skip to content

Commit

Permalink
feat(template): update helper structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sparanoid committed Feb 3, 2017
1 parent a137df6 commit 90f6d0f
Show file tree
Hide file tree
Showing 29 changed files with 583 additions and 535 deletions.
529 changes: 2 additions & 527 deletions _app/_includes/_amsf.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions _app/_includes/amsf/author
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% comment %}
Page/post author meta
{% endcomment %}
{% include amsf/type type=include.type %}
{% if type.author %}
{% assign author = site.data.authors[type.author] %}
{% else %}
{% assign author = site.data.authors["default"] %}
{% endif %}
20 changes: 20 additions & 0 deletions _app/_includes/amsf/core
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% comment %}
Almace Scaffolding core helpers
{% endcomment %}
{% include amsf/type type=include.type %}
{% include amsf/author %}
{% include amsf/hostname %}
{% include amsf/site_title %}
{% include amsf/site_desc %}
{% include amsf/urls %}
{% include amsf/dates %}
{% include amsf/lang %}
{% include amsf/css %}
{% include amsf/open_graph %}
{% include amsf/theme_color %}
{% include amsf/favicons %}
{% include amsf/word_counter %}
{% include amsf/thumbnail %}
{% include amsf/heading %}
{% include amsf/service_worker %}
{% include amsf/google_analytics %}
10 changes: 10 additions & 0 deletions _app/_includes/amsf/css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% comment %}
Page custom CSS
{% endcomment %}
{% capture amsf_page_css %}
{% if page.css %}
<style>
{{ page.css }}
</style>
{% endif %}
{% endcapture %}
18 changes: 18 additions & 0 deletions _app/_includes/amsf/dates
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% comment %}
Page publish date
{% endcomment %}
{% capture amsf_page_pubdate %}{{ page.date }}{% endcapture %}

{% comment %}
Page update date
{% endcomment %}
{% capture amsf_page_update %}
{% assign date_publish = page.date | date: "%b %-d, %Y" %}
{% assign date_update = page.last_modified_at | date: "%b %-d, %Y" %}

{% if date_publish != date_update %}
{{ page.last_modified_at }}
{% else %}
{{ page.date }}
{% endif %}
{% endcapture %}
31 changes: 31 additions & 0 deletions _app/_includes/amsf/favicons
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% comment %}
Favicons

Check `static_file` and output favicon markup

@since 1.1.0
{% endcomment %}
{% capture amsf_favicon_png %}{{ "/favicon.png" | relative_url }}{% endcapture %}
{% capture amsf_favicon_svg %}{{ "/favicon.svg?assets-inline-assets-keep" | relative_url }}{% endcapture %}
{% capture amsf_mask_icon %}{{ "/mask-icon.svg" | relative_url }}{% endcapture %}
{% capture amsf_apple_touch_icon %}{{ "/apple-touch-icon.png" | relative_url }}{% endcapture %}

{% capture amsf_favicons %}
{% for static_file in site.static_files %}
{% if static_file.path == "/favicon.png" %}
<link rel="icon" href="{{ amsf_favicon_png }}" type="image/png">
{% endif %}

{% if static_file.path == "/favicon.svg" %}
<link rel="icon" href="{{ amsf_favicon_svg }}" sizes="any" type="image/svg+xml">
{% endif %}

{% if static_file.path == "/mask-icon.svg" %}
<link rel="mask-icon" href="{{ amsf_mask_icon }}" color="{{ amsf_page_theme_color_with_fallback | strip }}">
{% endif %}

{% if static_file.path == "/apple-touch-icon.png" %}
<link rel="apple-touch-icon" href="{{ amsf_apple_touch_icon }}">
{% endif %}
{% endfor %}
{% endcapture %}
16 changes: 16 additions & 0 deletions _app/_includes/amsf/google_analytics
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% comment %}
Google Analytics tracking code
{% endcomment %}
{% capture amsf_google_analytics %}
{% if site.google_analytics.enabled %}
<script>
(function(a,m,s,f,j,k,l){a['GoogleAnalyticsObject']=j;a[j]=a[j]||function(){
(a[j].q=a[j].q||[]).push(arguments)},a[j].l=1*new Date();k=m.createElement(s),
l=m.getElementsByTagName(s)[0];k.async=1;k.src=f;l.parentNode.insertBefore(k,l)
})(window,document,'script','{{ site.google_analytics.url }}','ga');

ga('create', '{{ site.google_analytics.id }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{% endcapture %}
12 changes: 12 additions & 0 deletions _app/_includes/amsf/has_protocol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% comment %}
Has Protocol

Check if given string has protocol (aka. external link)

{% include amsf/has_protocol url=my_url %}
{{ amsf_has_protocol }}

@since 1.1.6
{% endcomment %}
{% assign url = include.url | default: '' %}
{% assign amsf_has_protocol = url | match_regex: '^((?:https?:)?\/\/)' %}
139 changes: 139 additions & 0 deletions _app/_includes/amsf/heading
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{% comment %}
Heading image

Check front-matter fileds and generate custom heading image styles

@since 1.1.0
{% endcomment %}
{% capture amsf_page_heading_img %}
{% include amsf/has_protocol url=page.heading-img %}
{% if amsf_has_protocol == null %}
{% if page.heading-img-local %}
<img
src="{{ amsf_user_assets }}/{{ page.heading-img }}"
{% if page.heading-img-width %}
style="width: {{ page.heading-img-width | times: 0.1 }}vw;"
{% else %}
style="width: 50vw;"
{% endif %}
>
{% else %}
<img
src="{{ site.file }}/{{ page.heading-img }}"
{% if page.heading-img-width %}
style="width: {{ page.heading-img-width | times: 0.1 }}vw;"
{% else %}
style="width: 50vw;"
{% endif %}
>
{% endif %}
{% else %}
<img
src="{{ page.heading-img }}"
{% if page.heading-img-width %}
style="width: {{ page.heading-img-width | times: 0.1 }}vw;"
{% else %}
style="width: 50vw;"
{% endif %}
>
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_text %}
{% if page.heading-img %}
{{ page.title }}
{{ amsf_page_heading_img }}
{% else %}
{{ page.title }}<span class="dot dot--post"> </span>
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_class %}
{% if page.heading-img %}
image-title
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_external %}
{% if page.link %}
class=external
{% endif %}
{% endcapture %}

{% capture amsf_page_heading %}
{% if page.link %}
<a href="{{ page.link }}" class=external>
{{ amsf_page_heading_text }}
</a>
{% else %}
{{ amsf_page_heading_text }}
{% endif %}
{% endcapture %}

{% comment %}
Heading background

Check front-matter fileds and generate custom heading background styles

@since 1.1.0
{% endcomment %}
{% capture amsf_page_heading_bg_image %}
{% if page.heading-bg %}
{% include amsf/has_protocol url=page.heading-bg %}
{% if amsf_has_protocol == null %}
{% if page.heading-bg-local %}
background-image: url('{{ amsf_user_assets }}/{{ page.heading-bg }}');
{% else %}
background-image: url('{{ site.file }}/{{ page.heading-bg }}');
{% endif %}
{% else %}
background-image: url('{{ page.heading-bg }}');
{% endif %}
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg_color %}
{% if page.heading-bg-color %}
background-color: {{ page.heading-bg-color }};
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg_size %}
{% if page.heading-bg %}
{% if page.heading-bg-size %}
background-size: {{ page.heading-bg-size }};
{% else %}
background-size: cover;
{% endif %}
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg_position %}
{% if page.heading-bg %}
{% if page.heading-bg-position %}
background-position: {{ page.heading-bg-position }};
{% else %}
background-position: center center;
{% endif %}
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg_repeat %}
{% if page.heading-bg %}
{% if page.heading-bg-position %}
background-repeat: {{ page.heading-bg-repeat }};
{% else %}
background-repeat: no-repeat;
{% endif %}
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg_text %}
{% if page.heading-bg-text %}
color: {{ page.heading-bg-text }};
{% endif %}
{% endcapture %}

{% capture amsf_page_heading_bg %}
style="{{ amsf_page_heading_bg_image | strip }} {{ amsf_page_heading_bg_color | strip }} {{ amsf_page_heading_bg_size | strip }} {{ amsf_page_heading_bg_position | strip }} {{ amsf_page_heading_bg_repeat | strip }} {{ amsf_page_heading_bg_text | strip }}"
{% endcapture %}
8 changes: 8 additions & 0 deletions _app/_includes/amsf/hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% comment %}
Site domain

Get current site domain name defined by `site.url`
Regex:
- Match domain hostname (without port): https://regex101.com/r/VkNQ7Q/1
{% endcomment %}
{% assign amsf_hostname = site.url | match_regex: '^(?:https?\:)?\/\/([^\/?#:]+)(?:[\/?#:]|$)' %}
12 changes: 12 additions & 0 deletions _app/_includes/amsf/lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% comment %}
Page language tag
{% endcomment %}
{% capture amsf_page_lang %}
{% if page.languages %}
{% if page.languages[0] != null %}
lang="{{ page.languages | first }}"
{% else %}
lang="{{ page.languages }}"
{% endif %}
{% endif %}
{% endcapture %}
21 changes: 21 additions & 0 deletions _app/_includes/amsf/open_graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% comment %}
Page type (used by Open Graph)
{% endcomment %}
{% capture amsf_page_type %}
{% if page.permalink == '/' %}
website
{% else %}
article
{% endif %}
{% endcapture %}

{% comment %}
Page type (used by Twitter Cards)
{% endcomment %}
{% capture amsf_page_type_twitter %}
{% if site.tc_large_image or page.tc_large_image %}
summary_large_image
{% else %}
summary
{% endif %}
{% endcapture %}
20 changes: 20 additions & 0 deletions _app/_includes/amsf/relative_url
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% comment %}
Relative URL

Make given link relative to current site base (except external links with protocol)

{% include amsf/relative_url url=my_url %}
{{ amsf_relative_url }}

@since 1.1.6
{% endcomment %}
{% assign url = include.url | default: '' %}
{% include amsf/has_protocol url=url %}

{% capture amsf_relative_url %}
{% if amsf_has_protocol == null %}
{{ url | relative_url }}
{% else %}
{{ url }}
{% endif %}
{% endcapture %}
16 changes: 16 additions & 0 deletions _app/_includes/amsf/service_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% comment %}
Service Worker
{% endcomment %}
{% capture amsf_service_worker %}
{% if site.service_worker.enabled == true and site.dev == false %}
<script>
if ('serviceWorker' in navigator && window.location.hostname === '{{ amsf_hostname }}') {
navigator.serviceWorker.register('{{ "/service-worker.js" | relative_url }}').then(function (registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
});
}
</script>
{% endif %}
{% endcapture %}
14 changes: 14 additions & 0 deletions _app/_includes/amsf/site_desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% comment %}
Site description
{% endcomment %}
{% capture amsf_site_desc %}
{% if page.permalink != '/' %}
{% if page.desc %}
{{ page.desc | strip_html | strip_newlines | xml_escape }}
{% else %}
{{ page.content | markdownify | strip_html | normalize_whitespace | xml_escape | truncate: 300 | truncatewords: 40 }}
{% endif %}
{% else %}
{{ site.description }}
{% endif %}
{% endcapture %}
5 changes: 5 additions & 0 deletions _app/_includes/amsf/site_title
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% comment %}
Site title
{% endcomment %}
{% capture amsf_site_title %}{% if page.title != site.name %} - {{ site.name }}{% endif %}{% endcapture %}
{% capture amsf_site_title_alt %}{% if page.title != site.name %}{{ site.name }} - {% endif %}{% endcapture %}
Loading

0 comments on commit 90f6d0f

Please sign in to comment.