Custom External JS/CSS

This commit is contained in:
tangly1024.com
2023-02-01 15:16:02 +08:00
parent 1ac2c5598f
commit e542b271f9
3 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import BLOG from '@/blog.config'
import { loadExternalResource } from '@/lib/utils'
import React from 'react'
/**
* 自定义引入外部JS 和 CSS
* @returns
*/
const ExternalScript = () => {
React.useEffect(() => {
if (BLOG.CUSTOM_EXTERNAL_JS && BLOG.CUSTOM_EXTERNAL_JS.length > 0) {
for (const url of BLOG.CUSTOM_EXTERNAL_JS) {
loadExternalResource(url, 'js')
}
}
if (BLOG.CUSTOM_EXTERNAL_CSS && BLOG.CUSTOM_EXTERNAL_CSS.length > 0) {
for (const url of BLOG.CUSTOM_EXTERNAL_CSS) {
loadExternalResource(url, 'css')
}
}
}, [])
return null
}
export default ExternalScript