This repository has been archived on 2025-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
vitepress-theme-blog-charle…/docs/.vitepress/config/head.ts

59 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { HeadConfig } from 'vitepress';
import { metaData } from './constants';
export const head: HeadConfig[] = [
['link', { rel: 'icon', href: '/favicon.ico' }],
['meta', { name: 'author', content: 'Charles7c' }],
['meta', { name: 'keywords', content: '查尔斯的知识库, 知识库, 博客, Charles7c' }],
['meta', { name: 'HandheldFriendly', content: 'True' }],
['meta', { name: 'MobileOptimized', content: '320' }],
['meta', { name: 'theme-color', content: '#3c8772' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: metaData.locale }],
['meta', { property: 'og:title', content: metaData.title }],
['meta', { property: 'og:description', content: metaData.description }],
['meta', { property: 'og:site', content: metaData.site }],
['meta', { property: 'og:site_name', content: metaData.title }],
['meta', { property: 'og:image', content: metaData.image }],
// 百度统计代码https://tongji.baidu.com
['script', {}, `var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?53af4b1a12fbe40810ca7ad39f8db9c7";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();`],
// 页面访问量统计
['script', {}, `
window.addEventListener('load', function() {
let oldHref = document.location.href, bodyDOM = document.querySelector('body');
const observer = new MutationObserver(function(mutations) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
getPv()
window.requestAnimationFrame(function() {
let tmp = document.querySelector('body');
if(tmp != bodyDOM) {
bodyDOM = tmp;
observer.observe(bodyDOM, config);
}
})
}
});
const config = {
childList: true,
subtree: true
};
observer.observe(bodyDOM, config);
getPv()
}, true);
function getPv() {
xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.charles7c.top/blog/pv?pageUrl=' + location.href);
xhr.send();
}`]
];