Skip to content

Commit

Permalink
remove: js
Browse files Browse the repository at this point in the history
  • Loading branch information
shlu committed Jan 9, 2025
1 parent 5642074 commit ab7bf24
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
73 changes: 0 additions & 73 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,79 +39,6 @@ <h1><a href="{{ "/" | absolute_url }}">{{ site.title }}</a></h1>
<p>声明:转载请注明出处,原文地址:<a href="{{ site.url }}{{ page.url }}">{{ site.title }}</a></p>
</blockquote>
{% endif %}
<script>
(function() {
/**
* 使用 TreeWalker 遍历所有节点以查找注释节点
* @param {Document} doc - 要遍历的文档对象
* @returns {Array} - 包含所有注释节点的数组
*/
function getAllComments(doc) {
const comments = [];
const walker = doc.createTreeWalker(
doc,
NodeFilter.SHOW_COMMENT,
null,
false
);
let node;
while (node = walker.nextNode()) {
comments.push(node);
}
return comments;
}

/**
* 从注释内容中提取描述文本
* @param {string} comment - 注释文本内容
* @returns {string|null} - 提取的描述文本或 null
*/
function extractDescription(comment) {
const regex = /^description\s*:\s*(.+)$/i;
const match = comment.match(regex);
return match ? match[1].trim() : null;
}

// 等待 DOM 完全加载
document.addEventListener('DOMContentLoaded', function() {
const comments = getAllComments(document);
let descText = null;

// 遍历所有注释节点,查找匹配的描述注释
for (let commentNode of comments) {
const commentContent = commentNode.nodeValue.trim();
const extracted = extractDescription(commentContent);
if (extracted) {
descText = extracted;
break; // 找到第一个匹配的注释后退出循环
}
}

if (descText) {
// 更新 <meta name="description">
const metaDescription = document.querySelector('meta[name="description"]');
if (metaDescription) {
metaDescription.setAttribute('content', descText);
console.log('已更新 <meta name="description"> 内容为:', descText);
} else {
console.warn('未找到 <meta name="description"> 标签。');
}

// 更新 <meta property="og:description">
const metaOgDescription = document.querySelector('meta[property="og:description"]');
if (metaOgDescription) {
metaOgDescription.setAttribute('content', descText);
console.log('已更新 <meta property="og:description"> 内容为:', descText);
} else {
console.warn('未找到 <meta property="og:description"> 标签。');
}
} else {
console.warn('未找到符合格式的 description 注释(<!-- description: xxxxxx -->)。');
}
});
})();

</script>
<!-- comments config BEGIN -->

<!-- src="https://giscus.app/client.js" 自定义client.js-->
Expand Down
2 changes: 0 additions & 2 deletions git/git提交规范.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# GIT 提交规范

<!-- description: 介绍了GIT 提交的规范格式-->

## 1. 提交信息格式

Git 提交信息通常包含三部分:
Expand Down

0 comments on commit ab7bf24

Please sign in to comment.