npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@apostrophecms/blog

v1.0.4

Published

Blog module for Apostrophe 3 websites

Downloads

297

Readme

This module bundle helps developers quickly add blog articles to Apostrophe 3 websites. It provides the blog post piece type (@apostrophecms/blog) as well as a special page type (@apostrophecms/blog-page) for editors to create a blog.

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 the app.js file:

require('apostrophe')({
  shortName: 'my-project',
  // Activate the bundle
  bundles: [ '@apostrophecms/blog' ],
  modules: {
    // The main blog piece type module
    '@apostrophecms/blog': {},
    // The blog page module
    '@apostrophecms/blog-page': {}
  }
});

Enable the page type

To enable the blog page type for editor to select, add it to the @apostrophecms/page configuration:

// modules/@apostrophecms/page/index.js
module.exports = {
  options: {
    types: [
      {
        name: '@apostrophecms/home-page',
        label: 'Home'
      },
      // Adding the blog page type
      {
        name: '@apostrophecms/blog-page',
        label: 'Blog Page'
      }
    ]
  }
};

Note: The index page template (index.html), filters template partial (filters.html), and show page template (show.html) are primarily meant as a starting point for a project. They demonstrate much of the available template data, but developers will almost always want to override them to implement proper styles and layout.

Filtering by year, month, and day

The default field publishedAt ("Publication Date" in the UI) sets the publication date of the blog post. By default, only articles released in the past are displayed to the user. In the Apostrophe admin UI, all articles are shown to the editors and admin.

This doesn't mean that Apostrophe will automatically publish a draft update to an existing post on this date. To schedule the publication of new draft content, consider installing the optional @apostrophecms/scheduled-publishing module.

The blog page module, @apostrophecms/blog-page, provides query filters to refine blog results by year, month, and day. These are primarily used for index page filters (see the filters.html file), but can also be used in REST API requests and server-side queries.

| Filter Name | Description | Expected Format | | ----------- | -------------------- | --------------- | | year | Filter by blog year | YYYY | | month | Filter by blog month | YYYY-MM | | day | Filter by blog day | YYYY-MM-DD |

Multiple blog piece 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.

Just as we extend @apostrophecms/piece-type to create a new piece type, we can extend @apostrophecms/blog to create a new blog post type. The blog post type will need its own module directory and UI labels. It can simply inherit the original fields, and other configuration or override them in the blog type's index.js file.

A special blog post type that has a blog URL field might look like this:

// modules/special-blog/index.js
module.exports = {
  extend: '@apostrophecms/blog',
  options: {
    label: 'Special blog post',
    pluralLabel: 'Special blog posts'
  },
  fields: {
    add: {
      blogUrl: {
        label: 'blog post URL',
        type: 'url'
      }
    },
    group: {
      basics: { fields: ['blogUrl'] }
    }
  }
};

As always with piece-page types and piece types, you must have a module extending @apostrophecms/blog-page that corresponds to each module extending @apostrophecms/blog. Apostrophe will match them up based on the naming convention.

// modules/special-blog-page/index.js
module.exports = {
  extend: '@apostrophecms/blog-page'
};

Do this as many times as you need custom blog types. Adding filtering and new fields to the base blog module is usually enough for most use cases, but organizations with more complex blog needs will find this strategy helpful.