version: "3"

includes:
  _cfg:
    taskfile: ../config/vars.yml
    internal: true

vars:
  ALEF_SNIPPETS_TAG: v0.16.69

tasks:
  build:
    desc: Build documentation
    cmds:
      - uv run --no-sync --group doc zensical build --clean

  build:strict:
    desc: Build documentation in strict mode (CI-equivalent)
    cmds:
      - uv run --no-sync --group doc zensical build --strict --clean

  serve:
    desc: Serve documentation locally with live reload
    cmds:
      - uv run --no-sync --group doc zensical serve

  lint:links:
    desc: Check links with lychee
    cmds:
      # docs/overrides/main.html contains Jinja template variables (e.g.
      # `{{ page.edit_url }}`) that lychee interprets as broken local file
      # links — skip that path; the rendered site is link-checked separately.
      - lychee --offline --root-dir "$PWD/docs" --exclude-path "docs/overrides" docs/ README.md

  lint:prose:
    desc: Lint prose with textlint (via prek hook)
    cmds:
      - prek run textlint --all-files

  snippets:install:
    desc: Install alef CLI (which now includes the snippets subcommand) if missing
    cmds:
      - cmd: |
          if ! command -v alef >/dev/null 2>&1; then
            cargo install --locked --git https://github.com/kreuzberg-dev/alef --tag {{.ALEF_SNIPPETS_TAG}} alef-cli
          fi
        ignore_error: false

  snippets:validate:
    desc: Validate all docs/snippets via `alef snippets` (syntax level)
    deps: ["snippets:install"]
    cmds:
      - alef snippets validate --snippets docs/snippets --level syntax --timeout 120 -j 4

  snippets:validate:lang:
    desc: "Validate snippets for one language (set LANG=dart|kotlin|swift|...)"
    deps: ["snippets:install"]
    cmds:
      - alef snippets validate --snippets docs/snippets --level syntax --languages {{.LANG}} --timeout 120 -j 4
    requires:
      vars: [LANG]

  snippets:list:
    desc: List all snippets discovered under docs/snippets
    deps: ["snippets:install"]
    cmds:
      - alef snippets list --snippets docs/snippets

  snippets:audit:
    desc: Audit snippet metadata and coverage
    deps: ["snippets:install"]
    cmds:
      - alef snippets audit --snippets docs/snippets

  snippets:gaps:
    desc: Report missing snippet variants across languages
    deps: ["snippets:install"]
    cmds:
      - alef snippets gaps --snippets docs/snippets
