Files
labyricorn-site/templates/macros/social-sharing.html
T
Labyricorn b12030aeb0
Deploy production / deploy (push) Successful in 22s
Add model-specific social cards
2026-08-22 22:56:05 -07:00

194 lines
12 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 fallback_image_path = '/static/labyricorn-social-card.png' %}
{% set image_alt = 'Labyricorn — systems, ideas, infrastructure, built to evolve.' %}
{% if schema_type == 'Article' %}
{% set fallback_image_path = '/static/labyricorn-social-article.png' %}
{% set image_alt = 'Labyricorn Article // Analysis social card.' %}
{% elif schema_type == 'BlogPosting' %}
{% set fallback_image_path = '/static/labyricorn-social-blog.png' %}
{% set image_alt = 'Labyricorn Blog // Signal social card.' %}
{% elif schema_type == 'SoftwareSourceCode' %}
{% set fallback_image_path = '/static/labyricorn-social-project.png' %}
{% set image_alt = 'Labyricorn Project // System social card.' %}
{% elif schema_type == 'TechArticle' %}
{% set fallback_image_path = '/static/labyricorn-social-devlog.png' %}
{% set image_alt = 'Labyricorn Devlog // Build Log social card.' %}
{% endif %}
{% set image_url = site_url ~ fallback_image_path %}
{% set image_is_fallback = true %}
{% set image_reference = '' %}
{% if record.logo %}
{% set image_reference = record.logo|string %}
{% set image_alt = record.title ~ ' logo' %}
{% else %}
{% set rendered_body = record.body|string %}
{% if '<img ' in rendered_body and 'src="' in rendered_body.split('<img ', 1)[1] %}
{% set first_image_tag = rendered_body.split('<img ', 1)[1].split('>', 1)[0] %}
{% set image_reference = first_image_tag.split('src="', 1)[1].split('"', 1)[0]|replace('&amp;', '&')|trim %}
{% if 'alt="' in first_image_tag %}
{% set referenced_alt = first_image_tag.split('alt="', 1)[1].split('"', 1)[0]|replace('&amp;', '&')|striptags|trim %}
{% if referenced_alt %}{% set image_alt = referenced_alt %}{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% if image_reference %}
{% set image_is_fallback = false %}
{% if image_reference.startswith('https://') or image_reference.startswith('http://') %}
{% set image_url = image_reference %}
{% elif image_reference.startswith('//') %}
{% set image_url = 'https:' ~ image_reference %}
{% elif image_reference.startswith('/') %}
{% set image_url = site_url ~ image_reference %}
{% else %}
{% set image_url = site_url ~ record.url_path ~ image_reference %}
{% 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 }}">
{% if image_is_fallback %}
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
{% endif %}
<meta property="og:image:alt" content="{{ image_alt }}">
<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="{{ image_alt }}">
{% 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 }}{% if image_is_fallback %},
"width": 1200,
"height": 630
{% endif %}
},
"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">
<h2 id="share-heading">Share <span aria-hidden="true">// Transmit</span><span class="visually-hidden"> this {{ content_kind }}</span></h2>
<span class="share-panel-signal" aria-hidden="true"></span>
</div>
<div class="share-actions">
<a class="share-action share-action-primary" href="{{ canonical_url }}" data-share-native aria-label="Share {{ share_title }}" title="Share using device controls">
<svg class="share-icon share-icon-stroke" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="18" cy="5" r="2.2"/><circle cx="6" cy="12" r="2.2"/><circle cx="18" cy="19" r="2.2"/><path d="m8 11 7.9-4.7M8 13l7.9 4.7"/></svg>
</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" title="Share on Facebook">
<svg class="share-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M17.525 13.5l.667-4.344h-4.167V6.337c0-1.189.582-2.348 2.448-2.348h1.894V.29S16.648 0 15.003 0c-3.426 0-5.665 2.077-5.665 5.838v3.318H5.53V13.5h3.808V24h4.687V13.5z"/></svg>
</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" title="Share on LinkedIn">
<svg class="share-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 1 1 0-4.124 2.062 2.062 0 0 1 0 4.124zM6.962 20.452H3.71V9h3.252z"/></svg>
</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" title="Share on Reddit">
<svg class="share-icon share-icon-stroke" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5.3 10.2A8.9 8.9 0 0 1 12 7.6a8.9 8.9 0 0 1 6.7 2.6A2.3 2.3 0 1 1 20 14.4c-.8 2.8-4 4.8-8 4.8s-7.2-2-8-4.8a2.3 2.3 0 1 1 1.3-4.2ZM14.7 7.9l.9-4.1 3.3.8"/><circle cx="20.4" cy="4.9" r="1.6"/><circle cx="8.5" cy="13.2" r="1" class="share-icon-fill"/><circle cx="15.5" cy="13.2" r="1" class="share-icon-fill"/><path d="M8.8 16.1c1.7 1.2 4.7 1.2 6.4 0"/></svg>
</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" title="Share on Bluesky">
<svg class="share-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 10.8c-1.09-2.11-4.05-6.05-6.8-8C2.57.94 1.56 1.27.9 1.57.14 1.91 0 3.08 0 3.77c0 .69.38 5.65.62 6.48.82 2.74 3.71 3.66 6.38 3.36-4.68.69-8.83 2.39-3.38 8.46 6 6.36 8.22-1.69 3.19-3.38 2.05 1.7 6.5 3.77 6.5 3.77s4.45-2.07 6.5-3.77c-1.69 5.02.53 7.69 3.38 8.22 5.45-6.07 1.3-7.77-3.38-8.46 2.67.3 5.57-.62 6.38-3.36.25-.83.62-5.79.62-6.48 0-.69-.14-1.86-.9-2.2-.66-.3-1.66-.62-4.3 1.24-2.75 1.94-5.71 5.88-6.8 8Z"/></svg>
</a>
<a class="share-action" href="{{ canonical_url }}" data-share-copy aria-label="Copy the link to {{ share_title }}" title="Copy link">
<svg class="share-icon share-icon-stroke" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m10.4 13.6 3.2-3.2M8.1 16l-1.4 1.4a4 4 0 0 1-5.7-5.7l3.4-3.4A4 4 0 0 1 10 8m5.9 0 1.4-1.4a4 4 0 0 1 5.7 5.7l-3.4 3.4A4 4 0 0 1 14 16"/></svg>
</a>
</div>
<p class="share-status" data-share-status role="status" aria-live="polite"></p>
</aside>
{%- endmacro %}