inlinecms
Version:
Real-time inline CMS for Astro with post management, frontmatter editing, and live preview
232 lines (175 loc) ⢠6.34 kB
Markdown
# InlineCMS
## Simplest CMS for Astro blogs
A modern, TypeScript-first Astro integration that enables seamless inline editing of Markdown content during development. Edit blog posts, documentation, and any markdown-based content directly in your browser with real-time auto-save.
https://github.com/user-attachments/assets/01702a21-deac-4302-9ba5-3155d4236d2a
## ⨠Features
- **ā” Real-time Editing** - Click any content and start typing
- **š Post Management** - Create, delete, and manage posts with clean UI
- **āļø Frontmatter Editor** - Edit YAML frontmatter with syntax validation
- **ā¶ Undo/Redo System** - Full history tracking with Ctrl+Z/Ctrl+Y
- **š¾ Smart Auto-save** - Debounced saving with retry logic and error recovery
- **š¼ļø Image Support** - Drag & drop images with file type validation
- **āØļø Rich Keyboard Shortcuts** - Bold (Ctrl+B), Italic (Ctrl+I), Links (Ctrl+K)
- **š Markdown Aware** - Proper list indentation, heading levels, code blocks
- **š Unsaved Changes Tracking** - Visual indicators and browser warnings
- **š§© Plugin System** - Modular architecture with focused classes
- **šØ Professional UX** - Smooth animations, toast notifications, modal dialogs
- **š± TypeScript First** - Full type safety and IntelliSense support
## š¦ Installation
```bash
npm install inlinecms
# or
bun add inlinecms
# or
pnpm add inlinecms
# or
yarn add inlinecms
```
## š Quick Start
### 1. Add the Integration
```ts
// astro.config.mjs
import inlineCMS from "inlinecms";
export default {
integrations: [inlineCMS("src/content/blog")],
};
```
### 2. Wrap Your Markdown Content
```astro
<!-- src/layouts/BlogLayout.astro -->
<div data-markdown>
<slot />
</div>
```
### 3. Start Developing
```bash
npm run dev
```
That's it! Your markdown content is now editable inline during development.
## āļø Configuration
### Basic Usage
```ts
// Simple string for content directory
inlineCMS("src/content/blog");
```
### Advanced Configuration
```ts
// Full configuration object
inlineCMS({
contentDir: "src/content/blog",
urlPattern: "/posts/{slug}/", // URL pattern (default: "/posts/{slug}/")
autosaveDelay: 1000, // Auto-save delay in ms (default: 2000)
enabled: true, // Enable/disable (default: true)
});
```
### Environment-based Setup
```ts
// Only enable in development
inlineCMS({
contentDir: "src/content/blog",
enabled: import.meta.env.DEV,
});
```
## š® Usage Guide
### Editing Content
- **Click** any text to start editing
- **Type naturally** - content auto-saves after 2 seconds of inactivity
- **Status indicator** shows current state (editing, saving, saved)
### Keyboard Shortcuts
**Post Management:**
- `Ctrl+N` - Create new post
- `Ctrl+Shift+L` - List all posts
- `Ctrl+Shift+F` - Edit frontmatter
- `Ctrl+Shift+D` - Delete current post
**Editing:**
- `Ctrl+S` - Manual save
- `Ctrl+Z` - Undo
- `Ctrl+Y` / `Ctrl+Shift+Z` - Redo
- `Ctrl+B` - Toggle bold
- `Ctrl+I` - Toggle italic
- `Ctrl+K` - Create/edit links
- `Tab` - Indent list items or add 4 spaces in code blocks
- `Shift+Tab` - Outdent list items or remove indentation in code blocks
- `Backspace` (at heading start) - Decrease heading level
- `Enter` (in empty list item) - Exit list
### Images
- **Drag & drop** images directly into content
- **File type validation** (JPG, PNG, GIF, WebP, SVG)
- **Size limits** (10MB max)
- Automatic upload to `public/uploads/` directory
- Proper markdown image syntax generation
### Post Management UI
- **Floating sidebar** for easy access
- **Toast notifications** for user feedback
- **Modal dialogs** for post creation and editing
- **Frontmatter editor** with YAML syntax validation
### Lists & Structure
- Smart list handling with Tab/Shift+Tab indentation
- Automatic list exit when pressing Enter in empty items
- Heading level management with Backspace
- Code block editing with proper Tab behavior
## š”ļø Error Handling
InlineCMS includes robust error handling:
- **Automatic retry** with exponential backoff (1s, 2s, 4s delays)
- **Network failure recovery** with user-friendly dialogs
- **Unsaved changes warnings** before page navigation
- **Detailed error logging** for debugging
## š§ Development
### Setup
```bash
git clone <repository>
cd inlinecms
bun install
```
### Build
```bash
bun run build # Build for production
bun run type-check # TypeScript type checking
bun run format # Format code with Prettier
```
### Project Structure
```
inlinecms/
āāā src/
ā āāā core/
ā ā āāā InlineCMS.ts # Main editor class
ā ā āāā StatusManager.ts # Status handling
ā ā āāā UndoRedoManager.ts # Undo/redo system
ā āāā plugins/
ā ā āāā MathPlugin.ts # LaTeX handling
ā ā āāā CodePlugin.ts # Code blocks
ā ā āāā ImagePlugin.ts # Image uploads
ā ā āāā ListPlugin.ts # List management
ā ā āāā PostAPI.ts # API communication
ā ā āāā PostManagementPlugin.ts # Post management UI
ā ā āāā ModalManager.ts # Modal dialogs
ā ā āāā index.ts # Plugin exports
ā āāā utils/
ā ā āāā dom.ts # DOM utilities
ā ā āāā keyboard.ts # Key handling
ā āāā styles/
ā ā āāā editor.css # Editor styles
ā āāā types/
ā ā āāā index.ts # Type definitions
ā āāā main.ts # Entry point
āāā index.ts # Integration code
āāā index.d.ts # TypeScript definitions
āāā dist/ # Built files
āāā index.js # Server integration
āāā client.js # Client-side bundle
```
## š TypeScript Support
InlineCMS is built with TypeScript-first principles:
```ts
import type { InlineCMSConfig } from "inlinecms";
const config: InlineCMSConfig = {
contentDir: "src/content/blog",
autosaveDelay: 1500,
enabled: import.meta.env.DEV,
};
```
Full IntelliSense support for configuration options and API.
## š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## š License
MIT License - see LICENSE file for details.