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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@astracms/astro-loader

v1.0.3

Published

Astro Content Collection loader for AstraCMS

Readme

@astracms/astro-loader

Astro Content Collection loaders for AstraCMS. Seamlessly integrate your AstraCMS content into Astro.js projects.

Features

  • 🚀 4 Content Loaders: Posts, Categories, Tags, and Authors
  • 🔐 Dual API Support: Works with both v1 (workspaceId) and v2 (API key) authentication
  • 📝 Markdown Rendering: Full support for Astro's <Content /> component
  • 🔄 Incremental Builds: Content digests for efficient rebuilds
  • 📘 TypeScript: Full type safety with Zod schema validation
  • 🎯 Filtering: Filter posts by categories, tags, and search queries

Installation

npm install @astracms/astro-loader
# or
pnpm add @astracms/astro-loader
# or
yarn add @astracms/astro-loader

Quick Start

1. Configure Environment Variables

# .env
ASTRACMS_API_KEY=your_api_key_here

2. Set Up Content Collections

// src/content.config.ts
import { defineCollection } from 'astro:content';
import {
  postsLoader,
  categoriesLoader,
  tagsLoader,
  authorsLoader,
} from '@astracms/astro-loader';

const config = {
  apiKey: import.meta.env.ASTRACMS_API_KEY,
};

const posts = defineCollection({
  loader: postsLoader({
    ...config,
    format: 'markdown', // or 'html'
  }),
});

const categories = defineCollection({
  loader: categoriesLoader(config),
});

const tags = defineCollection({
  loader: tagsLoader(config),
});

const authors = defineCollection({
  loader: authorsLoader(config),
});

export const collections = { posts, categories, tags, authors };

3. Use in Your Pages

---
// src/pages/blog/[slug].astro
import { getCollection, render } from 'astro:content';

export async function getStaticPaths() {
  const posts = await getCollection('posts');
  return posts.map((post) => ({
    params: { slug: post.id },
    props: { post },
  }));
}

const { post } = Astro.props;
const { Content } = await render(post);
---

<article>
  <h1>{post.data.title}</h1>
  <p>{post.data.description}</p>
  
  {post.data.coverImage && (
    <img src={post.data.coverImage} alt={post.data.title} />
  )}
  
  <div class="meta">
    <span>Category: {post.data.category.name}</span>
    <span>Published: {post.data.publishedAt.toLocaleDateString()}</span>
  </div>
  
  <div class="tags">
    {post.data.tags.map((tag) => (
      <a href={`/tags/${tag.slug}`}>{tag.name}</a>
    ))}
  </div>
  
  <Content />
  
  <div class="authors">
    {post.data.authors.map((author) => (
      <div class="author">
        {author.image && <img src={author.image} alt={author.name} />}
        <span>{author.name}</span>
        {author.role && <span>{author.role}</span>}
      </div>
    ))}
  </div>
</article>

API Reference

postsLoader(options)

Loads blog posts from AstraCMS.

| Option | Type | Required | Description | |--------|------|----------|-------------| | apiKey | string | * | API key (recommended for v2 API) | | workspaceId | string | * | Workspace ID (required for v1 API) | | apiVersion | 'v1' \| 'v2' | | API version (defaults to 'v2') | | format | 'html' \| 'markdown' | | Content format (default: 'markdown') | | categories | string[] | | Filter by category slugs | | excludeCategories | string[] | | Exclude category slugs | | tags | string[] | | Filter by tag slugs | | excludeTags | string[] | | Exclude tag slugs | | query | string | | Search query |

* Either apiKey or workspaceId is required

categoriesLoader(options)

Loads categories from AstraCMS.

| Option | Type | Required | Description | |--------|------|----------|-------------| | apiKey | string | * | API key (recommended) | | workspaceId | string | * | Workspace ID | | apiVersion | 'v1' \| 'v2' | | API version | | query | string | | Search query | | excludeCategories | string[] | | Exclude category slugs |

tagsLoader(options)

Loads tags from AstraCMS.

| Option | Type | Required | Description | |--------|------|----------|-------------| | apiKey | string | * | API key (recommended) | | workspaceId | string | * | Workspace ID | | apiVersion | 'v1' \| 'v2' | | API version | | query | string | | Search query |

authorsLoader(options)

Loads authors from AstraCMS.

| Option | Type | Required | Description | |--------|------|----------|-------------| | apiKey | string | * | API key (recommended) | | workspaceId | string | * | Workspace ID | | apiVersion | 'v1' \| 'v2' | | API version | | query | string | | Search query |

Schemas

The package exports Zod schemas that you can use for custom validation or extend:

import {
  postSchema,
  categorySchema,
  tagSchema,
  authorSchema,
} from '@astracms/astro-loader';

// Extend the post schema
const customPostSchema = postSchema.extend({
  customField: z.string(),
});

Authentication

API Key (v2 API) - Recommended

postsLoader({
  apiKey: import.meta.env.ASTRACMS_API_KEY,
});

Workspace ID (v1 API)

postsLoader({
  apiVersion: 'v1',
  workspaceId: 'your-workspace-id',
});

Requirements

  • Astro 5.0 or later
  • AstraCMS account with API access

License

MIT