@apostrophecms/blog

中文文档
1.0.6发布于 2025/09/03MITCommonJS近 30 天下载 2313

Blog module for ApostropheCMS websites

原始使用文档
文档目录12 节
  1. Features
  2. Installation
  3. Usage
  4. Enable the page type
  5. Customizing Templates
  6. Date-based Filtering
  7. Publication Control
  8. Multiple Blog Types
  9. Creating a Custom Blog Type
  10. Custom Templates for Blog Types
  11. Field Reference
  12. Built with ❤️ by the ApostropheCMS team.
ApostropheCMS logo

Apostrophe Blog

Add blog functionality to ApostropheCMS sites with article management, date-based filtering, and multiple blog support. Provides both the blog piece type and page templates to get started quickly.

Features

  • 📝 Blog Article Management - Complete CRUD interface for blog posts with publication dates
  • 🗓️ Date-based Filtering - Built-in year/month/day query filters for archives and navigation
  • 🎨 Fully Customizable — Override templates, add fields, and style it to match your brand
  • 🔗 Multiple Blog Types - Extend to create different blog categories (news, updates, etc.)
  • ⏰ Publication Control - Articles only appear when published date is in the past

Installation

To install the module, use the command line to run this command in an Apostrophe project's root directory:

npm install @apostrophecms/blog

Usage

Configure the blog modules in your app.js file:

import apostrophe from 'apostrophe';

export default apostrophe({
  root: import.meta,
  shortName: 'my-project',
  bundles: [ '@apostrophecms/blog' ],
  modules: {
    '@apostrophecms/blog': {},
    '@apostrophecms/blog-page': {}
  }
});

Enable the page type

Add the blog page type to your page configuration:

// modules/@apostrophecms/page/index.js
export default {
  options: {
    types: [
      {
        name: '@apostrophecms/home-page',
        label: 'Home'
      },
      {
        name: '@apostrophecms/blog-page',
        label: 'Blog'
      }
    ]
  }
};

Customizing Templates

The included templates (index.html, show.html, filters.html) are starting points that demonstrate the available data. Override them in your project to implement your own styling and layout:

modules/
├── @apostrophecms/
│   └── blog-page/
│       └── views/
│           ├── index.html      # Blog listing page
│           ├── show.html       # Individual blog post
│           └── filters.html    # Date filtering controls

Date-based Filtering

The blog includes built-in query filters for creating archive navigation and date-based URLs:

FilterFormatExample URL
yearYYYY/blog?year=2024
monthYYYY-MM/blog?month=2024-03
dayYYYY-MM-DD/blog?day=2024-03-15

Publication Control

Blog posts use the publishedAt field to control visibility. Only articles with publication dates in the past appear on the public site. Editors see all articles in the admin interface.

Note: This doesn't automatically publish draft changes on the publication date. For scheduled publishing of draft content, consider the @apostrophecms/scheduled-publishing module.

Multiple Blog Types

Sometimes a website needs multiple, distinct types of blog posts. If the blog posts types can be managed together, it might be easiest to add a new field and query builder to customize blog views. But if the blog posts types should be managed completely separately, it may be better to create separate piece types for each.

Creating a Custom Blog Type

// modules/news-blog/index.js - for news articles
export default {
  extend: '@apostrophecms/blog',
  options: {
    label: 'News Article',
    pluralLabel: 'News Articles'
  },
  fields: {
    add: {
      priority: {
        type: 'select',
        choices: [
          { label: 'Standard', value: 'standard' },
          { label: 'Breaking', value: 'breaking' },
          { label: 'Featured', value: 'featured' }
        ]
      },
      source: {
        type: 'string',
        label: 'News Source',
        help: 'Original source of this news item'
      }
    },
    group: {
      basics: { fields: ['priority', 'source'] }
    }
  }
};

Every blog piece type needs a corresponding page type that extends @apostrophecms/blog-page:

// modules/news-blog-page/index.js - page type for news articles
export default {
  extend: '@apostrophecms/blog-page'
};

Custom Templates for Blog Types

Each blog type can have its own templates. Create them in the corresponding page module:

modules/
├── news-blog-page/
│   └── views/
│       ├── index.html      # News listing page
│       ├── show.html       # Individual news article
│       └── filters.html    # Custom filters for news
└── @apostrophecms/
    └── blog-page/
        └── views/
            ├── index.html  # Default blog listing
            └── show.html   # Default blog post

This allows you to:

  • Style news articles differently from regular blog posts
  • Add custom filtering options specific to news content
  • Display different fields or layouts for each blog type
  • Create distinct navigation and user experiences

This approach works well when blog types have different:

  • Content structures - News articles vs. technical tutorials vs. company announcements
  • Editorial workflows - Different teams managing different content types
  • Display requirements - Unique styling, filtering, or organization needs
  • URL patterns - /blog/, /news/, /updates/ with distinct navigation

Field Reference

The blog piece type includes these fields by default:

  • Title (title) - Article headline
  • Slug (slug) - URL-friendly identifier
  • Publication Date (publishedAt) - Controls public visibility
  • Content (body) - Rich text content area
  • Meta Description (metaDescription) - SEO description
  • Tags (tags) - Taxonomy for categorization

Built with ❤️ by the ApostropheCMS team.

Found this useful? Give us a star on GitHub ⭐

版本与发布记录

@apostrophecms/blog 共发布 7 个版本,首次发布于 2022/10/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.6latest2025/09/031.2 年前
1.0.52025/04/171.6 年前
1.0.42023/09/283 年前
1.0.32023/02/183 年前
1.0.22023/02/013 年前
1.0.12022/11/293 年前

关于 @apostrophecms/blog 的常见问题

@apostrophecms/blog 是什么?

Blog module for ApostropheCMS websites

如何安装 @apostrophecms/blog?

在项目目录运行 npm install @apostrophecms/blog,或使用 pnpm add / yarn add / bun add。

@apostrophecms/blog 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/apostrophecms__blog 是否存在。

@apostrophecms/blog 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@apostrophecms/blog 可以商用吗?

@apostrophecms/blog 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@apostrophecms/blog 的下载量有多少?

根据 npm 官方下载统计,@apostrophecms/blog 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,313 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@apostrophecms/blog 还在维护吗?

最新版本 1.0.6 发布于 2025/09/03(1.2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/10/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。