@maxlkatze/cms
Version:
A git based Nuxt Module CMS - zero effort, zero cost
33 lines (32 loc) • 990 B
JavaScript
import { ref } from "vue";
import { useEditContentStorage } from "./useEditContentStorage.js";
import { toRef, useRuntimeConfig } from "#imports";
const isCMSUser = ref(false);
export const useContentSource = () => {
const runtimeConfig = useRuntimeConfig();
const content = runtimeConfig.public.content;
const editContentStorage = useEditContentStorage();
const enableCMSMode = async () => {
if (import.meta.server) return;
await editContentStorage.loadContent();
isCMSUser.value = true;
};
const getContentByKey = (key, defaultValue) => {
if (isCMSUser.value) {
if (!editContentStorage.editContent.value[key]) {
editContentStorage.editContent.value[key] = defaultValue;
}
return toRef(editContentStorage.editContent.value, key, defaultValue);
}
if (!content[key]) {
return defaultValue;
}
return content[key];
};
return {
enableCMSMode,
getContentByKey,
isCMSUser,
editContentStorage
};
};