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

@coffic/cosy-content

v0.2.28

Published

Cosy Content

Downloads

351

Readme

Cosy Content

English 简体中文 Release DEV NPM NPM Downloads NPM Version Coffic Maintainer GitHub License

一个用于管理多种类型内容的 TypeScript 库,支持博客、课程、实验、课程、手册等多种内容类型。

功能特性

  • 多种内容类型支持:博客、课程、实验、故事、手册等
  • 多语言支持:内置中文和英文支持
  • 类型安全:完整的 TypeScript 类型定义
  • Schema 扩展:支持自定义字段,保持类型安全
  • 灵活的内容管理:支持层级结构、标签、分类等
  • SEO 友好:内置 SEO 优化功能
  • 易于扩展:模块化设计,易于添加新的内容类型

内容类型

BlogDoc - 博客文档

适合发布独立的博客文章,支持标签、分类、作者等信息。

CourseDoc - 课程文档

适合组织成体系的课程内容,支持多级章节结构。

LessonDoc - 课程文档

适合单个课程的详细教程,支持步骤化的学习内容。

ExperimentDoc - 实验文档

适合记录技术实验和探索,支持实验过程和结果展示。

ManualDoc - 手册文档

适合展示成体系的文档,如产品用户手册、技术框架文档等。每个仓库只有一个完整的手册,按章节组织。

StoryDoc - 故事文档

适合绘本、故事等内容,支持多级章节结构和自定义字段扩展。

目录结构

content/
├── blogs/          # 博客文章
├── courses/        # 课程内容
├── lessons/        # 课程教程
├── experiments/    # 实验记录
├── stories/        # 故事内容
├── manuals/        # 手册文档
└── meta/           # 元数据

快速开始

安装

npm install @coffic/cosy-content

基本使用

import { blogRepo, courseRepo, storyRepo, manualRepo } from '@coffic/cosy-content';

// 获取博客文章
const blogs = await blogRepo.allBlogsByLang('zh-cn');

// 获取课程内容
const courses = await courseRepo.allCoursesByLang('zh-cn');

// 获取故事内容
const stories = await storyRepo.allStoriesByLang('zh-cn');

// 获取手册内容
const manuals = await manualRepo.allManualsByLang('zh-cn');

API 参考

BlogRepo

  • allBlogsByLang(lang: string) - 获取指定语言的所有博客
  • getFamousBlogs(lang: string, count?: number) - 获取精选博客
  • getBlogsWithTag(lang: string, tag: string) - 根据标签获取博客

CourseRepo

  • allCoursesByLang(lang: string) - 获取指定语言的所有课程
  • getFamousCourses(lang: string, count?: number) - 获取精选课程
  • getCoursesWithTag(lang: string, tag: string) - 根据标签获取课程

StoryRepo

  • allStoriesByLang(lang: string) - 获取指定语言的所有故事
  • getFamousStories(lang: string, count?: number) - 获取精选故事
  • getStoriesWithTag(lang: string, tag: string) - 根据标签获取故事

ManualRepo

  • allManualsByLang(lang: string) - 获取指定语言的所有手册章节
  • getImportantManuals(lang: string, count?: number) - 获取重要章节
  • getManualsWithTag(lang: string, tag: string) - 根据标签获取手册内容
  • getManualsByCategory(lang: string, category: string) - 根据分类获取手册内容
  • getManualStructure(lang: string) - 获取手册的完整目录结构

配置

content.config.ts 中配置内容集合:

import {
  makeBlogCollection,
  makeCourseCollection,
  makeStoryCollection,
  makeManualCollection,
} from '@coffic/cosy-content/schema';

export const collections = {
  blogs: makeBlogCollection('./content/blogs'),
  courses: makeCourseCollection('./content/courses'),
  stories: makeStoryCollection('./content/stories'),
  manuals: makeManualCollection('./content/manuals'),
};

Schema 扩展

支持为任何集合添加自定义字段:

import { z } from 'astro:content';
import { makeStoryCollection } from '@coffic/cosy-content/schema';

export const collections = {
  stories: makeStoryCollection('./content/stories', {
    // 自定义字段
    background: z.string().optional(),
    pageAspectRatio: z.number().optional(),
    textBoxes: z.array(z.object({
      slot: z.string(),
      top: z.number(),
      left: z.number(),
      width: z.number(),
      bg: z.string(),
      content: z.string(),
    })).optional(),
  }),
};

开发

构建

npm run build

测试

npm run test

许可证

MIT License