Skip to content

Commit 695a13d

Browse files
committed
initial commit
1 parent 8940d5f commit 695a13d

22 files changed

+7145
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
.next
4+
tsconfig.json
5+
.env.local

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# File-CMS
2+
3+
File-CMS is a filesystem-based Content Management System (CMS), offering functionality similar to a headless CMS. It provides APIs to fetch content from files stored in a specified convention, making content management easy and developer-friendly.
4+
5+
## Key Features
6+
7+
- **Filesystem-Based**: File-CMS allows you to manage your content directly within the filesystem, making it easy to use version control tools like Git or any other Source Code Management (SCM) system to track changes.
8+
9+
- **Headless CMS**: Like a traditional headless CMS, File-CMS separates content management from front-end presentation. You can fetch content via APIs, giving you full flexibility over how and where your content is displayed.
10+
11+
- **Markdown Support**: Create the content in Markdown format along with metadata
12+
13+
- **Developer-Friendly**: With a simple setup, File-CMS is designed with developers in mind. It integrates seamlessly into modern development workflows, enabling efficient content management and versioning without the need for complex backend systems.
14+
15+
- **Version Control Integration**: Since content is stored as files, you can manage updates, rollback changes, and collaborate with others using Git or any other SCM system. This ensures a clear history of content updates, branching, and merging capabilities.
16+
17+
## How It Works
18+
19+
1. **Store Content**: Store your content in the filesystem using a predefined structure or convention.
20+
21+
2. **Version Control**: Use Git or any other SCM to version and manage content.
22+
23+
3. **Fetch Content**: Use the provided API to fetch the content from the filesystem, and integrate it into your application’s front-end, mobile app, or any other service.
24+
25+
## Content Structure
26+
27+
- **Root Directory**: All content is stored under a specified `rootDir`.
28+
- **Type Folders**: Content is grouped into folders based on its "type" (e.g., `blog`, `product`, `page`).
29+
- **Slug Naming**: Each file is named following the convention `[slug].md`.
30+
31+
### File Format
32+
33+
Each content file is divided into two sections:
34+
35+
1. **Metadata (YAML)**: This section contains metadata for the content (e.g., `title`, `date`, `author`).
36+
2. **Content (Markdown)**: The main content, written in Markdown format.
37+
38+
Example of a content file:
39+
40+
```YAML
41+
title: "Sample Blog Post"
42+
author: "John Doe"
43+
date: "2024-09-06"
44+
tags: ["blog", "example"]
45+
```
46+
# Welcome to the Sample Blog Post
47+
48+
This is an example of content written in Markdown.
49+
50+
> NOTE: Make sure **Meta section** starts with ` ```YAML ` and ends with ` ``` `
51+
52+
### API Response Structure
53+
54+
The content returned from the API follows this structure:
55+
56+
```JSON
57+
{
58+
"type": "blog",
59+
"slug": "sample-blog-post",
60+
"content": "Content in Markdown",
61+
"title": "Sample Blog Post",
62+
"author": "John Doe",
63+
"date": "2024-09-06",
64+
"tags": ["blog", "example"]
65+
}
66+
```
67+
68+
## Why Choose File-CMS?
69+
70+
- **No Databases**: Manage content without needing a database. File-CMS uses the filesystem, simplifying your infrastructure.
71+
72+
- **Versioning Made Easy**: Leverage the power of Git or any SCM for full control over content revisions, changes, and collaboration.
73+
74+
- **Decoupled Architecture**: Fetch content via APIs and render it anywhere—whether in a web application, mobile app, or other environments.
75+
76+
## Getting Started
77+
78+
1. **Install**: Install the npm package
79+
```BASH
80+
npm install file-cms
81+
```
82+
2. **Setup Content Structure**: Organize your content files under a root directory with type folders
83+
```BASH
84+
/rootDir/
85+
/blog/
86+
post-1.md
87+
post-2.md
88+
/product/
89+
product-1.md
90+
```
91+
3. **Use the APIs to fetch the Content**
92+
93+
## Example Usage
94+
95+
### Get Single Content
96+
97+
```TS
98+
import { Config, getContent } from 'file-cms';
99+
Config.setRootDir('/rootDir'); // set the root dir to path where the content is stored
100+
101+
const content = getContent('blog', 'post-1'); // getContent by type and slug
102+
console.log(content);
103+
```
104+
105+
### List contents
106+
107+
```TS
108+
import { Config, listContent } from 'file-cms';
109+
Config.setRootDir('/rootDir'); // set the root dir to path where the content is stored
110+
111+
const contents = listContent({
112+
type: 'blog',
113+
meta: {
114+
keywords: {
115+
has: "serverless"
116+
}
117+
}
118+
}); // list all contents of type blog and containing serverless keyword in the meta section
119+
console.log(contents);
120+
```
121+
122+
> Check [tests](/tests) folder for more examples
123+
124+
## Contributing
125+
126+
Contributions are welcome! Please read the fork and open a PR to improve File-CMS.
127+
128+
## License
129+
130+
File-CMS is released under the MIT License. See the [LICENSE](/LICENSE) file for more details.
131+
132+
## Support
133+
134+
This project is a part of the Open Source Initiative from [Sodaru Technologies](https://sodaru.com)
135+
136+
Write an email to [email protected] for queries on this project

jest.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
testMatch: ["**/tests/**/**.test.ts"],
6+
collectCoverageFrom: ["src/**/*.ts"],
7+
coverageReporters: ["text", "lcov"],
8+
transform: {
9+
"^.+\\.tsx?$": "ts-jest" // for ts & tsx files
10+
},
11+
modulePathIgnorePatterns: ["<rootDir>/dist/"]
12+
};

0 commit comments

Comments
 (0)