{% extends "blog/shell.html" %} {# ================================================================================ Blog Home Template (Kida-Native) ================================================================================ Optimized home page template for blog sites. Extends blog/shell.html. FEATURES: - Simplified hero section - Prominent recent posts grid - Auto-discovered blog section - Clean, reading-focused layout KIDA FEATURES USED: - {% let %} for template-scoped variables - Optional chaining (?.) for null-safe access - Null coalescing (??) for smart defaults - Pipeline operator (|>) for filter chains - {% def %} for reusable post card component - {% cache %} for recent posts computation USAGE: Set `template: blog/home.html` in home page frontmatter Or set `type: blog` on home page to auto-select ================================================================================ #} {% from 'partials/components/post-card.html' import post_card %} {# ============================================================================= MAIN TEMPLATE ============================================================================= #} {% block blog_content %} {# Template-scoped configuration #} {% let page_title = page?.title ?? config?.title ?? 'Blog' %} {% let page_desc = params?.description ?? '' %} {% let show_recent = params?.show_recent_posts ?? true %} {% let blog_section_name = params?.blog_section ?? 'posts' %}
{# Hero Section #}

{{ page_title }}

{% if page_desc %}

{{ page_desc }}

{% end %}
{# Main Content (if any) #} {% if content and content.strip() %}
{{ content | safe }}
{% end %} {# Recent Posts Section - cached for performance #} {% if show_recent %} {# Find blog section and recent posts (before cache for key computation) #} {% let site_sections = site?.sections ?? [] %} {% let blog_section_candidates = site_sections |> selectattr('name', 'eq', blog_section_name) |> list %} {% let blog_section = blog_section_candidates[0] if blog_section_candidates else none %} {# Get recent posts from blog section or fallback to site-wide search #} {# regular_pages excludes index by default (standard expected behavior) #} {% let recent = [] %} {% if blog_section and blog_section?.pages %} {% let section_pages = blog_section.regular_pages ?? blog_section.pages ?? [] %} {% let recent = section_pages |> selectattr('date') |> sort(attribute='date', reverse=true) |> take(6) %} {% elif site?.pages %} {# Fallback: find blog posts by URL path or metadata type #} {% let blog_posts = [] %} {% for p in site.pages %} {% let p_type = p?.metadata?.type ?? '' %} {% let p_path = p?._path ?? '' %} {% if p_type == 'blog' or '/blog/' in p_path or '/posts/' in p_path %} {% set _ = blog_posts.append(p) %} {% end %} {% end %} {% let recent = blog_posts |> selectattr('date') |> sort(attribute='date', reverse=true) |> take(6) %} {% end %} {# Cache key includes content hashes so hot reload invalidates when posts change #} {% let recent_hashes = recent | map(attribute='content_hash') | join('-') if recent else '' %} {% cache 'blog-home-recent-' ~ (site.nav_version ?? '') ~ '-' ~ recent_hashes %} {% if recent %}

Recent Posts

{% if blog_section %} View all posts → {% end %}
{% for post in recent %} {{ post_card(post, variant='default') }} {% end %}
{% end %} {% end %} {% end %}
{% end %}