Add latest gh-icon changes

This commit is contained in:
Eric Fennis
2023-05-10 00:12:35 +02:00
parent 44b602e6e4
commit ce16c3c569
5 changed files with 243 additions and 21 deletions
+20 -3
View File
@@ -1,7 +1,11 @@
import { eventHandler, getQuery, setResponseHeader, defaultContentType } from 'h3'
import { renderToString } from 'react-dom/server'
import { eventHandler, setResponseHeader, defaultContentType } from 'h3'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import { createElement } from 'react'
import SvgPreview from '../../lib/SvgPreview/index.tsx';
import * as iconNodes from '../../data/iconNodes'
import { camelCase } from 'lodash-es'
import createLucideIcon from 'lucide-react/src/createLucideIcon'
import Backdrop from '../../lib/SvgPreview/Backdrop.tsx';
export default eventHandler((event) => {
const { params } = event.context
@@ -11,8 +15,21 @@ export default eventHandler((event) => {
const src = Buffer.from(data, 'base64').toString('utf8');
const children = []
const camelCaseName = camelCase(name)
if (camelCaseName in iconNodes) {
const iconNode = iconNodes[camelCaseName]
const LucideIcon = createLucideIcon(name, iconNode)
const svg = renderToStaticMarkup(createElement(LucideIcon))
const backdropString = svg.replace(/<svg[^>]*>|<\/svg>/g, '');
children.push(createElement(Backdrop, { backdropString, src }))
}
const svg = Buffer.from(
renderToString(createElement(SvgPreview, {src, showGrid: true}))
renderToString(createElement(SvgPreview, {src, showGrid: true}, children))
).toString('utf8');
defaultContentType(event, 'image/svg+xml')