Spaces:
Running
Running
Upload scripts/render-card.mjs with huggingface_hub
Browse files- scripts/render-card.mjs +47 -0
scripts/render-card.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
| 2 |
+
import { join } from 'node:path'
|
| 3 |
+
import React from 'react'
|
| 4 |
+
import { renderToStaticMarkup } from 'react-dom/server'
|
| 5 |
+
import App from '../.ssr/App.js'
|
| 6 |
+
|
| 7 |
+
// The org card on hf.co is an inline, sanitized copy of this file: no
|
| 8 |
+
// scripts, no external assets. The rendered HTML must be self-contained.
|
| 9 |
+
// CSS is inlined below; the logo is already a data URI in the markup.
|
| 10 |
+
const css = readdirSync('dist/assets')
|
| 11 |
+
.filter((f) => f.endsWith('.css'))
|
| 12 |
+
.map((f) => readFileSync(join('dist/assets', f), 'utf8'))
|
| 13 |
+
.join('\n')
|
| 14 |
+
|
| 15 |
+
const logoB64 = readFileSync(
|
| 16 |
+
'src/assets/logo-horizontal.svg',
|
| 17 |
+
'utf8',
|
| 18 |
+
).replace(/\s+/g, ' ').trim()
|
| 19 |
+
|
| 20 |
+
// Substitute the placeholder with a self-contained data URI.
|
| 21 |
+
const body = renderToStaticMarkup(React.createElement(App)).replace(
|
| 22 |
+
/@LOGO_DATA_URI@/g,
|
| 23 |
+
'data:image/svg+xml;base64,' + Buffer.from(logoB64, 'utf8').toString('base64'),
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
const html = `<!doctype html>
|
| 27 |
+
<html lang="en">
|
| 28 |
+
<head>
|
| 29 |
+
<meta charset="UTF-8" />
|
| 30 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 31 |
+
<title>Orchestrel AI</title>
|
| 32 |
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
| 33 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
| 34 |
+
<link
|
| 35 |
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=JetBrains+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap"
|
| 36 |
+
rel="stylesheet"
|
| 37 |
+
/>
|
| 38 |
+
<style>${css}</style>
|
| 39 |
+
</head>
|
| 40 |
+
<body>
|
| 41 |
+
${body}
|
| 42 |
+
</body>
|
| 43 |
+
</html>
|
| 44 |
+
`
|
| 45 |
+
|
| 46 |
+
writeFileSync('dist/index.html', html)
|
| 47 |
+
console.log('rendered dist/index.html (' + html.length + ' bytes, self-contained)')
|