<commit_before>---
description: 'Used to retrieve category objects.'
action: 'shop:category'
template: json-api
protocol: all
published: true
name: 'Category API'
url: '/api/categories/:urlName'
---

{
  "name": "{{ category.name | raw }}",
  "short_description": "{{ category.short_description | escape("html_attr")  }}",
  "thumbnail": "{{ category.images.first.thumbnail(600,'auto') |default('http://placehold.it/1920x1080') }}",
  "images": [
    {% for image in category.images %}
    "{{ image.thumbnail(1280, 'auto') }}"
    {% if not loop.last %},{% endif %}
    {% endfor %}
  ],
  "children":
  {% if category.children is not empty %}
    {{ category.children | raw }},
    {% else %}
    [],
  {% endif %}
  "parent":
  {% if category.parent is not empty %}
    {{ category.parent | raw }},
    {% else %}
    {},
  {% endif %}
  "products": [
    {{ partial("partial-product", { "products": category.productList[param('start'):param('length')] }) }}
  ],
  "count": {{ category.productList|length }}
}<commit_msg>Added search ability to the category api.<commit_after>---
description: 'Used to retrieve category objects.'
action: 'shop:category'
template: json-api
protocol: all
published: true
name: 'Category API'
url: '/api/categories/:urlName'
---
{# filter products #}
{% set filtered = [] %}
{% for product in category.productList %}
  {% if not param('search') or param('search')|lower in product.name|lower %}
    {% set filtered = filtered|merge([product]) %}
  {% endif %}
{% endfor %}
{
  "name": "{{ category.name | raw }}",
  "short_description": "{{ category.short_description | escape("html_attr")  }}",
  "thumbnail": "{{ category.images.first.thumbnail(600,'auto') |default('http://placehold.it/1920x1080') }}",
  "images": [
    {% for image in category.images %}
    "{{ image.thumbnail(1280, 'auto') }}"
    {% if not loop.last %},{% endif %}
    {% endfor %}
  ],
  "children":
  {% if category.children is not empty %}
    {{ category.children | raw }},
    {% else %}
    [],
  {% endif %}
  "parent":
  {% if category.parent is not empty %}
    {{ category.parent | raw }},
    {% else %}
    {},
  {% endif %}
  "products": [
    {{ partial("partial-product", { "products": filtered[param('start'):param('length')] }) }}
  ],
  "count": {{ filtered|length }}
}
{'fraction_non_alphanumeric': 0.21245102307357422, 'fraction_numerical': 0.013060513713539399, 'mean_word_length': 3.6707317073170733, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3617389', 'n_tokens_mistral': 795, 'n_tokens_neox': 722, 'n_words': 160}