@ehp/gatsby-source-drupal
Version:
Gatsby source plugin for building websites using the Drupal CMS as a data source
32 lines (26 loc) • 989 B
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
const nodeFromData = datum => {
const _datum$attributes = datum.attributes,
_datum$attributes2 = _datum$attributes === void 0 ? {} : _datum$attributes,
_attributes_id = _datum$attributes2.id,
attributes = (0, _objectWithoutProperties2.default)(_datum$attributes2, ["id"]);
const preservedId = typeof _attributes_id !== `undefined` ? {
_attributes_id
} : {};
return Object.assign({
id: datum.id,
drupal_id: datum.id,
parent: null,
children: []
}, attributes, preservedId, {
internal: {
type: datum.type.replace(/-|__|:|\.|\s/g, `_`)
}
});
};
exports.nodeFromData = nodeFromData;
exports.normalizeTypeName = function (typeName) {
return typeName.replace(/[_-]{2,}/g, `_`).replace(/[_-]+$/g, ``);
};
;