{# Course landing page with counts + traversal — graph-native style.

  Demonstrates combining {% count %} (for the badge) with {% traverse %}
  (for the lesson list). Single-page, no Cypher, no precomputed fields.

  Schema assumptions:
    - course type: title, slug, description, body
    - lesson type: title, slug, order_index, status — connected by
      `(course)-[:HAS_LESSON]->(lesson)` (or pass `parentId:{{ id }}` if
      you import flat)
    - question type: connected by (lesson)-[:HAS_QUESTION]->(question)
      for the total-questions count #}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>{{ title }} — {{ site.siteName }}</title>
  <meta name="description" content="{{ description | strip_html | truncate: 160 }}">
</head>
<body>
  <header>
    <h1>{{ title }}</h1>

    {# Two cheap counts in the header — one engine round-trip each. #}
    {% count type:"lesson"   where:"parentId:{{ id }}" as lesson_count %}
    <p class="meta">
      <span class="badge">{{ lesson_count }} lessons</span>
    </p>

    {% if description %}<p class="lead">{{ description }}</p>{% endif %}
  </header>

  <main class="course-layout">
    <aside class="course-nav">
      <h2>Curriculum</h2>
      {# Traverse the HAS_LESSON edge — no Cypher in the template. #}
      <ol>
        {% traverse from:"{{ id }}" via:"-[:HAS_LESSON]->" type:"lesson"
                    where:"status:published" order:"order_index" as lesson %}
          <li><a href="{{ lesson.url }}">{{ lesson.title }}</a></li>
        {% else %}
          <li class="empty">No lessons published yet.</li>
        {% endtraverse %}
      </ol>
    </aside>

    <article class="course-body">
      <div class="body">{{ body | md }}</div>

      {# Engine-side "what else is like this?" via embeddings.
         This is the differentiator: graph-similarity recommendation
         without writing a single line of Cypher. #}
      <section class="related">
        <h2>Related courses</h2>
        <ul>
          {% similar to:"{{ id }}" limit:3 as match %}
            <li>
              <a href="{{ match.url }}">{{ match.title }}</a>
              <span>{{ match.score | times: 100 | round }}%</span>
            </li>
          {% else %}
            <li>(none indexed yet)</li>
          {% endsimilar %}
        </ul>
      </section>
    </article>
  </main>
</body>
</html>
