UNPKG

@nuxt/content

Version:

Write your content inside your Nuxt app

31 lines (30 loc) 833 B
import contentManifest from "#content/manifest"; export function refineContentFields(sql, doc) { const fields = findCollectionFields(sql); const item = { ...doc }; for (const key in item) { if (fields[key] === "json" && item[key] && item[key] !== "undefined") { item[key] = JSON.parse(item[key]); } if (fields[key] === "boolean" && item[key] !== "undefined") { item[key] = Boolean(item[key]); } } for (const key in item) { if (item[key] === "NULL") { item[key] = void 0; } } return item; } function findCollectionFields(sql) { const table = sql.match(/FROM\s+(\w+)/); if (!table) { return {}; } const info = contentManifest[getCollectionName(table[1])]; return info?.fields || {}; } function getCollectionName(table) { return table.replace(/^_content_/, ""); }