add-cms
This commit is contained in:
38
source/admin/packages/decap-cms-lib-util/src/APIUtils.ts
Normal file
38
source/admin/packages/decap-cms-lib-util/src/APIUtils.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export const CMS_BRANCH_PREFIX = 'cms';
|
||||
export const DEFAULT_PR_BODY = 'Automatically generated by Decap CMS';
|
||||
export const MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Decap CMS.';
|
||||
|
||||
const DEFAULT_DECAP_CMS_LABEL_PREFIX = 'decap-cms/';
|
||||
|
||||
function getLabelPrefix(labelPrefix: string) {
|
||||
return labelPrefix || DEFAULT_DECAP_CMS_LABEL_PREFIX;
|
||||
}
|
||||
|
||||
export function isCMSLabel(label: string, labelPrefix: string) {
|
||||
return label.startsWith(getLabelPrefix(labelPrefix));
|
||||
}
|
||||
|
||||
export function labelToStatus(label: string, labelPrefix: string) {
|
||||
return label.slice(getLabelPrefix(labelPrefix).length);
|
||||
}
|
||||
|
||||
export function statusToLabel(status: string, labelPrefix: string) {
|
||||
return `${getLabelPrefix(labelPrefix)}${status}`;
|
||||
}
|
||||
|
||||
export function generateContentKey(collectionName: string, slug: string) {
|
||||
return `${collectionName}/${slug}`;
|
||||
}
|
||||
|
||||
export function parseContentKey(contentKey: string) {
|
||||
const index = contentKey.indexOf('/');
|
||||
return { collection: contentKey.slice(0, index), slug: contentKey.slice(index + 1) };
|
||||
}
|
||||
|
||||
export function contentKeyFromBranch(branch: string) {
|
||||
return branch.slice(`${CMS_BRANCH_PREFIX}/`.length);
|
||||
}
|
||||
|
||||
export function branchFromContentKey(contentKey: string) {
|
||||
return `${CMS_BRANCH_PREFIX}/${contentKey}`;
|
||||
}
|
||||
Reference in New Issue
Block a user