Skip to content

Commit b870c3d

Browse files
committed
对首页部分链接增加 pjax 的功能,完善部分功能
1 parent 01d94b6 commit b870c3d

File tree

17 files changed

+61
-23
lines changed

17 files changed

+61
-23
lines changed

src/css/common/outline/header/brand.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
margin: 0;
99

1010
& a {
11-
color: #464646;
11+
color: var(--body-color);
1212
font-weight: 400;
1313

1414
&:hover {

src/css/theme/tag/header.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
display: inline-block;
66
font-size: 25px;
77
font-weight: 400;
8-
color: #666;
8+
color: var(--color);
99

1010
&::before {
1111
content: "";

src/libs/pjax.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import NProgress from "nprogress";
2525

2626
NProgress.configure({ trickle: false });
2727

28-
new Pjax({
28+
const pjax = new Pjax({
2929
elements: "a[data-pjax]",
3030
selectors: ["head title", ".wrapper", ".pjax"],
3131
switches: {
@@ -36,6 +36,9 @@ new Pjax({
3636
debug: import.meta.env.MODE === "development" ? true : false,
3737
});
3838

39+
// 挂载 pjax 实例至全局
40+
sakura.mountGlobalProperty("pjax", pjax);
41+
3942
window.addEventListener("pjax:send", () => {
4043
NProgress.start();
4144
});

src/main.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface Sakura {
2323
registerDocumentFunction(documentFunction: DocumentFunction): void;
2424
translate(key: String, defaultValue: string, options?: TOptions): string;
2525
getPageConfig(key: string): any | undefined;
26+
mountGlobalProperty(key: string, value: any): void;
2627
}
2728

2829
declare var Sakura: {
@@ -231,6 +232,23 @@ export class SakuraApp implements Sakura {
231232
this.finishRefresh();
232233
}
233234

235+
/**
236+
* 挂载全局属性至 sakura 中
237+
*/
238+
public mountGlobalProperty(key: string, value: any) {
239+
const descriptor = Object.getOwnPropertyDescriptor(sakura, `$${key}`);
240+
if (descriptor) {
241+
return;
242+
}
243+
Object.defineProperty(sakura, `$${key}`, {
244+
value: value,
245+
writable: false,
246+
enumerable: false,
247+
configurable: false,
248+
});
249+
// TODO 触发属性挂载完成事件
250+
}
251+
234252
protected mountGlobalFunction() {
235253
// 注册sakura toast 组件
236254
const isToast = sakura.getThemeConfig("toast", "open_toast", Boolean)?.valueOf();
@@ -312,7 +330,7 @@ export class SakuraApp implements Sakura {
312330
hour: "numeric",
313331
minute: "numeric",
314332
second: "numeric",
315-
}
333+
};
316334
break;
317335
case "date":
318336
default:

src/module/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export class Utils {
141141
colorScheme: 'light'
142142
}
143143
);
144+
// 注入样式
145+
this.injectCommentStyle();
144146
resolve("success");
145147
});
146148
}

src/page/tags.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { documentFunction } from "../main";
1+
import { documentFunction, sakura } from "../main";
22
// @ts-ignore
33
import cloneDeep from "lodash.clonedeep";
44
// @ts-ignore
@@ -17,6 +17,13 @@ export default class Tags {
1717
});
1818
}
1919

20+
/**
21+
*
22+
* 注册标签云
23+
*
24+
* @description 生成标签云
25+
* @see https://github.com/jasondavies/d3-cloud
26+
*/
2027
@documentFunction()
2128
public async registerTagsWordCloud() {
2229
const wordCloudElement = document.getElementById("tag-wordcloud");
@@ -50,6 +57,7 @@ export default class Tags {
5057
.attr("xlink:href", function (d: any) {
5158
return d.link;
5259
})
60+
.attr("data-pjax", "")
5361
.append("text")
5462
.style("font-size", function (d: any) {
5563
return d.size;
@@ -67,6 +75,11 @@ export default class Tags {
6775
.text(function (d: any) {
6876
return d.text;
6977
});
78+
// 如果存在 pjax,则刷新 wordCloudElement
79+
if (sakura.$pjax) {
80+
// TODO 虽然添加上了,但似乎没生效
81+
sakura.$pjax.refresh(wordCloudElement);
82+
}
7083
});
7184
layout.start();
7285
}

templates/assets/dist/css/main.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/libs/pjax.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/main.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/assets/dist/page/categories.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)