feat: 首页打字机动画完全可配置,TypeWriteList 为空或注释时不再渲染标签和动画

- MainHeader.astro 条件渲染 <p class=desc>,仅在 TypeWriteList 有内容时输出
- Init.ts/TypeWrite.ts 仅在 TypeWriteList 有内容时初始化动画
- 彻底清理无用标签和副作用,提升主题可定制性
This commit is contained in:
unknown 2025-06-04 11:41:42 +08:00
parent 2aa978451d
commit f84e030c1e
3 changed files with 6 additions and 2 deletions

View File

@ -8,5 +8,7 @@ import "./MainHeader.less";
<img src="/assets/images/lazy-loading.webp" data-vh-lz-src={SITE_INFO.Avatar} alt="avatar" />
</div>
<h3 class="auther">{SITE_INFO.Author || "-"}</h3>
{Array.isArray(SITE_INFO.TypeWriteList) && SITE_INFO.TypeWriteList.length > 0 && (
<p class="desc"></p>
)}
</div>

View File

@ -80,7 +80,7 @@ const indexInit = async (only: boolean = true) => {
// Han Analytics 统计
HanAnalyticsInit();
// 打字效果
only && TypeWriteInit();
only && Array.isArray(SITE_INFO.TypeWriteList) && SITE_INFO.TypeWriteList.length > 0 && TypeWriteInit();
// 泡泡🫧效果
PaoPaoInit();
// 预加载搜索数据

View File

@ -3,6 +3,8 @@ export default () => {
const writeDom = document.querySelector('.header-main>.desc');
if (!writeDom) return;
const TypeWriteList = SITE_INFO.TypeWriteList;
// 如果 TypeWriteList 不是数组或没有内容则不执行动画
if (!Array.isArray(TypeWriteList) || TypeWriteList.length === 0) return;
let TypeWriteListIndex = 0;
let index = 0;
let isDeleting = false;