diff --git a/components/Ackee.js b/components/Ackee.js index 8a002bc1..95c6001e 100644 --- a/components/Ackee.js +++ b/components/Ackee.js @@ -4,42 +4,45 @@ import { useEffect } from 'react' import BLOG from '@/blog.config' import { loadExternalResource } from '@/lib/utils' import { useRouter } from 'next/router' +import { siteConfig } from '@/lib/config' const Ackee = () => { const router = useRouter() + const server = siteConfig('ANALYTICS_ACKEE_DATA_SERVER') + const domainId = siteConfig('ANALYTICS_ACKEE_DOMAIN_ID') + + // 或者使用其他依赖数组,根据需要执行 handleAckee + useEffect(() => { + handleAckeeCallback() + }, [router]) // handleAckee 函数 const handleAckeeCallback = () => { handleAckee( router.asPath, { - server: BLOG.ANALYTICS_ACKEE_DATA_SERVER, - domainId: BLOG.ANALYTICS_ACKEE_DOMAIN_ID + server: server, + domainId: domainId }, { /* - * Enable or disable tracking of personal data. - * We recommend to ask the user for permission before turning this option on. - */ + * Enable or disable tracking of personal data. + * We recommend to ask the user for permission before turning this option on. + */ detailed: true, /* - * Enable or disable tracking when on localhost. - */ + * Enable or disable tracking when on localhost. + */ ignoreLocalhost: false, /* - * Enable or disable the tracking of your own visits. - * This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header. - * Some browsers strictly block third-party cookies. The option won't have an impact when this is the case. - */ + * Enable or disable the tracking of your own visits. + * This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header. + * Some browsers strictly block third-party cookies. The option won't have an impact when this is the case. + */ ignoreOwnVisits: false } ) } - // 或者使用其他依赖数组,根据需要执行 handleAckee - useEffect(() => { - handleAckeeCallback() - }, [router]) - return null } @@ -53,8 +56,8 @@ export default Ackee * @param {Object} environment - Object containing the URL of the Ackee server and the domain id. * @param {?Object} options - Ackee options. */ -const handleAckee = async function(pathname, environment, options = {}) { - await loadExternalResource(BLOG.ANALYTICS_ACKEE_TRACKER, 'js') +const handleAckee = async function (pathname, environment, options = {}) { + await loadExternalResource(siteConfig('ANALYTICS_ACKEE_TRACKER'), 'js') const ackeeTracker = window.ackeeTracker const instance = ackeeTracker?.create(environment.server, options) diff --git a/components/AlgoliaSearchModal.js b/components/AlgoliaSearchModal.js index e1ba9f3e..fe672e44 100644 --- a/components/AlgoliaSearchModal.js +++ b/components/AlgoliaSearchModal.js @@ -1,10 +1,10 @@ import { useState, useImperativeHandle, useRef } from 'react' -import BLOG from '@/blog.config' import algoliasearch from 'algoliasearch' import replaceSearchResult from '@/components/Mark' import Link from 'next/link' import { useGlobal } from '@/lib/global' import throttle from 'lodash/throttle' +import { siteConfig } from '@/lib/config' /** * 结合 Algolia 实现的弹出式搜索框 @@ -31,8 +31,8 @@ export default function AlgoliaSearchModal({ cRef }) { } }) - const client = algoliasearch(BLOG.ALGOLIA_APP_ID, BLOG.ALGOLIA_SEARCH_ONLY_APP_KEY) - const index = client.initIndex(BLOG.ALGOLIA_INDEX) + const client = algoliasearch(siteConfig('ALGOLIA_APP_ID'), siteConfig('ALGOLIA_SEARCH_ONLY_APP_KEY')) + const index = client.initIndex(siteConfig('ALGOLIA_INDEX')) /** * 搜索 @@ -97,7 +97,7 @@ export default function AlgoliaSearchModal({ cRef }) { setIsModalOpen(false) } - if (!BLOG.ALGOLIA_APP_ID) { + if (!siteConfig('ALGOLIA_APP_ID')) { return <> } @@ -123,7 +123,7 @@ export default function AlgoliaSearchModal({ cRef }) {