Skip to content

Commit

Permalink
updated the way open graph images work
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyff committed May 29, 2024
1 parent b558afe commit 5abc669
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
19 changes: 18 additions & 1 deletion templates/macros/hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@

{% macro posts_below_title(page) %}
<span class="description"> {{page.description}} </span>
{% endmacro posts_below_title %}
{% endmacro posts_below_title %}



{% macro og_image_tags() %}
{%- if page.extra.og_preview_img -%}
{%- set_global url = get_url(path=page.extra.og_preview_img) | safe -%}
{%- endif -%}

{%- if url -%}
<meta property="og:image" content="{{ url }}"/>
{#
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="630"/>
#}
{%- endif -%}

{% endmacro og_image_tags %}
19 changes: 19 additions & 0 deletions templates/macros/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
{% endmacro responsive_image -%}


{% macro responsive_image_url(path, src, width, height, op="fill") -%}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true -%}
{# ZOLA BUG? Can't use get_url doesn't work here... as this fails for some reason... #}
{# <img alt="{{ alt }}" title="{{ alt }}" src="{{ get_url(path="/content" ~ src) | safe }}" class="{{ class }}" />
#}
/inky.png
{% else -%}
{% set abspath = path ~ src -%}
{% set meta = get_image_metadata(path=abspath) -%}
{% set current_width = meta.width -%}

{# {% if current_width >= width -%} #}
{% set resized = resize_image(format=config.extra.image_format, path=abspath, width=width, height=height, op=op, quality=config.extra.image_quality) -%}
{{ resized.url | safe }}
{# {% endif -%} #}
{% endif -%}
{% endmacro responsive_image_url -%}


{% macro responsive_thumbnail(path, src, alt, default_size, sizes, class="") -%}
{% if config.extra.image_resizing_disabled and config.extra.image_resizing_disabled == true -%}
{# <img alt="{{ alt }}" title="{{ alt }}" src="{{ get_url(path=path ~ src) | safe }}" class="{{ class }}" /> #}
Expand Down
14 changes: 1 addition & 13 deletions templates/macros/opengraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
<meta property="og:type" content="website" />
<meta property="og:url" content="{{ current_url | safe }}" />
<meta property="og:description" content="{{ social::og_description() }}" />
<meta property="og:image" content="{{social::og_image() }}" />
<meta property="og:image:url" content="{{social::og_image() }}" />
<meta property="og:image:secure_url" content="{{social::og_image() }}" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="{{social::og_title() }}" />
<meta name="twitter:description" content="{{ social::og_description() }}" />
<meta property="twitter:image" content="{{social::og_image() }}" />
{{hooks::og_image_tags() }}

{% endmacro og_preview %}

Expand Down Expand Up @@ -59,9 +53,3 @@
{%- else -%}{{ config.description }}{%- endif -%}
{%- endif -%}
{% endmacro og_title %}

{% macro og_image() %}
{%- if page.extra.og_preview_img -%}
{{ get_url(path=page.extra.og_preview_img) | safe }}
{%- endif -%}
{% endmacro og_image %}

0 comments on commit 5abc669

Please sign in to comment.