Merge pull request #468 from chengzhongxue/main

优化随机图重复
This commit is contained in:
困困鱼 2023-09-02 15:06:31 +08:00 committed by GitHub
commit 9e2f4dca23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 86 additions and 73 deletions

View File

@ -13,7 +13,7 @@
<div id="archive">
<div class="article-sort-title">文章 - [[${siteStatsFinder.getStats().post}]]</div>
<div class="article-sort" th:each="archive : ${archives.items}"
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<div class="article-sort-item year" th:text="${archive.year}"></div>
<div class="article-sort" th:each="month : ${archive.months}">
<!-- 月份没有样式所以不显示 -->

View File

@ -3,7 +3,6 @@
.relatedPosts-list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.relatedPosts>.relatedPosts-list>div {
background: #363636;

View File

@ -17,43 +17,44 @@
let keys = GLOBAL_CONFIG.source.postAi.keys;
let Referers = GLOBAL_CONFIG.source.postAi.Referers;
let post = document.querySelector('#post')
const interface = {
name: "AI-摘要",
aiToggle: "切换",
version: "Tianli GPT",
button: ["介绍自己", "生成本文简介", "推荐相关文章", "前往主页"],
}
// 插入html结构
const post_ai_box = document.createElement('div');
post_ai_box.className = 'post-ai';
post.insertBefore(post_ai_box, post.firstChild);
// let post = document.querySelector('#post')
// const interface = {
// name: "AI-摘要",
// aiToggle: "切换",
// version: "Tianli GPT",
// button: ["介绍自己", "生成本文简介", "推荐相关文章", "前往主页"],
// }
// // 插入html结构
// const post_ai_box = document.createElement('div');
// post_ai_box.className = 'post-ai';
// post.insertBefore(post_ai_box, post.firstChild);
//
// var PostAI = `
// <div class="ai-title">
// <i class="haofont hao-icon-bilibili"></i>
// <div class="ai-title-text">${interface.name}</div>`
// if (switchBtn) {
// PostAI += `<div id="ai-Toggle">${interface.aiToggle}</div> `;
// }
// PostAI += `<i class="haofont hao-icon-arrow-rotate-right"></i> `;
// if (modeName == 'local') {
// PostAI += `<div class="ai-tag" id="ai-tag">${gptName} GPT</div>`;
// } else {
// PostAI += `<div class="ai-tag" id="ai-tag">${interface.version}</div> `;
// }
// PostAI += `
// </div>
// <div class="ai-explanation" style="display: block;">AI初始化中...</div>
// <div class="ai-btn-box">
// <div class="ai-btn-item">${interface.button[0]}</div>
// <div class="ai-btn-item">${interface.button[1]}</div>
// <div class="ai-btn-item">${interface.button[2]}</div>
// <div class="ai-btn-item">${interface.button[3]}</div>
// <div class="ai-btn-item" id="go-tianli-blog">前往tianli博客</div>
// </div>`;
//
// post_ai_box.innerHTML = PostAI;
var PostAI = `
<div class="ai-title">
<i class="haofont hao-icon-bilibili"></i>
<div class="ai-title-text">${interface.name}</div>`
if (switchBtn) {
PostAI += `<div id="ai-Toggle">${interface.aiToggle}</div> `;
}
PostAI += `<i class="haofont hao-icon-arrow-rotate-right"></i> `;
if (modeName == 'local') {
PostAI += `<div class="ai-tag" id="ai-tag">${gptName} GPT</div>`;
} else {
PostAI += `<div class="ai-tag" id="ai-tag">${interface.version}</div> `;
}
PostAI += `
</div>
<div class="ai-explanation" style="display: block;">AI初始化中...</div>
<div class="ai-btn-box">
<div class="ai-btn-item">${interface.button[0]}</div>
<div class="ai-btn-item">${interface.button[1]}</div>
<div class="ai-btn-item">${interface.button[2]}</div>
<div class="ai-btn-item">${interface.button[3]}</div>
<div class="ai-btn-item" id="go-tianli-blog">前往tianli博客</div>
</div>`;
post_ai_box.innerHTML = PostAI;
// 当前随机到的ai摘要到index
let lastAiRandomIndex = -1;
let animationRunning = true; // 标志变量,控制动画函数的运行

View File

@ -1369,9 +1369,9 @@ blockquote footer cite::before {
transition: all 0.3s ease 0s;
}
@media screen and (max-width: 900px) {
.layout > div:first-child {
width: 100% !important;
@media screen and (max-width: 1200px) {
.layout>div:first-child {
width:100%!important
}
}
@ -6754,9 +6754,9 @@ a.console_switchbutton {
}
}
@media screen and (max-width: 900px) {
@media screen and (max-width: 1200px) {
#aside-content {
display: none;
display:none
}
}

View File

@ -35,7 +35,7 @@
<!-- TODO 按照年份分组 需要 halo 提供归档数据-->
<!--<div class="article-sort-item year">2022</div>-->
<div class="article-sort-item" th:each="post : ${posts.items}"
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<a class="article-sort-item-img" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}">
<img th:alt="${post.spec.title}"

View File

@ -30,12 +30,12 @@
<div class="aside-list">
<div class="aside-list-group"
th:with='topGroupPosts = ${postFinder.list(1,6)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg : theme.config.layout.postRandomImg+"?"}'>
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<div th:each="post : ${topGroupPosts}" class="aside-list-item"><a class="thumbnail"
th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}"><img
loading="lazy"
th:src='${#strings.isEmpty(post.spec.cover) ? postRandomImg+","+post.spec.title : post.spec.cover}'
th:src='${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}'
th:alt="${post.spec.title}"></a>
<div class="content"><a class="title" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}"

View File

@ -30,12 +30,12 @@
<div class="aside-list">
<div class="aside-list-group"
th:with='topGroupPosts = ${postFinder.list(1,6)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg : theme.config.layout.postRandomImg+"?"}'>
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<div th:each="post : ${topGroupPosts}" class="aside-list-item"><a class="thumbnail"
th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}"><img
loading="lazy"
th:src='${#strings.isEmpty(post.spec.cover) ? postRandomImg+","+post.spec.title : post.spec.cover}'
th:src='${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}'
th:alt="${post.spec.title}"></a>
<div class="content"><a class="title" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}"

View File

@ -12,6 +12,7 @@
<head>
<th:block th:replace="~{modules/head :: head(htmlType = ${htmlType})}"/>
<script th:src="${assets_link + '/js/custom.js'}"></script>
</head>
<body>
@ -55,7 +56,6 @@
<div th:replace="~{modules/right-menu :: right-menu}"></div>
<div>
<script th:src="${assets_link + '/js/custom.js'}"></script>
<script th:src="${assets_link + '/js/utils.js' + theme_version}"></script>
<script th:src="${assets_link + '/js/main.js' + theme_version}"></script>
<script charset="utf-8" data-pjax th:src="${assets_link + '/zhheo/blogex.js' + theme_version}"></script>
@ -86,8 +86,8 @@
<script th:src="${assets_link + '/libs/view-image/view-image.min.js'}"></script>
<!--左下角音乐-->
<script>var meting_api = '[[${theme.config.tool.nav_music.meting_api}]]'; </script>
<!--音乐-->
<script>var meting_api = "[(${theme.config.tool.nav_music.meting_api})]"; </script>
<link rel="stylesheet" href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.css" media="all" onload="this.media='all'">

View File

@ -3,7 +3,7 @@
<th:block th:fragment="post-list"
th:with='postItems=${posts.items},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg : theme.config.layout.postRandomImg+"?"}'>
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<!-- card需要添加在没有图片时使用随机图片 -->
<div class="recent-post-item"
@ -16,7 +16,7 @@
<div class="post_cover left_radius">
<a th:attr="title=${post.spec.title}" th:href="@{${post.status.permalink}}">
<img class="post_bg"
th:with='img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+","+post.spec.title : post.spec.cover}'
th:with='img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}'
th:alt="${post.spec.title}"
th:data-lazy-src="${ isLazyload ? img : ''}"
th:src="${isLazyload ? loadingImg : img}">

View File

@ -3,7 +3,8 @@
<!-- 阅读建议 -->
<th:block th:fragment="relatedPosts" th:if="${not #lists.isEmpty(post.categories)}" th:with="recommendQuantity = ${theme.config.post.recommendQuantity},
recommandPosts = ${postFinder.listByCategory(1,recommendQuantity == 'six' ? 7 : recommendQuantity == 'two' ? 3 : 1,post.categories.get(0).metadata.name)},
containsTitle = ${#strings.contains(recommandPosts,post.spec.title)}">
containsTitle = ${#strings.contains(recommandPosts,post.spec.title)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,'?') ? theme.config.layout.postRandomImg+'&' : theme.config.layout.postRandomImg+'?'}">
<div class="relatedPosts" th:if="${recommandPosts.total>1}">
<div class="headline">
<i class="haofont hao-icon-cainixihuan" style="font-size: 1.1rem;"></i>
@ -17,7 +18,7 @@ containsTitle = ${#strings.contains(recommandPosts,post.spec.title)}">
<div th:if="${!containsTitle ? iterStat.index <6 : true}">
<a th:href="@{${recommandPost.status.permalink}}" th:title="${recommandPost.spec.title}">
<img alt="cover" class="cover" id="preimg"
th:with="img = ${#strings.isEmpty(recommandPost.spec.cover) ? theme.config.layout.postRandomImg : recommandPost.spec.cover}"
th:with="img = ${#strings.isEmpty(recommandPost.spec.cover) ? postRandomImg+recommandPost.spec.title : recommandPost.spec.cover}"
th:src="${isLazyload ? loadingImg : img}"
th:data-lazy-src="${ isLazyload ? img : ''}">
<div class="content is-center">
@ -37,7 +38,7 @@ containsTitle = ${#strings.contains(recommandPosts,post.spec.title)}">
<div th:if="${!containsTitle ? iterStat.index <2 : true}">
<a th:href="@{${recommandPost.status.permalink}}" th:title="${recommandPost.spec.title}">
<img class="cover" alt="cover"
th:with="img = ${#strings.isEmpty(recommandPost.spec.cover) ? theme.config.layout.postRandomImg : recommandPost.spec.cover}"
th:with="img = ${#strings.isEmpty(recommandPost.spec.cover) ? postRandomImg+recommandPost.spec.title : recommandPost.spec.cover}"
th:src="${isLazyload ? loadingImg : img}"
th:data-lazy-src="${ isLazyload ? img : ''}">

View File

@ -180,15 +180,6 @@
<style>
.is-center {
text-align: center;
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-direction: row;
align-items: center
}
.card-info-avatar.is-center {
flex-direction: column;
display: flex;

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div class="card-widget card-recent-post" th:fragment="recent-posts" th:with='posts = ${postFinder.list(1,theme.config.sidebar.recentPost)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<div class="item-headline"><i class="haofont hao-icon-eicon_map-2-line1"></i><span>最近发布</span></div>
<div class="aside-list">
<!-- 最新文章,用户可以自定义展示数量 -->

View File

@ -3,7 +3,7 @@
<!-- 推荐文章 -->
<div class="topGroup" th:fragment="top-group" th:with='topGroupPosts = ${postFinder.list(1,6)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg : theme.config.layout.postRandomImg+"?"}'
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'
>
<div class="recent-post-item"
th:each="post : ${topGroupPosts}"
@ -14,7 +14,7 @@
<span class="recent-post-top-text"
th:attr="onclick='pjax.loadUrl(\''+ @{${post.status.permalink}} +'\')'">荐</span>
<img class="post_bg"
th:with=' img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+","+post.spec.title : post.spec.cover}'
th:with=' img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}'
th:alt="${post.spec.title}"
th:src="${isLazyload ? loadingImg : img}"
@ -41,7 +41,7 @@
<span class="recent-post-top-text"
th:attr="onclick='pjax.loadUrl(\''+ @{${post.status.permalink}} +'\')'">荐</span>
<img class="post_bg"
th:with='img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+","+post.spec.title : post.spec.cover}'
th:with='img = ${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}'
th:alt="${post.spec.title}"
th:src="${isLazyload ? loadingImg : img}"

View File

@ -97,6 +97,26 @@
<main class="layout" id="content-inner" th:classappend="${theme.config.sidebar.location}">
<div id="post">
<!-- 文章ai摘要 -->
<div class="post-ai" th:if="${theme.config.post.aiDescription.aiDescriptionEnable}">
<div class="ai-title"><i class="haofont hao-icon-bilibili"></i>
<div class="ai-title-text">AI-摘要</div>
<div th:if="${theme.config.post.aiDescription.switchBtn}" id="ai-Toggle">切换</div>
<i class="haofont hao-icon-arrow-rotate-right"></i>
<div th:if="${#strings.equals(theme.config.post.aiDescription.mode, 'local')}" class="ai-tag" id="ai-tag">[[${theme.config.post.aiDescription.gptName}]] GPT</div>
<div th:if="${#strings.equals(theme.config.post.aiDescription.mode, 'tianli')}" class="ai-tag" id="ai-tag">Tianli GPT</div>
</div>
<div class="ai-explanation" style="display: block;">AI初始化中...</div>
<div class="ai-btn-box">
<div class="ai-btn-item">介绍自己</div>
<div class="ai-btn-item">生成本文简介</div>
<div class="ai-btn-item">推荐相关文章</div>
<div class="ai-btn-item">前往主页</div>
<div class="ai-btn-item" id="go-tianli-blog">前往tianli博客</div>
</div>
</div>
<!-- 文章内容 -->
<article th:class="'post-content '+${ theme.config.code.enable_line || pluginFinder.available('PluginPrismJS') ? 'line-numbers' : ''}" id="article-container" th:utext="${post.content.content}">
</article>
@ -109,11 +129,12 @@
<th:block th:replace="~{modules/post/copyright :: copyright}"></th:block>
<nav class="pagination-post" id="pagination"
th:with="postCursor = ${postFinder.cursor(post.metadata.name)}">
th:with="postCursor = ${postFinder.cursor(post.metadata.name)},
postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,'?') ? theme.config.layout.postRandomImg+'&' : theme.config.layout.postRandomImg+'?'}">
<div th:class="${postCursor.hasPrevious()==true && postCursor.hasNext()==false} ? 'prev-post2 pull-left postcarnepre' : 'prev-post pull-left'">
<a th:if="${postCursor.hasPrevious()}" th:href="@{${postCursor.previous.status.permalink}}">
<img alt="cover" id="preimg" class="nolazyload"
th:with="img = ${#strings.isEmpty(postCursor.previous.spec.cover) ? theme.config.layout.postRandomImg : postCursor.previous.spec.cover}"
th:with="img = ${#strings.isEmpty(postCursor.previous.spec.cover) ? postRandomImg+postCursor.previous.spec.title : postCursor.previous.spec.cover}"
th:src="${isLazyload ? loadingImg : img}"
th:data-lazy-src="${ isLazyload ? img : ''}">
@ -126,7 +147,7 @@
<div th:class="${postCursor.hasPrevious()==false && postCursor.hasNext()==true} ? 'next-post2 pull-right postcarnepre':'next-post pull-right'">
<a th:if="${postCursor.hasNext()}" th:href="@{${postCursor.next.status.permalink}}">
<img alt="cover" id="preimg" class="nolazyload"
th:with="img = ${#strings.isEmpty(postCursor.next.spec.cover) ? theme.config.layout.postRandomImg : postCursor.next.spec.cover}"
th:with="img = ${#strings.isEmpty(postCursor.next.spec.cover) ? postRandomImg+postCursor.next.spec.title : postCursor.next.spec.cover}"
th:src="${isLazyload ? loadingImg : img}"
th:data-lazy-src="${ isLazyload ? img : ''}">
<div class="pagination-info">

View File

@ -24,7 +24,7 @@
<div class="article-sort" th:with="postItems=${posts.items}">
<!--<div class="article-sort-item year">2022</div>-->
<div class="article-sort-item" th:each="post : ${postItems}"
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
<a class="article-sort-item-img" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}">
<img loading="lazy" th:alt="${post.status.excerpt}"