UNPKG

gatsby-source-prismic

Version:

Gatsby source plugin for building websites using Prismic as a data source

1 lines 3.71 kB
{"version":3,"file":"buildImageObjectType.cjs","sources":["../../../src/lib/buildImageObjectType.ts"],"sourcesContent":["import { ImageFieldImage, isFilled } from \"@prismicio/client\";\nimport type {\n\tGatsbyCache,\n\tGatsbyGraphQLObjectType,\n\tNodePluginSchema,\n} from \"gatsby\";\nimport type { ImgixURLParams } from \"imgix-url-builder\";\nimport { buildURL } from \"imgix-url-builder\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { DEFAULT_IMGIX_PARAMS } from \"../constants\";\n\nimport { buildGatsbyImageDataFieldConfig } from \"./buildGatsbyImageDataFieldConfig\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildImageObjectTypeConfig = {\n\tschema: NodePluginSchema;\n\tcache: GatsbyCache;\n\tpluginOptions: PluginOptions;\n};\n\nexport const buildImageObjectType = (\n\tconfig: BuildImageObjectTypeConfig,\n): GatsbyGraphQLObjectType => {\n\treturn config.schema.buildObjectType({\n\t\tname: pascalCase(\"Prismic\", config.pluginOptions.typePrefix, \"ImageField\"),\n\t\tdescription: \"An Image field.\",\n\t\tfields: {\n\t\t\talt: {\n\t\t\t\ttype: \"String\",\n\t\t\t\tdescription: \"An alternative text for the image.\",\n\t\t\t},\n\t\t\tcopyright: {\n\t\t\t\ttype: \"String\",\n\t\t\t\tdescription: \"Copyright information for the image.\",\n\t\t\t},\n\t\t\tdimensions: {\n\t\t\t\ttype: \"PrismicImageFieldDimensions\",\n\t\t\t\tdescription: \"The image's width and height.\",\n\t\t\t},\n\t\t\turl: {\n\t\t\t\ttype: \"String\",\n\t\t\t\tdescription: \"The image's URL.\",\n\t\t\t\targs: {\n\t\t\t\t\timgixParams: {\n\t\t\t\t\t\ttype: \"PrismicImgixURLParams\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Parameters to modify the image output using Imgix's URL API. To learn more, see: https://docs.imgix.com/apis/rendering\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tresolve: (\n\t\t\t\t\tsource: ImageFieldImage,\n\t\t\t\t\targs: { imgixParams?: ImgixURLParams },\n\t\t\t\t): string | null => {\n\t\t\t\t\tif (isFilled.imageThumbnail(source)) {\n\t\t\t\t\t\treturn buildURL(source.url, {\n\t\t\t\t\t\t\t...DEFAULT_IMGIX_PARAMS,\n\t\t\t\t\t\t\t...config.pluginOptions.imageImgixParams,\n\t\t\t\t\t\t\t...args.imgixParams,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\tgatsbyImageData: buildGatsbyImageDataFieldConfig({\n\t\t\t\tcache: config.cache,\n\t\t\t\tpluginOptions: config.pluginOptions,\n\t\t\t}),\n\t\t\tlocalFile: {\n\t\t\t\ttype: \"File\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"The locally download image file if the field is configured to download locally.\",\n\t\t\t\textensions: { link: {} },\n\t\t\t},\n\t\t},\n\t\tinterfaces: [\"PrismicImageFieldBase\"],\n\t});\n};\n"],"names":["pascalCase","isFilled","buildURL","DEFAULT_IMGIX_PARAMS","buildGatsbyImageDataFieldConfig"],"mappings":";;;;;;;AAsBa,MAAA,uBAAuB,CACnC,WAC4B;AACrB,SAAA,OAAO,OAAO,gBAAgB;AAAA,IACpC,MAAMA,WAAW,WAAA,WAAW,OAAO,cAAc,YAAY,YAAY;AAAA,IACzE,aAAa;AAAA,IACb,QAAQ;AAAA,MACP,KAAK;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACb;AAAA,MACD,WAAW;AAAA,QACV,MAAM;AAAA,QACN,aAAa;AAAA,MACb;AAAA,MACD,YAAY;AAAA,QACX,MAAM;AAAA,QACN,aAAa;AAAA,MACb;AAAA,MACD,KAAK;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,QACb,MAAM;AAAA,UACL,aAAa;AAAA,YACZ,MAAM;AAAA,YACN,aACC;AAAA,UACD;AAAA,QACD;AAAA,QACD,SAAS,CACR,QACA,SACkB;AACd,cAAAC,QAAA,SAAS,eAAe,MAAM,GAAG;AAC7B,mBAAAC,gBAAA,SAAS,OAAO,KAAK;AAAA,cAC3B,GAAGC,UAAA;AAAA,cACH,GAAG,OAAO,cAAc;AAAA,cACxB,GAAG,KAAK;AAAA,YAAA,CACR;AAAA,UAAA,OACK;AACC,mBAAA;AAAA,UACP;AAAA,QACF;AAAA,MACA;AAAA,MACD,iBAAiBC,gCAAAA,gCAAgC;AAAA,QAChD,OAAO,OAAO;AAAA,QACd,eAAe,OAAO;AAAA,MAAA,CACtB;AAAA,MACD,WAAW;AAAA,QACV,MAAM;AAAA,QACN,aACC;AAAA,QACD,YAAY,EAAE,MAAM,GAAI;AAAA,MACxB;AAAA,IACD;AAAA,IACD,YAAY,CAAC,uBAAuB;AAAA,EAAA,CACpC;AACF;;"}