Move to custom SSG instead of eleventy.
This commit is contained in:
19
docs/renderer/util/feather-icons.js
Normal file
19
docs/renderer/util/feather-icons.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import feather from 'feather-icons'
|
||||
|
||||
const defaultAttributes = {
|
||||
"class": "feather feather-x",
|
||||
"xmlns": "http://www.w3.org/2000/svg",
|
||||
"width": 24,
|
||||
"height": 24,
|
||||
"viewBox": "0 0 24 24",
|
||||
"fill": "none",
|
||||
"stroke": "currentColor",
|
||||
"stroke-width": 2,
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
}
|
||||
|
||||
export default (iconName, attributes = {}) => {
|
||||
attributes = { ...defaultAttributes, ...attributes }
|
||||
return feather.icons[iconName].toSvg(attributes)
|
||||
}
|
||||
45
docs/renderer/util/google-fonts.js
Normal file
45
docs/renderer/util/google-fonts.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import https from 'node:https'
|
||||
|
||||
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
|
||||
|
||||
const isValidURL = url => {
|
||||
return /fonts.googleapis.com/.test(url)
|
||||
}
|
||||
|
||||
const downloadFont = url => {
|
||||
return new Promise((resolve) => {
|
||||
let rawData = ''
|
||||
https.get(
|
||||
url,
|
||||
{
|
||||
headers: {
|
||||
'user-agent': UA,
|
||||
},
|
||||
},
|
||||
res => {
|
||||
res.on('data', chunk => {
|
||||
rawData += chunk
|
||||
})
|
||||
res.on('end', () => {
|
||||
resolve(rawData.toString('utf8'))
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const createInlineCss = async url => {
|
||||
if (!isValidURL(url)) {
|
||||
throw new Error('Invalid Google Fonts URL')
|
||||
}
|
||||
|
||||
const content = await downloadFont(url)
|
||||
|
||||
return (
|
||||
`<link rel="preconnect" href="https://fonts.gstatic.com">`+
|
||||
`<link data-href="${url}" rel="stylesheet">`+
|
||||
`<style data-href='${url}'>${content}</style>`
|
||||
)
|
||||
}
|
||||
|
||||
export default createInlineCss
|
||||
Reference in New Issue
Block a user