From 89ae4f64c870cedc759c046e0dae269e71491bb8 Mon Sep 17 00:00:00 2001 From: Joxit Date: Mon, 9 Jan 2023 23:33:27 +0100 Subject: [PATCH] feat(theme): add import SVG for docker image --- package.json | 4 +- rollup.config.js | 2 + rollup/import-svg.js | 29 ++++++++++++++ .../tag-history/tag-history-element.riot | 32 ++++++++++----- src/images/docker-logo.svg | 40 ++----------------- src/scripts/utils.js | 2 + 6 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 rollup/import-svg.js diff --git a/package.json b/package.json index 1335f22..62a9d57 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@rollup/plugin-html": "^1.0.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", + "@rollup/plugin-terser": "^0.2.1", "core-js": "^3.27.1", "node-sass": "^8.0.0", "prettier": "^2.8.1", @@ -39,7 +40,6 @@ "rollup-plugin-copy": "^3.4.0", "rollup-plugin-riot": "^6.0.0", "rollup-plugin-scss": "^4.0.0", - "rollup-plugin-serve": "^2.0.2", - "@rollup/plugin-terser": "^0.2.1" + "rollup-plugin-serve": "^2.0.2" } } diff --git a/rollup.config.js b/rollup.config.js index 9ce9270..ac1d2a4 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -13,6 +13,7 @@ import copy from 'rollup-plugin-copy'; import copyTransform from './rollup/copy-transform.js'; import license from './rollup/license.js'; import checkOutput from './rollup/check-output.js'; +import importSVG from './rollup/import-svg.js'; const useServe = process.env.ROLLUP_SERVE === 'true'; const output = useServe ? '.serve' : 'dist'; @@ -20,6 +21,7 @@ const output = useServe ? '.serve' : 'dist'; const plugins = [ riot(), json(), + importSVG(), nodeResolve(), commonjs(), scss({ fileName: `docker-registry-ui.css`, outputStyle: 'compressed' }), diff --git a/rollup/import-svg.js b/rollup/import-svg.js new file mode 100644 index 0000000..91832fc --- /dev/null +++ b/rollup/import-svg.js @@ -0,0 +1,29 @@ +import {extname} from 'path'; + +const injectNode = (svg) => (` +export default function() { + return (new DOMParser().parseFromString(${svg}, 'image/svg+xml')); +}; +`); + +/** + * @param options + * @param options.include + * @param options.exclude + * @param options.stringify - if true returns String, otherwise returns DOM Node + */ +export default function () { + + return { + name: 'import-svg', + transform: (code, id) => { + if (extname(id) !== '.svg') return null; + const content = JSON.stringify(code); + + return { + code: injectNode(content), + map: { mappings: '' }, + }; + }, + }; +}; \ No newline at end of file diff --git a/src/components/tag-history/tag-history-element.riot b/src/components/tag-history/tag-history-element.riot index cd3050a..2bc86f0 100644 --- a/src/components/tag-history/tag-history-element.riot +++ b/src/components/tag-history/tag-history-element.riot @@ -16,8 +16,9 @@ along with this program. If not, see . -->
- { state.icon } -

{ state.name }

+ { state.icon } + + { state.name }
{ state.value }
@@ -25,6 +26,7 @@ along with this program. If not, see .