@staticcms/proxy-server-lite
Version:
Proxy server to be used with Static CMS proxy backend
41 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.branchFromContentKey = exports.contentKeyFromBranch = exports.statusToLabel = exports.labelToStatus = exports.isCMSLabel = exports.parseContentKey = exports.generateContentKey = exports.MERGE_COMMIT_MESSAGE = exports.DEFAULT_PR_BODY = exports.DEFAULT_STATIC_CMS_LABEL_PREFIX = exports.CMS_BRANCH_PREFIX = void 0;
exports.CMS_BRANCH_PREFIX = 'cms';
exports.DEFAULT_STATIC_CMS_LABEL_PREFIX = 'static-cms/';
exports.DEFAULT_PR_BODY = 'Automatically generated by Static CMS';
exports.MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Static CMS.';
function generateContentKey(collectionName, slug) {
return `${collectionName}/${slug}`;
}
exports.generateContentKey = generateContentKey;
function parseContentKey(contentKey) {
const index = contentKey.indexOf('/');
return { collection: contentKey.slice(0, index), slug: contentKey.slice(index + 1) };
}
exports.parseContentKey = parseContentKey;
function getLabelPrefix(labelPrefix) {
return labelPrefix !== null && labelPrefix !== void 0 ? labelPrefix : exports.DEFAULT_STATIC_CMS_LABEL_PREFIX;
}
function isCMSLabel(label, labelPrefix) {
return label.startsWith(getLabelPrefix(labelPrefix));
}
exports.isCMSLabel = isCMSLabel;
function labelToStatus(label, labelPrefix) {
var _a;
return (_a = label.slice(getLabelPrefix(labelPrefix).length)) !== null && _a !== void 0 ? _a : 'draft';
}
exports.labelToStatus = labelToStatus;
function statusToLabel(status, labelPrefix) {
return `${getLabelPrefix(labelPrefix)}${status}`;
}
exports.statusToLabel = statusToLabel;
function contentKeyFromBranch(branch) {
return branch.slice(`${exports.CMS_BRANCH_PREFIX}/`.length);
}
exports.contentKeyFromBranch = contentKeyFromBranch;
function branchFromContentKey(contentKey) {
return `${exports.CMS_BRANCH_PREFIX}/${contentKey}`;
}
exports.branchFromContentKey = branchFromContentKey;
//# sourceMappingURL=APIUtils.js.map