diff --git a/package.json b/package.json index 9b130656..314871fa 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,7 @@ "react-hotkeys-hook": "^4.5.0", "react-notion-x": "6.16.0", "react-share": "^4.4.1", - "react-tweet-embed": "~2.0.0", - "typed.js": "^2.0.12" + "react-tweet-embed": "~2.0.0" }, "devDependencies": { "@waline/client": "^2.5.1", 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 ( - ) } diff --git a/yarn.lock b/yarn.lock index ced20b9f..ffe43bd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4048,11 +4048,6 @@ typed-array-length@^1.0.4: for-each "^0.3.3" is-typed-array "^1.1.9" -typed.js@^2.0.12: - version "2.1.0" - resolved "https://registry.yarnpkg.com/typed.js/-/typed.js-2.1.0.tgz#b97a06111a5f57d6a59acfdd36d4f9b891ee13b4" - integrity sha512-bDuXEf7YcaKN4g08NMTUM6G90XU25CK3bh6U0THC/Mod/QPKlEt9g/EjvbYB8x2Qwr2p6J6I3NrsoYaVnY6wsQ== - unbox-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"