Skip to content

Commit

Permalink
Merge pull request #130 from jamebal/recycle
Browse files Browse the repository at this point in the history
perf: 优化seo
  • Loading branch information
jamebal authored Jul 8, 2024
2 parents 9c15f82 + da05489 commit d2bae62
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private String articlePage(HttpServletRequest request, String slug, Model map) {

private String setDescription(ArticleVO articleVO) {
if (articleVO == null || articleVO.getHtml() == null) {
return "";
return articleVO.getName();
}
return articleVO.getHtml().substring(0, Math.min(articleVO.getHtml().length(), 500)).replaceAll("<[^>]*>","");
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/static/articles/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User-agent: *
Disallow: /private/
Allow: *
14 changes: 8 additions & 6 deletions src/main/resources/templates/component/article-top.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
<li class="nav-item" th:if="${setting.isShowAlonePage('archives')}">
<a class="nav-link" th:href="${setting.siteUrl} + '/archives'" title="归档">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-guidang"></use>
<use href="#icon-guidang"></use>
</svg>
<span class="nav-link-label">归档</span>
</a>
</li>
<li class="nav-item" th:if="${setting.isShowAlonePage('categories')}">
<a class="nav-link" th:href="${setting.siteUrl} + '/categories'" title="分类">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-fenlei"></use>
<use href="#icon-fenlei"></use>
</svg>
<span class="nav-link-label">分类</span>
</a>
</li>
<li class="nav-item" th:if="${setting.isShowAlonePage('tags')}">
<a class="nav-link" th:href="${setting.siteUrl} + '/tags'" title="标签">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-tag"></use>
<use href="#icon-tag"></use>
</svg>
<span class="nav-link-label">标签</span>
</a>
Expand All @@ -33,10 +33,10 @@
</a>
</li>
<li th:if="${alonePages.size() > showAlonePages.size()}" class="nav-item nav-item-more" onmouseover="mouseover()" onmouseleave="mouseleave()">
<a class="nav-link">
<a class="nav-link" href="#">
<span class="nav-link-label">更多</span>
<svg class="icon icon-more" aria-hidden="true">
<use xlink:href="#icon-drop_down"></use>
<use href="#icon-drop_down"></use>
</svg>
</a>
<ul class="dropdown-menu">
Expand Down Expand Up @@ -66,7 +66,7 @@
</a>
</li>
<li>
<a class="changeTheme">
<a class="changeTheme" href="javascript:changeTheme();">
<i th:if="${darkTheme}" class="fas fa-sun"></i>
<i th:if="${!darkTheme}" class="fas fa-moon"></i>
</a>
Expand All @@ -76,6 +76,8 @@
</div>
</div>
<script>
function changeTheme() {
}
let menu = document.body.querySelector('.dropdown-menu')
let icon = document.documentElement.querySelector('.icon-more')
function mouseover(){
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/templates/component/articles-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ <h2 class="title">
<div class="new-meta-item date">
<div class="not-link">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-fabu"></use>
<use href="#icon-fabu"></use>
</svg>
<p th:text="'发布于 '+${article.uploadTime()}"></p>
</div>
</div>
<div class="new-meta-item categoryDO" th:if="${article.categories != null && article.categories.size() > 0}">
<a class="link">
<a class="link" href="#">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-fenlei"></use>
<use href="#icon-fenlei"></use>
</svg>
</a>
<div class="flex-text">
Expand All @@ -37,9 +37,9 @@ <h2 class="title">
</div>
</div>
<div class="new-meta-item tag" th:if="${article.tags != null && article.tags.size() > 0}">
<a class="link">
<a class="link" href="#">
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-tag"></use>
<use href="#icon-tag"></use>
</svg>
</a>
<div class="flex-text">
Expand Down Expand Up @@ -73,7 +73,7 @@ <h2 class="title">
<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
<i th:if="${articlesData.getTotalPage() > 1}">
<i th:if="${articlesData.getCurrentPage() == 1}">
<a data-pjax th:class="'layui-laypage-prev'+ ${articlesData.isFirst()?' layui-disabled':''}" >上一页</a>
<a data-pjax th:class="'layui-laypage-prev'+ ${articlesData.isFirst()?' layui-disabled':''}" href="#" >上一页</a>
</i>
<i th:if="${articlesData.getCurrentPage() > 1}">
<a data-pjax th:href="'?page=' + ${articlesData.getCurrentPage()-1}" th:class="'layui-laypage-prev'+ ${articlesData.isFirst()?' layui-disabled':''}" >上一页</a>
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/templates/component/common-js.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@
function getThemeCSSName() {
return getCookie('jmal-theme') || "light";
}
$('.changeTheme').on('click', function (){

function changeTheme() {
useDarkTheme(getThemeCSSName() === 'light')
// 记录切换主题的时间戳
setCookie('changeTheme', new Date().getTime())
}

$('.changeTheme').on('click', function (){
changeTheme()
})

let media = window.matchMedia('(prefers-color-scheme: dark)');
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/templates/component/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<meta property="og:title" th:content="${titleName}" />
<meta property="og:site_name" th:content="${setting.siteName}" />
<meta property="og:type" th:content="${markdown!= null ? 'article' : 'website'}" />
<meta property="og:description" th:content="${description}" />
<meta property="og:description" th:content="${description != null ? description : setting.siteName}" />
<meta name="description" th:content="${description != null ? description : setting.siteName}" />

<meta property="og:url" th:content="${setting.siteUrl + (url != null ? url : '')}" />
<meta property="og:image" th:content="${markdown != null && markdown.cover !=null ? markdown.cover : setting.backgroundSite}" />
<meta name="title" th:content="${titleName}" />
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/templates/component/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</a>
</li>
<li onclick="toggle()">
<a class="changeTheme">
<a class="changeTheme" href="javascript:changeTheme();">
<i th:if="${darkTheme}" class="fas fa-sun"></i>
<span th:if="${darkTheme}">亮色</span>
<i th:if="${!darkTheme}" class="fas fa-moon"></i>
Expand All @@ -68,6 +68,8 @@
</div>
</div>
<script>
function changeTheme() {
}
let body = document.getElementById("body")
let footer = document.getElementById("footer")
let toggleNav = document.getElementById("toggle-nav")
Expand Down

0 comments on commit d2bae62

Please sign in to comment.