# 博客

Blog API 用于获取店铺的博客以及某个博客下的文章。两个 endpoint 匿名访客都可以调用。

所有 Ajax API 请求应使用[多语言 URL](/zh-CN/docs/theme/references/ajax-api/#locale-aware-urls)，以便为访客提供一致的体验。

## 获取店铺博客列表

```text
GET /{locale}/api/front/blogs
```

获取店铺的博客列表，包含每个博客的文章数和前台路径。没有参数。

### 请求示例

**请求示例**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/front/blogs')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 响应

**数据结构 | 示例**

- `count` number

  返回的博客数量。
- `blogs` object[]

  文章所属的博客。

  *   Array \[

  - `id` string

    博客的 ID。
  - `title` string

    博客标题。
  - `description` string

    博客的描述。
  - `seo_title` string

    SEO 标题。
  - `seo_description` string

    SEO 描述。
  - `seo_keywords` undefined[]

    SEO 关键词。
  - `handle` string

    用于资源链接的 handle（URL 友好别名）。
  - `seo_url` string

    博客的相对地址。
  - `article_count` number

    博客下的文章数量。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  *   \]

```json
{
  "count": 1,
  "blogs": [
    {
      "id": "9e1a47ab-e22b-4370-bbf0-2309cc3d6c72",
      "title": "Ajax API Probe",
      "description": null,
      "seo_title": "",
      "seo_description": "",
      "seo_keywords": [],
      "handle": "ajax-probe",
      "seo_url": "/blogs/ajax-probe",
      "article_count": 1,
      "created_at": "2026-09-02T13:42:08Z",
      "updated_at": "2026-09-02T13:42:24Z"
    }
  ]
}
```

## 获取博客下的文章列表

```text
GET /{locale}/api/front/blogs/{blog_slug}/articles
```

获取某个博客下的文章列表，`blog_slug` 取博客的 handle。

### 请求示例

**请求示例**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/front/blogs/ajax-probe/articles?page=1&per_page=5')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 请求参数

- `blog_slug` string

  博客的 handle。
- `page` number

  返回第几页文章。
- `per_page` number

  每页返回的文章数。

### 响应

**数据结构 | 示例**

- `count` number

  返回的文章数量。
- `articles` object[]

  文章列表。

  *   Array \[

  - `id` string

    文章的 ID。
  - `title` string

    文章标题。
  - `excerpt` string

    文章的简短摘要。
  - `author` string

    文章作者。
  - `image` string

    文章的配图。
  - `published_at` string

    发布时间（ISO-8601 格式）。
  - `handle` string

    用于资源链接的 handle（URL 友好别名）。
  - `url` string

    文章的相对地址。
  - `blogs` object[]

    文章所属的博客。

    *   Array \[

    - `id` string

      博客的 ID。
    - `title` string

      博客标题。
    - `url` string

      博客的相对地址。
    - `handle` string

      用于资源链接的 handle（URL 友好别名）。
    *   \]
  *   \]

```json
{
  "count": 1,
  "articles": [
    {
      "id": "b90f0520-afea-4efd-8c92-3e5751490317",
      "title": "Ajax API Probe Article",
      "excerpt": "Sample article for Ajax API docs.",
      "author": "Docs",
      "image": null,
      "published_at": null,
      "handle": "ajax-probe-article",
      "url": "/blog/ajax-probe-article",
      "blogs": [
        {
          "id": "9e1a47ab-e22b-4370-bbf0-2309cc3d6c72",
          "title": "Ajax API Probe",
          "url": "/blogs/ajax-probe",
          "handle": "ajax-probe"
        }
      ]
    }
  ]
}
```
