{% extends "base.html" %}

{% block extrahead %}
  <!-- Standard meta description -->
  {% if page.meta and page.meta.description %}
  <meta name="description" content="{{ page.meta.description }}">
  {% else %}
  <meta name="description" content="Multi-engine LLM benchmark &amp; monitoring CLI for Apple Silicon. 7 engines, GPU observability, community leaderboard.">
  {% endif %}

  <!-- OpenGraph -->
  {% if page.meta and page.meta.title %}
  <meta property="og:title" content="{{ page.meta.title }}">
  {% else %}
  <meta property="og:title" content="{{ page.title }} — asiai">
  {% endif %}
  {% if page.meta and page.meta.description %}
  <meta property="og:description" content="{{ page.meta.description }}">
  {% else %}
  <meta property="og:description" content="Multi-engine LLM benchmark &amp; monitoring CLI for Apple Silicon. 7 engines, GPU observability, community leaderboard.">
  {% endif %}
  <meta property="og:url" content="{{ page.canonical_url }}">
  <meta property="og:type" content="{% if page.meta and page.meta.type == 'article' %}article{% else %}website{% endif %}">
  <meta property="og:site_name" content="asiai">
  <meta property="og:image" content="https://asiai.dev/assets/og-image.png?v=3">

  <!-- Twitter Card -->
  <meta name="twitter:card" content="summary_large_image">
  {% if page.meta and page.meta.title %}
  <meta name="twitter:title" content="{{ page.meta.title }}">
  {% else %}
  <meta name="twitter:title" content="{{ page.title }} — asiai">
  {% endif %}
  {% if page.meta and page.meta.description %}
  <meta name="twitter:description" content="{{ page.meta.description }}">
  {% else %}
  <meta name="twitter:description" content="Benchmark, monitor, and manage 7 LLM engines on Apple Silicon. Zero dependencies.">
  {% endif %}
  <meta name="twitter:image" content="https://asiai.dev/assets/og-image.png?v=3">
  <meta name="twitter:creator" content="@jmn67">
  <meta name="twitter:site" content="@asiai_dev">

  <!-- hreflang alternate links -->
  {% set base_url = 'https://asiai.dev/' %}
  {% set raw_path = page.canonical_url | replace(base_url, '') %}
  {# Strip language prefix (fr/, de/, etc.) to get the EN base path #}
  {% if raw_path[:3] in ['fr/', 'de/', 'es/', 'it/', 'pt/', 'zh/', 'ja/', 'ko/'] %}
  {% set en_path = raw_path[3:] %}
  {% else %}
  {% set en_path = raw_path %}
  {% endif %}
  <link rel="alternate" href="{{ base_url }}{{ en_path }}" hreflang="en">
  <link rel="alternate" href="{{ base_url }}{{ en_path }}" hreflang="x-default">
  <link rel="alternate" href="{{ base_url }}fr/{{ en_path }}" hreflang="fr">
  <link rel="alternate" href="{{ base_url }}de/{{ en_path }}" hreflang="de">
  <link rel="alternate" href="{{ base_url }}es/{{ en_path }}" hreflang="es">
  <link rel="alternate" href="{{ base_url }}it/{{ en_path }}" hreflang="it">
  <link rel="alternate" href="{{ base_url }}pt/{{ en_path }}" hreflang="pt">
  <link rel="alternate" href="{{ base_url }}zh/{{ en_path }}" hreflang="zh">
  <link rel="alternate" href="{{ base_url }}ja/{{ en_path }}" hreflang="ja">
  <link rel="alternate" href="{{ base_url }}ko/{{ en_path }}" hreflang="ko">

  <!-- Structured Data: SoftwareApplication (global) -->
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "SoftwareApplication",
    "name": "asiai",
    "description": "Multi-engine LLM benchmark & monitoring CLI for Apple Silicon. Compare 7 inference engines side-by-side, monitor GPU metrics, share results with the community.",
    "url": "https://asiai.dev",
    "operatingSystem": "macOS",
    "applicationCategory": "DeveloperApplication",
    "license": "https://opensource.org/licenses/Apache-2.0",
    "author": {
      "@type": "Person",
      "name": "Jean-Marc Nahlovsky",
      "alternateName": "druide67",
      "url": "https://github.com/druide67"
    },
    "codeRepository": "https://github.com/druide67/asiai",
    "softwareVersion": "1.5.0",
    "downloadUrl": "https://pypi.org/project/asiai/",
    "installUrl": "https://pypi.org/project/asiai/",
    "softwareRequirements": "macOS on Apple Silicon (M1/M2/M3/M4), Python 3.11+",
    "screenshot": "https://asiai.dev/assets/og-image.png?v=3",
    "offers": {
      "@type": "Offer",
      "price": "0",
      "priceCurrency": "USD"
    },
    "keywords": ["LLM", "benchmark", "Apple Silicon", "inference", "monitoring", "CLI", "Ollama", "LM Studio", "MLX"],
    "dateModified": "2026-03-29"
  }
  </script>

  <!-- Structured Data: BreadcrumbList -->
  {% if page.url != '.' and page.url != '' and page.url != 'index.html' %}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "name": "Home",
        "item": "https://asiai.dev/"
      },
      {
        "@type": "ListItem",
        "position": 2,
        "name": "{{ page.title }}",
        "item": "{{ page.canonical_url }}"
      }
    ]
  }
  </script>
  {% endif %}

  <!-- Structured Data: Article (for content pages) -->
  {% if page.meta and page.meta.type == 'article' %}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "headline": "{{ page.meta.title | default(page.title) }}",
    "description": "{{ page.meta.description | default('') }}",
    "url": "{{ page.canonical_url }}",
    "author": {
      "@type": "Person",
      "name": "Jean-Marc Nahlovsky",
      "url": "https://github.com/druide67"
    },
    "publisher": {
      "@type": "Organization",
      "name": "asiai",
      "url": "https://asiai.dev",
      "logo": {
        "@type": "ImageObject",
        "url": "https://asiai.dev/assets/logo.svg"
      }
    },
    "mainEntityOfPage": "{{ page.canonical_url }}"
    {% if page.meta.date %},
    "datePublished": "{{ page.meta.date }}"
    {% endif %}
    {% if page.meta.updated %},
    "dateModified": "{{ page.meta.updated }}"
    {% endif %}
  }
  </script>
  {% endif %}

  <!-- Structured Data: FAQPage -->
  {% if page.meta and page.meta.faq %}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    "mainEntity": [
      {% for item in page.meta.faq %}
      {
        "@type": "Question",
        "name": "{{ item.q }}",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "{{ item.a }}"
        }
      }{% if not loop.last %},{% endif %}
      {% endfor %}
    ]
  }
  </script>
  {% endif %}

  <!-- Structured Data: HowTo -->
  {% if page.meta and page.meta.type == 'howto' and page.meta.steps %}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "HowTo",
    "name": "{{ page.meta.title | default(page.title) }}",
    "description": "{{ page.meta.description | default('') }}",
    "totalTime": "{{ page.meta.duration | default('PT5M') }}",
    "tool": {
      "@type": "HowToTool",
      "name": "asiai CLI"
    },
    "step": [
      {% for step in page.meta.steps %}
      {
        "@type": "HowToStep",
        "position": {{ loop.index }},
        "name": "{{ step.name }}",
        "text": "{{ step.text }}"
      }{% if not loop.last %},{% endif %}
      {% endfor %}
    ]
  }
  </script>
  {% endif %}

  <!-- Structured Data: Dataset (for benchmark data pages) -->
  {% if page.meta and page.meta.dataset %}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "Dataset",
    "name": "{{ page.meta.dataset.name }}",
    "description": "{{ page.meta.dataset.description }}",
    "url": "{{ page.canonical_url }}",
    "license": "https://opensource.org/licenses/Apache-2.0",
    "creator": {
      "@type": "Person",
      "name": "Jean-Marc Nahlovsky"
    },
    "temporalCoverage": "{{ page.meta.dataset.date | default('2026-03') }}",
    "measurementTechnique": "asiai CLI automated benchmark (MLPerf/SPEC-inspired methodology)"
  }
  </script>
  {% endif %}

  <!-- Brand header styling -->
  <style>
    /* Brand name: bolder, slightly larger */
    .md-header__topic:first-child .md-ellipsis {
      font-weight: 700;
      font-size: 1.05rem;
      letter-spacing: -0.3px;
    }
    .md-header__topic:first-child .md-ellipsis .brand-ai {
      color: #06b6d4;
    }
    /* Inline tagline after brand name */
    .md-header__topic:first-child .md-ellipsis .brand-tagline {
      display: inline;
      font-size: 0.7rem;
      font-weight: 400;
      color: rgba(255,255,255,0.9);
      margin-left: 0.5rem;
      letter-spacing: 0;
    }
    /* Hide star/fork counters (0 is not flattering) */
    .md-source__facts { display: none; }
    /* Fix Chrome horizontal scrollbar (grey bar at bottom) */
    html { overflow-x: hidden !important; }
  </style>

  <!-- Brand: color "ai" green + tagline (safe DOM manipulation) -->
  <script>
  document.addEventListener('DOMContentLoaded', function() {
    var el = document.querySelector('.md-header__topic:first-child .md-ellipsis');
    if (el && el.textContent.trim() === 'asiai') {
      while (el.firstChild) el.removeChild(el.firstChild);
      el.appendChild(document.createTextNode('asi'));
      var ai = document.createElement('span');
      ai.className = 'brand-ai';
      ai.textContent = 'ai';
      el.appendChild(ai);
      var tag = document.createElement('span');
      tag.className = 'brand-tagline';
      tag.textContent = '— Multi-engine LLM benchmark & monitoring CLI';
      el.appendChild(tag);
    }
  });
  </script>

  <!-- Accessibility: language selector aria-expanded + Escape -->
  <script>
  document.addEventListener('DOMContentLoaded', function() {
    var sel = document.querySelector('.md-select');
    if (!sel) return;
    var btn = sel.querySelector('button, [role="button"]');
    if (btn) {
      btn.setAttribute('aria-expanded', 'false');
      btn.addEventListener('click', function(e) {
        var open = sel.classList.toggle('md-select--open');
        btn.setAttribute('aria-expanded', String(open));
        e.stopPropagation();
      });
    }
    var list = sel.querySelector('ul');
    if (list) list.setAttribute('role', 'menu');
    /* Admonitions: add role="note" for screen readers */
    document.querySelectorAll('.admonition').forEach(function(el) {
      el.setAttribute('role', 'note');
    });
    document.addEventListener('keydown', function(e) {
      if (e.key === 'Escape' && sel.classList.contains('md-select--open')) {
        sel.classList.remove('md-select--open');
        if (btn) btn.setAttribute('aria-expanded', 'false');
        if (btn) btn.focus();
      }
    });
    document.addEventListener('click', function(e) {
      if (!sel.contains(e.target) && sel.classList.contains('md-select--open')) {
        sel.classList.remove('md-select--open');
        if (btn) btn.setAttribute('aria-expanded', 'false');
      }
    });
  });
  </script>

  <!-- GoatCounter analytics (privacy-friendly, no cookies) -->
  <script data-goatcounter="https://asiai.goatcounter.com/count"
          async src="//gc.zgo.at/count.js"></script>

  <!-- WebMCP: register an in-page tool so AI browsers can query the community
       leaderboard directly from this page without leaving asiai.dev.
       Spec: https://webmcp.org/ — feature-detected, no-op if unsupported. -->
  <script>
  (function() {
    if (!('modelContext' in navigator) || !navigator.modelContext) return;

    async function queryLeaderboard(args) {
      const params = new URLSearchParams();
      if (args && args.chip) params.set('chip', args.chip);
      if (args && args.model) params.set('model', args.model);
      const url = 'https://api.asiai.dev/api/v1/leaderboard' +
                  (params.toString() ? '?' + params.toString() : '');
      const res = await fetch(url, { headers: { 'Accept': 'application/json' } });
      if (!res.ok) {
        return { error: 'Leaderboard fetch failed', status: res.status };
      }
      return await res.json();
    }

    const tool = {
      name: 'query_asiai_leaderboard',
      description: 'Query the asiai community benchmark leaderboard for Apple ' +
                   'Silicon LLM inference. Returns aggregated tok/s, TTFT, VRAM ' +
                   'and sample counts grouped by hardware chip + model + engine. ' +
                   'Optional filters: chip (e.g. "Apple M4 Pro") and model ' +
                   '(substring match).',
      inputSchema: {
        type: 'object',
        properties: {
          chip: {
            type: 'string',
            description: 'Apple Silicon chip name, e.g. "Apple M4 Pro", "Apple M5 Max".'
          },
          model: {
            type: 'string',
            description: 'Model name or substring, e.g. "qwen3.6", "gemma4:31b".'
          }
        }
      },
      execute: queryLeaderboard,
      annotations: { readOnlyHint: true, openWorldHint: true }
    };

    try {
      navigator.modelContext.registerTool(tool);
    } catch (e) {
      // unsupported shape, ignore
    }
  })();
  </script>
{% endblock %}
