Google analytics & fix for whitespace

This commit is contained in:
jimmyff 2023-02-20 11:24:42 +00:00
parent 0bb121ad11
commit 10c06b661c
6 changed files with 90 additions and 80 deletions

View file

@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file.
- Hooks names updated for consistency
- Added class parameter for responsive images
- Added `images::image()` macro and `image_original` shortcode for images that don't want resizing (eg: animated gifs)
- Added Google Analytics to `config.toml` see: `config.extra.google_analytics_tag_id`
- Fixes issues with unnecessary whitespace in templates
## [1.0]

View file

@ -38,6 +38,9 @@ anchors = "on"
# Place your avatar in your /static folder
avatar = "/inky.png"
# Your Google Analytics measurement id ("G-XXXXXXXXXX")
# google_analytics_tag_id = "";
keywords = "zola, theme, ink, hugo-ink"
search_enabled = false

View file

@ -12,12 +12,22 @@
{%- block og_preview -%}
{{ social::og_preview() }}
{%-endblock og_preview -%}
{% block rss %}
{% block rss -%}
<link rel="alternate"
type="application/rss+xml"
title="{{config.title}}"
href="{{ get_url(path='atom.xml',trailing_slash=false)|safe}}"> {%
endblock %}
href="{{ get_url(path='atom.xml',trailing_slash=false)|safe}}">
{% endblock rss -%}
{% if config.extra.google_analytics_tag_id -%}
<!-- Google Analytics tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config.extra.google_analytics_tag_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ config.extra.google_analytics_tag_id }}');
</script>
{% endif -%}
<link rel="preconnect"
href="https://fonts.googleapis.com">
<link rel="preconnect"
@ -35,13 +45,13 @@
<body>
<header>
{% if config.extra.avatar %}
{% if config.extra.avatar -%}
<div class="avatar">
<a href="/">
{{ images::responsive_image(path="", src=config.extra.avatar, default_size=128, sizes=[64,128,256], alt=config.title ) }}
</a>
</div>
{% endif %}
{% endif -%}
<a class="site-name"
href="/">
<h1>{{ config.title }}</h1>
@ -51,63 +61,63 @@
</div>
<nav>
<div class="links">
{% for menu_link in config.extra.menu_links %}
{% set link_url = menu_link.url | replace(from="$BASE_URL", to=config.base_url) %}
{% for menu_link in config.extra.menu_links -%}
{% set link_url = menu_link.url | replace(from="$BASE_URL", to=config.base_url) -%}
<a {% if current_url and current_url==link_url %}class="active" {% endif %}
href="{{ link_url | safe}} ">{{menu_link.name}}</a>
{% endfor %}
{% endfor -%}
</div>
</nav>
</header>
<article>
{% block content %}
{% endblock %}
{% block content -%}
{% endblock -%}
</article>
<footer>
<div class="social">
<ul>
{# Github #}
{% if config.extra.link_github_username %}
{% if config.extra.link_github_username -%}
<li>
<a href="https://github.com/{{ config.extra.link_github_username }}"
title="Github" rel="me"><i data-feather="github"></i></a>
</li>
{% endif %}
{% endif -%}
{# Mastadon #}
{% if config.extra.link_mastodon_url %}
{% if config.extra.link_mastodon_url -%}
<li>
<a href="{{ config.extra.link_mastodon_url }}"
title="Mastodon" rel="me"><i data-feather="message-square"></i></a>
</li>
{% endif %}
{% endif -%}
{# Twitter #}
{% if config.extra.link_twitter_username %}
{% if config.extra.link_twitter_username -%}
<li>
<a href="https://twitter.com/{{ config.extra.link_twitter_username }}"
title="Twitter"
rel="me"><i data-feather="twitter"></i></a>
</li>
{% endif %}
{% endif -%}
{# Instagram #}
{% if config.extra.link_instagram_username %}
{% if config.extra.link_instagram_username -%}
<li>
<a href="https://www.instagram.com/jimmyff_art/{{ config.extra.link_instagram_username }}"
title="Medium"
rel="me"><i data-feather="instagram"></i></a>
</li>
{% endif %}
{% endif -%}
{# Medium #}
{% if config.extra.link_medium_username %}
{% if config.extra.link_medium_username -%}
<li>
<a href="https://medium.com/@{{ config.extra.link_medium_username }}"
title="Medium"
rel="me"><i data-feather="file-text"></i></a>
</li>
{% endif %}
{% endif -%}
{# RSS feed #}
<li>

View file

@ -1,25 +1,24 @@
{% extends "base.html" %} {% block content %}
{% extends "base.html" -%}
{% block content -%}
<h1 class="title">{{ section.title }}</h1>
<article>{{ section.content | safe }}</article>
{% for year, posts in section.pages | group_by(attribute="year") %}
{% for year, posts in section.pages | group_by(attribute="year") -%}
<ul class="gallery flat">
<h2 class="archive-year">{{ year }}</h2>
{% for post in posts %}
{% if post.extra.images %}
{% for image in post.extra.images %}
{% for post in posts -%}
{% if post.extra.images -%}
{% for image in post.extra.images -%}
{# { set image = resize_image(path=post.path ~ image, width=256, height=256, format=config.extra.image_format, quality=config.extra.thumbnail_quality) %} #}
<li class="thumbnail">
<a href="{{ post.permalink | safe }}" title="{{ post.title }} - {{ post.date }}">
{{ images::responsive_thumbnail(path=post.colocated_path, src=image, default_size=128, sizes=[128,256], alt=post.title ~ " - " ~ post.date ) }}
{{ images::responsive_thumbnail(path=post.colocated_path, src=image, default_size=128, sizes=[128,256], alt=post.title ~ " - " ~ post.date ) -}}
</a>
</li>
{% endfor %}
{% endif %}
{% endfor %}
{% endfor -%}
{% endif -%}
{% endfor -%}
</ul>
{% endfor %} {% endblock content %}
{% endfor -%}
{% endblock content -%}

View file

@ -1,52 +1,52 @@
{% extends "base.html" %}
{% macro image(path, src, alt, class="") %}
{% macro image(path, src, alt, class="") -%}
<img alt="{{ alt }}" title="{{ alt }}" src="{{ get_url(path=path ~ src) | safe }}" class="{{ class }}" />
{% endmacro image %}
{% endmacro image -%}
{#
Original author: crepererum https://github.com/getzola/even/pull/48/files
Adapted to Inky template by jimmyff
#}
{% macro responsive_image(path, src, alt, default_size, sizes, class="") %}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true %}
{{ image(path=path, src=src, alt=alt, class=class) }}
{% else %}
{% set abspath = path ~ src %}
{% set meta = get_image_metadata(path=abspath) %}
{% set width = meta.width %}
{% set srcset_list = [] %}
{% for s in sizes %}
{% if width >= s %}
{% set resized = resize_image(format=config.extra.image_format, path=abspath, width=s, op="fit_width", quality=config.extra.image_quality) %}
{% set element = resized.url ~ " " ~ s ~ "w" %}
{% set_global srcset_list = srcset_list | concat(with=[element]) %}
{% endif %}
{% endfor %}
{% set default_resized = resize_image(format=config.extra.image_format, path=abspath, width=default_size, op="fit_width", quality=config.extra.image_quality) %}
{% macro responsive_image(path, src, alt, default_size, sizes, class="") -%}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true -%}
{{ image(path=path, src=src, alt=alt, class=class) -}}
{% else -%}
{% set abspath = path ~ src -%}
{% set meta = get_image_metadata(path=abspath) -%}
{% set width = meta.width -%}
{% set srcset_list = [] -%}
{% for s in sizes -%}
{% if width >= s -%}
{% set resized = resize_image(format=config.extra.image_format, path=abspath, width=s, op="fit_width", quality=config.extra.image_quality) -%}
{% set element = resized.url ~ " " ~ s ~ "w" -%}
{% set_global srcset_list = srcset_list | concat(with=[element]) -%}
{% endif -%}
{% endfor -%}
{% set default_resized = resize_image(format=config.extra.image_format, path=abspath, width=default_size, op="fit_width", quality=config.extra.image_quality) -%}
<img alt="{{ alt }}" title="{{ alt }}" src="{{ default_resized.url | safe }}" srcset="{{ srcset_list | join(sep=", ") | safe }}" class="{{ class }}" />
{% endif %}
{% endmacro responsive_image %}
{% endif -%}
{% endmacro responsive_image -%}
{% macro responsive_thumbnail(path, src, alt, default_size, sizes, class="") %}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true %}
{{ image(path=path, src=src, alt=alt, class=class) }}
{% else %}
{% set abspath = path ~ src %}
{% set meta = get_image_metadata(path=abspath) %}
{% set width = meta.width %}
{% set srcset_list = [] %}
{% for s in sizes %}
{% if width >= s %}
{% set resized = resize_image(format=config.extra.image_format, path=abspath, width=s, height=s, op="fill", quality=config.extra.thumbnail_quality) %}
{% set element = resized.url ~ " " ~ s ~ "w" %}
{% set_global srcset_list = srcset_list | concat(with=[element]) %}
{% endif %}
{% endfor %}
{% set default_resized = resize_image(format=config.extra.image_format, path=abspath, width=default_size, height=default_size, op="fill", quality=config.extra.thumbnail_quality) %}
{% macro responsive_thumbnail(path, src, alt, default_size, sizes, class="") -%}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true -%}
{{ image(path=path, src=src, alt=alt, class=class) -}}
{% else -%}
{% set abspath = path ~ src -%}
{% set meta = get_image_metadata(path=abspath) -%}
{% set width = meta.width -%}
{% set srcset_list = [] -%}
{% for s in sizes -%}
{% if width >= s -%}
{% set resized = resize_image(format=config.extra.image_format, path=abspath, width=s, height=s, op="fill", quality=config.extra.thumbnail_quality) -%}
{% set element = resized.url ~ " " ~ s ~ "w" -%}
{% set_global srcset_list = srcset_list | concat(with=[element]) -%}
{% endif -%}
{% endfor -%}
{% set default_resized = resize_image(format=config.extra.image_format, path=abspath, width=default_size, height=default_size, op="fill", quality=config.extra.thumbnail_quality) -%}
<img alt="{{ alt }}" title="{{ alt }}" src="{{ default_resized.url | safe }}" srcset="{{ srcset_list | join(sep=", ") | safe }}" class="{{ class }}" />
{% endif %}
{% endmacro responsive_thumbnail %}
{% endif -%}
{% endmacro responsive_thumbnail -%}

View file

@ -1,16 +1,12 @@
{% extends "base.html" %}
{% block title %}
{% extends "base.html" -%}
{% block title -%}
{{ config.title }} | {{page.title}}
{% endblock title %}
{% block content %}
{% endblock title -%}
{% block content -%}
<h1 class="title">
{{ page.title }}
</h1>
<article>
{{ page.content | safe }}
</article>
{% endblock content %}
{% endblock content -%}