diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0199b2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +vendor +mix-manifest.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..068e853 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Graphql Svg String + +**Graphql Svg String** is a Statamic addon that adds a field `svgString` to an `AssetInterface`, which – you guessed it – returns the SVG as a string. + +## How to Install + +You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root: + +```bash +composer require el-schneider/graphql-svg-string +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e88f87f --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "el-schneider/graphql-svg-string", + "autoload": { + "psr-4": { + "ElSchneider\\GraphqlSvgString\\": "src" + } + }, + "extra": { + "statamic": { + "name": "Graphql Svg String", + "description": "Graphql Svg String addon" + }, + "laravel": { + "providers": [ + "ElSchneider\\GraphqlSvgString\\ServiceProvider" + ] + } + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php new file mode 100644 index 0000000..bc38cd2 --- /dev/null +++ b/src/ServiceProvider.php @@ -0,0 +1,29 @@ + GraphQL::type('String'), + "resolve" => function (Asset $asset) { + if ($asset->extension() === 'svg') { + return $asset->contents(); + } + return null; + } + ]; + } + ); + } +}