cmslab
v3.0.1
Published
a git-based cms package that provide variase composables to interact and create a content-based website/command line tool
Downloads
10
Readme
CMSLab is a github-based CMS package that provide variase functionality to fetch and built a CMS on top of GitHub API
the package is open-source, means you can customize the functionality exactly as you want. if you've developed something unique and want to include your code on the next release, Please contact me Here or send an email to [email protected]
Installation
tip: Always use CMSLab latest version to receive recent updates and bug fixes
to install CMSLab on your project, go to your project directory and run:
npm I cmslab@latest
after installing the package, you can import and use the functionality from boath cjs and mjs:
// example.cjs
const cms = require('cmslab');
cms.configure({user: 'github', repo: 'docs'});
async function main() {
const content = await cms.searchContent({input: 'API'});
console.log(content);
}
main();
or in mjs:
// example.mjs
import cms from 'cmslab';
// you can also use tree-shakable sintacs to import only the function that you need:
// import {configure, searchContent} from 'cmslab';
cms.configure({user: 'github', repo: 'docs'});
async function main() {
const content = await cms.searchContent({input: 'API'});
console.log(content);
}
main();
features
Here is the list of features that CMSLab version 3.x supports. we're regularly observing the usage patern of our package to built new features
Configure metadata: to remember your configuration so you do not need to pass the same informations again and again
Authenticated Requests: to get more rate-limit on GitHub API
extract user information, repozatory information, and file path from an GitHub URL: to extract and process any data from a plane GitHub link
formatNavigation: a function to format a GitHub response and return an structured Array to create a sidebar
getList: fetch the List of articles from a relative or apsilute path
getSingle: fetch a single article from a filename
built-in excerpt and last updated date extraction fasility: to display on your archive or post page
searchContent: to lookup about a specific text on your base directory(and/or any subdirectory)
complete usage
configure metadata to use on all requests
note: you can override any metadata by passing it to the options object in the specific function
cms.configure({
user: "GitHub", // your GitHub username
repo: "docs", // your GitHub repo to lookup articles
path: "", // any base path you want to set by default. leave it to set a blank path("")
token: null // your GitHub personal token to make authenticated requests. leave it to make unauthenticated requests
});
get list of articles
// getting the list of articles from the default path
const articles = await cms.getList();
// passing our own options(you can pass any valid options similar to the configure function)
const articles = await cms.getList({path: "src"});
console.log(articles);
search Content
const content = await cms.searchContent({input: "API"});
console.log(content);
get a single article
const single = await cms.getSingle({filename: "src/account/using-profile.md"});
console.log(single);
extracting informations from a plane,github URL
const url = "https://github.com/github/docs/src/account/introduction.md";
const metadata = cms.getInfo(url);
console.log(metadata);
formatting a GitHub rest API response to create a sidebar
const sidebar = cms.formatNavigation(response);
console.log(sidebar);
response object
the response Object is contains 2fields:
- data: the main field for success responses. for list of posts, the data is an Array and for single post, the data is an Object
- error: a string containing the error message if the response encountered an error while processing if the response successful, the error field will be null and if the response encountered an error, the data field will be null
for list of posts, the data field should looks like:
[
{
"name": "something.md",
"path": "src/something.md",
"link": "https://api.github.com/repos/user/repo/contents/src/something.md?ref=main/src/something.md",
"type": "file",
"updated": "2024-08-23T07:17:54Z",
"excerpt": "once apon a time, there [...]",
"content": "full content"
},
{...},
...
]
and a single post's response is the same but this time, the response will be just a single item instead of Array of items
feature requests
I welcome new feature requests. please contact me here or send an email to m at [email protected]