Files
labyricorn-site/templates/macros/social-sharing.html
T
Labyricorn 1d9dd212bf
Deploy production / deploy (push) Successful in 22s
Add rich social sharing support
2026-08-22 20:29:40 -07:00

146 lines
7.7 KiB
HTML

{% macro social_metadata(record, schema_type='WebPage', og_type='website', project=none) -%}
{% set site_url = 'https://www.labyricorn.com' %}
{% set canonical_url = site_url ~ record.url_path %}
{% set default_image_url = site_url ~ '/static/labyricorn-social-card.png' %}
{% set image_url = default_image_url %}
{% if record.social_image %}
{% if record.social_image.startswith('https://') %}
{% set image_url = record.social_image %}
{% elif record.social_image.startswith('/') %}
{% set image_url = site_url ~ record.social_image %}
{% else %}
{% set image_url = site_url ~ record.url_path ~ record.social_image %}
{% endif %}
{% endif %}
{% set social_title = record.title|default('Labyricorn', true)|striptags|trim %}
{% set base_description = record.summary|default('Labyricorn developer devlog and project hub', true)|striptags|trim %}
{% set social_description = base_description|truncate(220, true, '…') %}
{% if schema_type == 'TechArticle' and project %}
{% set social_title = record.title ~ ' — ' ~ project.title ~ ' Devlog' %}
{% set social_description = (project.title ~ ' devlog — ' ~ base_description)|truncate(220, true, '…') %}
{% elif schema_type == 'SoftwareSourceCode' and record.status %}
{% set social_description = (base_description ~ ' Status: ' ~ (record.status|capitalize) ~ '.')|truncate(220, true, '…') %}
{% endif %}
<meta name="description" content="{{ social_description }}">
<link rel="canonical" href="{{ canonical_url }}">
<meta property="og:title" content="{{ social_title }}">
<meta property="og:description" content="{{ social_description }}">
<meta property="og:url" content="{{ canonical_url }}">
<meta property="og:type" content="{{ og_type }}">
<meta property="og:site_name" content="Labyricorn">
<meta property="og:image" content="{{ image_url }}">
<meta property="og:image:secure_url" content="{{ image_url }}">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Labyricorn — systems, ideas, infrastructure, built to evolve.">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{{ social_title }}">
<meta name="twitter:description" content="{{ social_description }}">
<meta name="twitter:image" content="{{ image_url }}">
<meta name="twitter:image:alt" content="Labyricorn — systems, ideas, infrastructure, built to evolve.">
{% if record.author %}<meta name="author" content="{{ record.author }}">{% endif %}
{% if og_type == 'article' and record.date %}<meta property="article:published_time" content="{{ record.date|dateformat('YYYY-MM-dd') }}">{% endif %}
{% if og_type == 'article' and record.updated %}<meta property="article:modified_time" content="{{ record.updated|dateformat('YYYY-MM-dd') }}">{% endif %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": {{ schema_type|tojson }},
"name": {{ social_title|tojson }},
"headline": {{ social_title|tojson }},
"description": {{ social_description|tojson }},
"url": {{ canonical_url|tojson }},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ canonical_url|tojson }}
},
"image": {
"@type": "ImageObject",
"url": {{ image_url|tojson }},
"width": 1200,
"height": 630
},
"publisher": {
"@type": "Organization",
"name": "Labyricorn",
"url": "https://www.labyricorn.com/"
},
"isAccessibleForFree": true
{% if record.author %},
"author": {
"@type": "Person",
"name": {{ record.author|tojson }}
}
{% endif %}
{% if schema_type in ['Article', 'BlogPosting', 'TechArticle'] and record.date %},
"datePublished": {{ record.date|dateformat('YYYY-MM-dd')|tojson }}
{% endif %}
{% if schema_type in ['Article', 'BlogPosting'] and record.updated %},
"dateModified": {{ record.updated|dateformat('YYYY-MM-dd')|tojson }}
{% endif %}
{% if schema_type in ['Article', 'BlogPosting'] and record.tags %},
"keywords": {{ record.tags|join(', ')|tojson }}
{% endif %}
{% if schema_type == 'TechArticle' and project %},
"articleSection": {{ (project.title ~ ' development log')|tojson }},
"isPartOf": {
"@type": "CreativeWork",
"name": {{ project.title|tojson }},
"url": {{ (site_url ~ project.url_path)|tojson }}
},
"about": {
"@type": "SoftwareSourceCode",
"name": {{ project.title|tojson }},
"url": {{ (site_url ~ project.url_path)|tojson }},
"codeRepository": {{ project.repository_url|string|tojson }}
}
{% if record.topic_tags %},
"keywords": {{ record.topic_tags|join(', ')|tojson }}
{% endif %}
{% endif %}
{% if schema_type == 'SoftwareSourceCode' %},
"codeRepository": {{ record.repository_url|string|tojson }},
"sameAs": {{ record.repository_url|string|tojson }},
"creativeWorkStatus": {{ record.status|capitalize|tojson }}
{% if record.started %},
"dateCreated": {{ record.started|dateformat('YYYY-MM-dd')|tojson }}
{% endif %}
{% if record.repository_languages %},
"programmingLanguage": [
{% for language in record.repository_languages %}{{ language|tojson }}{% if not loop.last %},{% endif %}{% endfor %}
]
{% endif %}
{% if record.repository_latest_release %},
"version": {{ record.repository_latest_release|tojson }}
{% endif %}
{% if record.repository_license %},
"license": {{ record.repository_license|tojson }}
{% endif %}
{% endif %}
}
</script>
{%- endmacro %}
{% macro share_controls(record, content_kind='page', project=none) -%}
{% set canonical_url = 'https://www.labyricorn.com' ~ record.url_path %}
{% set share_title = record.title|striptags|trim %}
{% if project %}{% set share_title = project.title ~ ' devlog: ' ~ record.title %}{% endif %}
{% set share_description = record.summary|default('', true)|striptags|trim|truncate(180, true, '…') %}
{% set bluesky_text = (share_title|truncate(210, true, '…')) ~ ' ' ~ canonical_url %}
<aside class="share-panel" aria-labelledby="share-heading" data-share-component data-share-url="{{ canonical_url }}" data-share-title="{{ share_title }}" data-share-description="{{ share_description }}">
<div class="share-panel-heading">
<p class="share-kicker">Share</p>
<h2 id="share-heading">Send this {{ content_kind }}</h2>
</div>
<div class="share-actions">
<a class="share-action share-action-primary" href="{{ canonical_url }}" data-share-native aria-label="Share {{ share_title }}">Share</a>
<a class="share-action" href="https://www.facebook.com/sharer/sharer.php?u={{ canonical_url|urlencode }}" target="_blank" rel="noopener noreferrer" aria-label="Share {{ share_title }} on Facebook">Facebook</a>
<a class="share-action" href="https://www.linkedin.com/sharing/share-offsite/?url={{ canonical_url|urlencode }}" target="_blank" rel="noopener noreferrer" aria-label="Share {{ share_title }} on LinkedIn">LinkedIn</a>
<a class="share-action" href="https://www.reddit.com/submit?url={{ canonical_url|urlencode }}&amp;title={{ share_title|urlencode }}" target="_blank" rel="noopener noreferrer" aria-label="Share {{ share_title }} on Reddit">Reddit</a>
<a class="share-action" href="https://bsky.app/intent/compose?text={{ bluesky_text|urlencode }}" target="_blank" rel="noopener noreferrer" aria-label="Share {{ share_title }} on Bluesky">Bluesky</a>
<a class="share-action" href="{{ canonical_url }}" data-share-copy aria-label="Copy the link to {{ share_title }}">Copy Link</a>
</div>
<p class="share-status" data-share-status role="status" aria-live="polite"></p>
</aside>
{%- endmacro %}