Skip to content

Commit

Permalink
首页副标题的独立设置加随机一言
Browse files Browse the repository at this point in the history
修复分类分页问题
  • Loading branch information
chengzhongxue committed Apr 27, 2024
1 parent 43affd6 commit f51c41f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 17 deletions.
52 changes: 49 additions & 3 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,56 @@ spec:
label: 头图黑色蒙版的不透明度
help: 0 - 1.0 1 是完全不透明
value: 0.3
- $formkit: text
name: slogan_text
- $formkit: group
name: slogan
label: 首页副标题的独立设置
value: "An elegant Material-Design theme for Halo"
value:
enable: true
text: "An elegant Material-Design theme for Halo"
api:
enable: true
method: "GET"
url: "https://v1.hitokoto.cn/"
keys: "'hitokoto'"
children:
- $formkit: checkbox
name: enable
id: slogan_enable
label: 显示
- $formkit: text
name: text
if: $get(slogan_enable).value
label: 首页副标题
- $formkit: group
name: api
label: 通过 API 接口作为首页副标题的内容
help: 必须返回的是 JSON 格式,如果请求失败则按 text 字段显示,该功能必须先开启 typing 打字机功能
children:
- $formkit: checkbox
name: enable
id: api_enable
label: 显示
- $formkit: text
name: url
if: $get(api_enable).value
label: 请求地址
- $formkit: select
name: method
if: $get(api_enable).value
label: 请求方法
options:
- label: GET
value: "GET"
- label: POST
value: "POST"
- label: PUT
value: "PUT"
- $formkit: code
name: keys
if: $get(api_enable).value
label: 从请求结果获取字符串的取值字段
language: json

- $formkit: group
name: post_sticky
label: 在首页置顶文章图标
Expand Down
4 changes: 2 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
th:replace="~{modules/layout :: layout(_head = null,_content = ~{::content},_title = null,page_js = null)}">
<th:block th:fragment="content" th:with="banner_img_height = ${#conversions.convert(theme.config.index.banner_img_height, 'java.lang.Integer')}">
<header
th:with="banner_img=${theme.config.index.banner_img},banner_mask_alpha=${theme.config.index.banner_mask_alpha},_title=${theme.config.index.slogan_text}">
th:with="banner_img=${theme.config.index.banner_img},banner_mask_alpha=${theme.config.index.banner_mask_alpha},_title=${theme.config.index.slogan.enable ? theme.config.index.slogan.text : site.title}">
<th:block th:replace="~{'modules/header'}" />
</header>
<main>
Expand All @@ -14,7 +14,7 @@
<div class="col-12 col-md-10 m-auto">
<th:block th:each="post,iStat : ${posts.items}">
<div class="row mx-auto index-card" th:with="default_index_img= ${#strings.contains(theme.config.post.default_index_img,'?') ? theme.config.post.default_index_img+'&' : theme.config.post.default_index_img+'?'},
index_img = ${#strings.isEmpty(post.spec.cover) ? default_index_img+post.spec.title : post.spec.cover}">
index_img = ${not #strings.isEmpty(post.spec.cover) ? post.spec.cover : #strings.isEmpty(theme.config.post.default_index_img) ? theme.config.post.default_index_img : default_index_img+post.spec.title}">
<th:block >
<div class="col-12 col-md-4 m-auto index-img" th:if="${not #strings.isEmpty(index_img)}">
<a th:href="${post.status.permalink}" target="_self">
Expand Down
28 changes: 20 additions & 8 deletions templates/macro/category-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,31 @@

<div class="category-post-list" th:fragment="category-post-list(categoryPostList,category)">
<th:block th:with="limit = ${#conversions.convert(theme.config.category.post_limit, 'java.lang.Integer')}">
<th:block th:each="post,index : ${categoryPostList.items}">
<th:block th:if="${index.index >=limit }">
<a th:href="${category.status.permalink}" class="list-group-item list-group-item-action">
<span class="category-post" th:text="${category.spec.displayName}"></span>
</a>
</th:block>
<th:block th:unless="${index.index >=limit }">
<th:block th:if="${limit == 0}">
<th:block th:each="post,index : ${categoryPostList.items}">
<a th:href="${post.status.permalink}" th:title="${post.spec.title}"
class="list-group-item list-group-item-action">
class="list-group-item list-group-item-action">
<span class="category-post" th:text="${post.spec.title}"></span>
</a>
</th:block>
</th:block>

<th:block th:unless="${limit == 0}">
<th:block th:each="post,index : ${categoryPostList.items}">
<th:block th:if="${index.index == limit && categoryPostList.total > limit }">
<a th:href="${category.status.permalink}" class="list-group-item list-group-item-action">
<span class="category-post">更多</span>
</a>
</th:block>
<th:block th:unless="${index.index >=limit }">
<a th:href="${post.status.permalink}" th:title="${post.spec.title}"
class="list-group-item list-group-item-action">
<span class="category-post" th:text="${post.spec.title}"></span>
</a>
</th:block>
</th:block>
</th:block>

</th:block>


Expand Down
41 changes: 39 additions & 2 deletions templates/modules/layouts/typed.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
<th:block th:if="${theme.config.fun_features.typing.enable}">
<script th:src="@{/assets/libs/typed/typed.min.js?v='2.0.12'}"></script>
<script>
<script th:inline="javascript">
(function (window, document) {
var typing = Fluid.plugins.typing;
var subtitle = document.getElementById('subtitle');
if (!subtitle || !typing) {
return;
}
var text = subtitle.getAttribute('data-typed-text');
typing(text);
var urlinfo = window.location.pathname;
urlinfo = decodeURIComponent(urlinfo);
if ([[${theme.config.index.slogan.api.enable}]] && urlinfo == '/') {
$.ajax({
type: "[(${theme.config.index.slogan.api.method})]",
url: '[(${theme.config.index.slogan.api.url})]',
success: function(result) {
var apiText;
if (result) {
var keysData = [(${theme.config.index.slogan.api.keys})];
var keys = keysData.split(',');
if (result instanceof Array) {
result = result[0];
}
for (const k of keys) {
var value = result[k];
if (typeof value === 'string') {
apiText = value;
break;
} else if (value instanceof Object) {
result = value;
}
}
}
apiText ? typing(apiText) : typing(text);
},
error: function(xhr, status, error) {
if (error) {
var url = '[(${theme.config.index.slogan.api.url})]'
console.error(`Failed to request ${url}:`, error);
}
typing(text);
}
})
}else {
typing(text);
}

})(window, document);
</script>
</th:block>
2 changes: 1 addition & 1 deletion templates/modules/variables/configs.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
path: "window.location.pathname",
ignore_local: false
}
}
},
};
if (CONFIG.web_analytics.follow_dnt) {
var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
Expand Down
3 changes: 2 additions & 1 deletion theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ spec:
file: about.html
description: 🌊 一款 Material Design 风格的 Halo 主题 / An elegant Material-Design theme for Halo
logo: "/themes/theme-fluid/assets/img/fluid.png"
website: "https://github.com/chengzhongxue"
website: "https://www.halo.run/store/apps/app-jbTyl"
repo: "https://github.com/chengzhongxue/halo-theme-fluid"
issues: "https://github.com/chengzhongxue/halo-theme-fluid/issues"
settingName: "theme-fluid-setting"
configMapName: "theme-fluid-configMap"
version: "1.0.2"
Expand Down

0 comments on commit f51c41f

Please sign in to comment.