Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@cogita/core

npm version License: MIT

中文 | English

智能编排 Cogita 主题驱动架构的核心引擎

这是什么?

@cogita/core 是 Cogita 框架的大脑。它自动加载主题、管理插件,并提供类型安全的配置系统,让构建博客就像选择主题一样简单。

核心特性

  • 🎨 主题驱动:主题自动加载所需的插件
  • ⚙️ 类型安全:完整的 TypeScript 支持和智能默认值
  • 🔧 零配置:开箱即用,需要时可自定义
  • Rspress 驱动:基于快速现代的 Rspress 基础

快速开始

安装

pnpm add @cogita/core @cogita/theme-lucid

基础使用

创建 cogita.config.ts

import { defineConfig } from '@cogita/core';

export default defineConfig({
  site: {
    title: '我的博客',
    description: '使用 Cogita 构建的博客',
  },
  theme: 'lucid', // 主题处理其他一切!
});

posts/hello.md 中创建第一篇文章:

---
title: "你好,Cogita!"
createDate: "2024-01-01"
---

# 欢迎来到我的博客!

启动开发服务器:

pnpm dev

就这样!你的博客已经在 http://localhost:3000 准备好了。

工作原理

  1. 加载配置:读取你的 cogita.config.ts
  2. 加载主题:自动加载指定的主题
  3. 注册插件:主题声明其插件依赖
  4. 生成配置:创建优化的 Rspress 配置
  5. 构建/服务:使用 Rspress 为你的博客提供动力

配置

基础站点配置

export default defineConfig({
  site: {
    title: '我的博客',              // 站点标题
    description: '我的精彩博客',     // 元描述
    base: '/blog/',               // 基础 URL(子路径)
  },
  theme: 'lucid',                // 主题名称
});

高级配置

export default defineConfig({
  site: { /* ... */ },
  theme: 'lucid',
  
  // 透传给 Rspress 主题配置
  themeConfig: {
    nav: [
      { text: '首页', link: '/' },
      { text: '关于', link: '/about' },
    ],
    socialLinks: [
      { icon: 'github', mode: 'link', content: 'https://github.com/you' }
    ],
  },
  
  // 透传给 Rspress 构建配置
  builderConfig: {
    output: { assetPrefix: 'https://cdn.example.com/' }
  },
});

API 参考

defineConfig(config: CogitaConfig)

类型安全的配置助手。

loadCogitaConfig(root?: string)

从项目目录加载配置。

主要类型

interface CogitaConfig {
  site?: {
    title?: string;
    description?: string; 
    base?: string;
  };
  theme?: string;
  themeConfig?: any;    // Rspress 主题配置
  builderConfig?: any;  // Rspress 构建配置
}

可用主题

  • lucid(默认)- 简洁、专注内容的博客主题
  • 更多主题即将推出...

开发命令

# 开发
pnpm dev

# 构建
pnpm build

# 预览构建结果
pnpm preview

了解更多

相关包

许可证

MIT © wu9o