fix: synchronize free article seo metadata
This commit is contained in:
+35
-1
@@ -3,6 +3,12 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta
|
||||
name="description"
|
||||
content="查看神彩算用户公开发布的免费彩票分析与预测文章,内容仅供学习与交流。"
|
||||
/>
|
||||
<meta name="robots" content="index, follow" />
|
||||
<link id="canonicalUrl" rel="canonical" />
|
||||
<title id="page-title">神彩算 - 免费文章详情</title>
|
||||
<script src="../public/css/layui/layui.js"></script>
|
||||
<script src="../config.js"></script>
|
||||
@@ -273,6 +279,34 @@
|
||||
});
|
||||
}
|
||||
|
||||
function articlePlainText(value) {
|
||||
var container = document.createElement("div");
|
||||
container.innerHTML = String(value || "");
|
||||
return String(container.textContent || container.innerText || "")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function updateArticleSeo(data) {
|
||||
var title = articlePlainText(data && data.title) || "免费文章详情";
|
||||
var summarySource =
|
||||
(data && (data.summary || data.description || data.introduction)) ||
|
||||
(data && data.content) ||
|
||||
"查看神彩算用户公开发布的免费彩票分析与预测文章,内容仅供学习与交流。";
|
||||
var description = articlePlainText(summarySource).slice(0, 160);
|
||||
var descriptionMeta = document.querySelector('meta[name="description"]');
|
||||
var canonical = document.getElementById("canonicalUrl");
|
||||
|
||||
document.title = title + " - 神彩算";
|
||||
if (descriptionMeta && description) descriptionMeta.setAttribute("content", description);
|
||||
if (canonical && articleId) {
|
||||
canonical.setAttribute(
|
||||
"href",
|
||||
"https://www.scs8888.cn/mianfei/" + encodeURIComponent(articleId) + ".html",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renderArticle(data) {
|
||||
$("#articleTitle").text(data.title || "无标题");
|
||||
$("#articleAuthor").text(
|
||||
@@ -282,7 +316,7 @@
|
||||
);
|
||||
$("#articleTime").text(data.updateTime || data.createTime || data.publishTime || "--");
|
||||
$("#articleContent").html(scopeArticleContent(data.content || ""));
|
||||
document.title = "神彩算 - " + (data.title || "免费文章详情");
|
||||
updateArticleSeo(data);
|
||||
|
||||
renderArticleNav(data.prev || data.previous || data.prevArticle, data.next || data.nextArticle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user