diff --git a/themes/hexo/components/Hero.js b/themes/hexo/components/Hero.js index 6c7bb17a..67ae3468 100644 --- a/themes/hexo/components/Hero.js +++ b/themes/hexo/components/Hero.js @@ -1,11 +1,11 @@ // import Image from 'next/image' -import { useEffect, useState } from 'react' -import Typed from 'typed.js' -import CONFIG from '../config' -import NavButtonGroup from './NavButtonGroup' -import { useGlobal } from '@/lib/global' import LazyImage from '@/components/LazyImage' import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import { loadExternalResource } from '@/lib/utils' +import { useEffect, useState } from 'react' +import CONFIG from '../config' +import NavButtonGroup from './NavButtonGroup' let wrapperTop = 0 @@ -20,21 +20,29 @@ const Hero = props => { const scrollToWrapper = () => { window.scrollTo({ top: wrapperTop, behavior: 'smooth' }) } + const GREETING_WORDS = siteConfig('GREETING_WORDS').split(',') useEffect(() => { updateHeaderHeight() if (!typed && window && document.getElementById('typed')) { - changeType( - new Typed('#typed', { - strings: GREETING_WORDS, - typeSpeed: 200, - backSpeed: 100, - backDelay: 400, - showCursor: true, - smartBackspace: true - }) - ) + loadExternalResource( + 'https://cdn.jsdelivr.net/npm/typed.js@2.0.12', + 'js' + ).then(() => { + if (window.Typed) { + changeType( + new window.Typed('#typed', { + strings: GREETING_WORDS, + typeSpeed: 200, + backSpeed: 100, + backDelay: 400, + showCursor: true, + smartBackspace: true + }) + ) + } + }) } window.addEventListener('resize', updateHeaderHeight) @@ -51,33 +59,43 @@ const Hero = props => { } return ( - ) } diff --git a/themes/matery/components/Hero.js b/themes/matery/components/Hero.js index cd2f19ab..267ae006 100644 --- a/themes/matery/components/Hero.js +++ b/themes/matery/components/Hero.js @@ -1,10 +1,10 @@ // import Image from 'next/image' -import { useEffect, useState } from 'react' -import Typed from 'typed.js' -import CONFIG from '../config' -import { useGlobal } from '@/lib/global' import LazyImage from '@/components/LazyImage' import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import { loadExternalResource } from '@/lib/utils' +import { useEffect, useState } from 'react' +import CONFIG from '../config' let wrapperTop = 0 @@ -21,16 +21,23 @@ const Hero = props => { useEffect(() => { updateHeaderHeight() if (!typed && window && document.getElementById('typed')) { - changeType( - new Typed('#typed', { - strings: GREETING_WORDS, - typeSpeed: 200, - backSpeed: 100, - backDelay: 400, - showCursor: true, - smartBackspace: true - }) - ) + loadExternalResource( + 'https://cdn.jsdelivr.net/npm/typed.js@2.0.12', + 'js' + ).then(() => { + if (window.Typed) { + changeType( + new window.Typed('#typed', { + strings: GREETING_WORDS, + typeSpeed: 200, + backSpeed: 100, + backDelay: 400, + showCursor: true, + smartBackspace: true + }) + ) + } + }) } window.addEventListener('resize', updateHeaderHeight) @@ -47,29 +54,40 @@ const Hero = props => { } return ( - ) }