minearm-website 0.0.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/astro.config.ts +33 -0
- package/minearm.ts +174 -0
- package/package.json +64 -0
- package/public/13.jpg +0 -0
- package/public/1937daxue.png +0 -0
- package/public/3.png +0 -0
- package/public/404.png +0 -0
- package/public/5.jpg +0 -0
- package/public/BC.png +0 -0
- package/public/Chinese.png +0 -0
- package/public/avatar.avif +0 -0
- package/public/avatar.jpg +0 -0
- package/public/c++1.png +0 -0
- package/public/docker-hub.png +0 -0
- package/public/favicon.png +0 -0
- package/public/help1.png +0 -0
- package/public/heroimg.jpg +0 -0
- package/public/logo.png +0 -0
- package/public/mail.png +0 -0
- package/public/nahida.png +0 -0
- package/public/pojipao.avif +0 -0
- package/public/rust1.png +0 -0
- package/public/scripts/mdata.json +4 -0
- package/public/scripts/utils.js +190 -0
- package/public/xmrig.jpg +0 -0
- package/src/components/BodyInject.astro +5 -0
- package/src/components/HeadInject.astro +16 -0
- package/src/components/Search.astro +30 -0
- package/src/components/animation/bubbles.astro +82 -0
- package/src/components/animation/wave.astro +81 -0
- package/src/components/aside/announcement.astro +25 -0
- package/src/components/aside/aside.astro +32 -0
- package/src/components/aside/asideComps.astro +26 -0
- package/src/components/aside/authorInfo.astro +54 -0
- package/src/components/aside/blogToc.astro +26 -0
- package/src/components/aside/countScript.astro +18 -0
- package/src/components/aside/customCard.astro +23 -0
- package/src/components/aside/siteInfo.astro +51 -0
- package/src/components/client/searchCore.vue +77 -0
- package/src/components/client/themeControl.vue +77 -0
- package/src/components/footer/Footer.astro +32 -0
- package/src/components/header/Header.astro +40 -0
- package/src/components/header/HeaderButton.astro +59 -0
- package/src/components/header/HeaderItem.astro +63 -0
- package/src/components/header/heroWave.astro +19 -0
- package/src/components/header/searchBar.astro +21 -0
- package/src/components/icons/bilibili.astro +10 -0
- package/src/components/icons/c.astro +10 -0
- package/src/components/icons/code.astro +37 -0
- package/src/components/icons/computer.astro +4 -0
- package/src/components/icons/cube.astro +10 -0
- package/src/components/icons/game.astro +10 -0
- package/src/components/icons/getIcon.astro +64 -0
- package/src/components/icons/github.astro +10 -0
- package/src/components/icons/hardDriver.astro +10 -0
- package/src/components/icons/home.astro +14 -0
- package/src/components/icons/icon.ts +33 -0
- package/src/components/icons/icons.json +91961 -0
- package/src/components/icons/link.astro +4 -0
- package/src/components/icons/mail.astro +10 -0
- package/src/components/icons/paperPlane.astro +4 -0
- package/src/components/icons/pen.astro +14 -0
- package/src/components/icons/person.astro +14 -0
- package/src/components/icons/searchicon.astro +23 -0
- package/src/components/icons/tags.astro +10 -0
- package/src/components/icons/toTop.astro +10 -0
- package/src/components/icons/tools.astro +1 -0
- package/src/components/loading/loading.vue +185 -0
- package/src/components/postComment.astro +62 -0
- package/src/components/postlist/pagination.astro +40 -0
- package/src/components/postlist/postsList.astro +57 -0
- package/src/content/blog/default/Extended Search.md +50 -0
- package/src/content/blog/default/Mail.md +15 -0
- package/src/content/blog/default/history//345/205/254/345/205/203/345/211/215//347/247/246/345/247/213/347/232/207/347/273/237/344/270/200/345/205/255/345/233/275.md +40 -0
- package/src/content/blog/default/history//350/277/221/344/273/243/347/257/207//344/270/255/345/233/275/345/205/261/344/272/247/345/205/232/345/205/232/345/217/262.md +2361 -0
- package/src/content/blog/default/it/Rust/345/237/272/346/234/254/350/257/255/346/263/225.md +298 -0
- package/src/content/config.ts +38 -0
- package/src/env.d.ts +148 -0
- package/src/layouts/BaseLayout.astro +67 -0
- package/src/layouts/DefaultMdLayout.astro +46 -0
- package/src/layouts/HomeLayout.astro +27 -0
- package/src/layouts/PostLayout.astro +60 -0
- package/src/layouts/TagsLayout.astro +44 -0
- package/src/layouts/c.astro +42 -0
- package/src/layouts/h.astro +60 -0
- package/src/pages/404.md +10 -0
- package/src/pages/[...page].astro +46 -0
- package/src/pages/about/index.md +90 -0
- package/src/pages/blog/[...slug].astro +68 -0
- package/src/pages/categories/[category]/[...page].astro +45 -0
- package/src/pages/categories/index.astro +20 -0
- package/src/pages/friends/index.md +24 -0
- package/src/pages/rss.xml.js +20 -0
- package/src/pages/tags/[tag]/[...page].astro +42 -0
- package/src/pages/tags/index.astro +19 -0
- package/src/site_config.ts +15 -0
- package/src/styles/animation.scss +94 -0
- package/src/styles/blog/blog.scss +124 -0
- package/src/styles/blog/code.scss +111 -0
- package/src/styles/blog/directives.scss +356 -0
- package/src/styles/blog/index.scss +4 -0
- package/src/styles/blog/post.scss +474 -0
- package/src/styles/components/aside.scss +178 -0
- package/src/styles/components/footer.scss +74 -0
- package/src/styles/components/header.scss +421 -0
- package/src/styles/components/heroWave.scss +24 -0
- package/src/styles/components/main.scss +275 -0
- package/src/styles/components/page-content.scss +147 -0
- package/src/styles/components/pagination.scss +121 -0
- package/src/styles/components/search.scss +349 -0
- package/src/styles/custom.scss +21 -0
- package/src/styles/global.scss +167 -0
- package/src/styles/mixin.scss +17 -0
- package/src/styles/tags/tags.scss +83 -0
- package/src/theme_config.ts +178 -0
- package/src/utils/generateSearchData.ts +30 -0
- package/src/utils/md.ts +114 -0
- package/src/utils/processMd.ts +278 -0
- package/src/utils/utils.ts +87 -0
- package/tsconfig.json +32 -0
- package/vercel.json +26 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
@import "./animation.scss";
|
2
|
+
@import "./custom.scss";
|
3
|
+
// @import "./components/index.scss";
|
4
|
+
// @import "./blog/index.scss";
|
5
|
+
|
6
|
+
* {
|
7
|
+
box-sizing: border-box;
|
8
|
+
}
|
9
|
+
|
10
|
+
::-webkit-scrollbar {
|
11
|
+
width: 8px;
|
12
|
+
|
13
|
+
height: 8px;
|
14
|
+
}
|
15
|
+
|
16
|
+
::-webkit-scrollbar-thumb {
|
17
|
+
border-radius: 3px;
|
18
|
+
|
19
|
+
background: var(--theme-color);
|
20
|
+
}
|
21
|
+
|
22
|
+
::-webkit-scrollbar-track {
|
23
|
+
border-radius: 3px;
|
24
|
+
|
25
|
+
background: rgba(0, 0, 0, 0.06);
|
26
|
+
}
|
27
|
+
|
28
|
+
ul,
|
29
|
+
ol {
|
30
|
+
list-style-type: none;
|
31
|
+
}
|
32
|
+
|
33
|
+
body {
|
34
|
+
overflow-x: hidden;
|
35
|
+
|
36
|
+
margin: 0;
|
37
|
+
|
38
|
+
background: var(--body-background-color);
|
39
|
+
|
40
|
+
font-family: var(--default-font-family);
|
41
|
+
}
|
42
|
+
|
43
|
+
:root {
|
44
|
+
--theme-color: #a57ad4;
|
45
|
+
|
46
|
+
--font-black-white: #363636;
|
47
|
+
|
48
|
+
--font-white-black: white;
|
49
|
+
|
50
|
+
--navbar-bg-color: rgb(255 255 255 / 80%);
|
51
|
+
|
52
|
+
--button-background-black: #363636;
|
53
|
+
|
54
|
+
--button-background-white: var(--font-white);
|
55
|
+
|
56
|
+
--body-background-color: #f7f9fe;
|
57
|
+
|
58
|
+
--codeblock-background-grey: var(--background-grey);
|
59
|
+
|
60
|
+
--codeblock-copybutton-grey: var(--font-light-grey);
|
61
|
+
|
62
|
+
--border-light-grey: #ddd;
|
63
|
+
|
64
|
+
--mark-background: #dfbfff;
|
65
|
+
|
66
|
+
--link-color: #49ca1f;
|
67
|
+
|
68
|
+
--light-grey: #ddd;
|
69
|
+
|
70
|
+
--font-light-grey: #ddd;
|
71
|
+
|
72
|
+
--font-mid-grey: #696969;
|
73
|
+
|
74
|
+
--font-dark-grey: #444;
|
75
|
+
|
76
|
+
--font-white: white;
|
77
|
+
|
78
|
+
--font-code-color: rgb(255 136 0);
|
79
|
+
|
80
|
+
--font-code-background: #eee;
|
81
|
+
|
82
|
+
--background-white: white;
|
83
|
+
|
84
|
+
--card-background: white;
|
85
|
+
|
86
|
+
--background-grey: #eee;
|
87
|
+
|
88
|
+
--mask-grey: var(--light-grey);
|
89
|
+
|
90
|
+
--aside-link-color: #822eda;
|
91
|
+
|
92
|
+
&[data-theme="dark"] {
|
93
|
+
--theme-color: #d4af7a;
|
94
|
+
|
95
|
+
--font-black-white: white;
|
96
|
+
|
97
|
+
--font-white-black: black;
|
98
|
+
|
99
|
+
--navbar-bg-color: rgba(0 0 0 / 5%);
|
100
|
+
|
101
|
+
--button-background-black: white;
|
102
|
+
|
103
|
+
--button-background-white: var(--font-white);
|
104
|
+
|
105
|
+
--body-background-color: #18171d;
|
106
|
+
|
107
|
+
--codeblock-background-grey: #757575;
|
108
|
+
|
109
|
+
--codeblock-copybutton-grey: #ddd;
|
110
|
+
|
111
|
+
--font-code-background: #666;
|
112
|
+
|
113
|
+
--card-background: #1b1c20;
|
114
|
+
|
115
|
+
--mask-grey: #000;
|
116
|
+
|
117
|
+
--background-white: #0a0a0c;
|
118
|
+
|
119
|
+
--font-code-color: rgb(235, 125, 0);
|
120
|
+
|
121
|
+
--font-mid-grey: #ddd;
|
122
|
+
|
123
|
+
--border-light-grey: #696969;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
:root {
|
128
|
+
--header-nav-height: 4rem;
|
129
|
+
|
130
|
+
--header-item-icon-size: 18px;
|
131
|
+
|
132
|
+
--header-button-icon-size: 22px;
|
133
|
+
|
134
|
+
--font-code-size: 18px;
|
135
|
+
|
136
|
+
--font-post-size: 18px;
|
137
|
+
|
138
|
+
--code-lang-height: 35px;
|
139
|
+
}
|
140
|
+
|
141
|
+
:root {
|
142
|
+
--heading-font-family-en: georgia pro, crimson, georgia, -apple-system,
|
143
|
+
blinkmacsystemfont, "Segoe UI", roboto, oxygen, ubuntu, cantarell,
|
144
|
+
"Fira Sans", "Droid Sans", "Helvetica Neue", stheiti, "Microsoft YaHei",
|
145
|
+
simsun, sans-serif;
|
146
|
+
|
147
|
+
--heading-font-family-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei";
|
148
|
+
|
149
|
+
--code-font-family: consolas, Menlo, "PingFang SC", "Microsoft YaHei",
|
150
|
+
sans-serif;
|
151
|
+
|
152
|
+
--default-font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei";
|
153
|
+
}
|
154
|
+
|
155
|
+
:root {
|
156
|
+
--header-shadow: 0 8px 8px rgb(0 0 0 / 20%);
|
157
|
+
|
158
|
+
--card-shadow: 4px 4px 8px rgba(0, 0, 0, 7%);
|
159
|
+
|
160
|
+
--card-tiny-shadow: 2px 2px 4px rgb(0 0 0 / 15%);
|
161
|
+
|
162
|
+
--elastic-animation: cubic-bezier(0.42, 0, 0, 1.53);
|
163
|
+
|
164
|
+
--appear-animation: 0.3s ease 0.1s 1 normal both running appear;
|
165
|
+
|
166
|
+
--shak-hard-animation: 0.5s ease-in-out infinite shake-hard;
|
167
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
@import "../mixin.scss";
|
2
|
+
.tags-wrap {
|
3
|
+
display: flex;
|
4
|
+
|
5
|
+
align-items: center;
|
6
|
+
|
7
|
+
justify-content: center;
|
8
|
+
|
9
|
+
min-height: 300px;
|
10
|
+
.tags {
|
11
|
+
display: flex;
|
12
|
+
|
13
|
+
align-items: center;
|
14
|
+
|
15
|
+
flex-wrap: wrap;
|
16
|
+
|
17
|
+
justify-content: center;
|
18
|
+
|
19
|
+
width: 100%;
|
20
|
+
|
21
|
+
max-width: 800px;
|
22
|
+
.tag {
|
23
|
+
margin: 0.5rem;
|
24
|
+
|
25
|
+
padding: 5px 8px;
|
26
|
+
|
27
|
+
text-decoration: none;
|
28
|
+
|
29
|
+
color: var(--font-black-white);
|
30
|
+
|
31
|
+
border-radius: 10px;
|
32
|
+
|
33
|
+
background-color: var(--card-background);
|
34
|
+
|
35
|
+
font-size: 20px;
|
36
|
+
|
37
|
+
@include card-style();
|
38
|
+
&:hover {
|
39
|
+
transform: scale(1.2);
|
40
|
+
|
41
|
+
color: white;
|
42
|
+
|
43
|
+
background: var(--theme-color);
|
44
|
+
.tag-text {
|
45
|
+
&::before {
|
46
|
+
color: white;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
.tag-text {
|
51
|
+
&::before {
|
52
|
+
margin-right: 3px;
|
53
|
+
|
54
|
+
content: "#";
|
55
|
+
|
56
|
+
transition: 0.3s ease;
|
57
|
+
|
58
|
+
color: var(--font-light-grey);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
&.floating {
|
64
|
+
.tag {
|
65
|
+
animation: floating 7s ease-in-out infinite alternate;
|
66
|
+
|
67
|
+
&:nth-child(3n + 1) {
|
68
|
+
animation-delay: 0s;
|
69
|
+
}
|
70
|
+
&:nth-child(3n + 2) {
|
71
|
+
animation-delay: 2.334s;
|
72
|
+
}
|
73
|
+
&:nth-child(3n + 3) {
|
74
|
+
animation-delay: 4.667s;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
#inner-container {
|
81
|
+
.main-content {
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1,178 @@
|
|
1
|
+
import { Icons } from "@comp/icons/icon";
|
2
|
+
import { SiteConfig } from "./site_config";
|
3
|
+
// import { faStar } from "@fortawesome/free-solid-svg-icons";
|
4
|
+
// import { library, icon } from "@fortawesome/fontawesome-svg-core";
|
5
|
+
//import Code from '~/components/code.astro';
|
6
|
+
// library.add(faStar);
|
7
|
+
// const starIcon = icon({ prefix: "fas", iconName: "star" });
|
8
|
+
|
9
|
+
const today = new Date();
|
10
|
+
|
11
|
+
export const ThemeConfig: Configs = {
|
12
|
+
site: {
|
13
|
+
title: SiteConfig.title,
|
14
|
+
favicon: "/favicon.png",
|
15
|
+
logo: "/favicon.png",
|
16
|
+
author: "Minearm-RPM",
|
17
|
+
localSearch: {
|
18
|
+
enable: true,
|
19
|
+
comment: "你可以使用类似 unix 的格式:[扩展搜索](/blog/Search-help/)",
|
20
|
+
hits: ["[扩展搜索](/blog/Search-help/)", "[Help](/blog/Search-help/)"],
|
21
|
+
},
|
22
|
+
backgroundBubbles: 20,
|
23
|
+
},
|
24
|
+
head: [``],
|
25
|
+
body: [``],
|
26
|
+
header: {
|
27
|
+
menu: [
|
28
|
+
{
|
29
|
+
name: "主页",
|
30
|
+
customClass: "home",
|
31
|
+
link: "/",
|
32
|
+
icon: "local:solid.house",
|
33
|
+
},
|
34
|
+
{
|
35
|
+
name: "博客",
|
36
|
+
customClass: "articles",
|
37
|
+
icon: "local:solid.pen-fancy",
|
38
|
+
children: [
|
39
|
+
{
|
40
|
+
name: "分类",
|
41
|
+
customClass: "categories",
|
42
|
+
icon: "local:solid.hard-drive",
|
43
|
+
link: "/categories",
|
44
|
+
},
|
45
|
+
{
|
46
|
+
name: "标签",
|
47
|
+
customClass: "tags",
|
48
|
+
icon: "local:solid.tags",
|
49
|
+
link: "/tags",
|
50
|
+
},
|
51
|
+
],
|
52
|
+
},
|
53
|
+
{
|
54
|
+
name: "我的",
|
55
|
+
customClass: "mine",
|
56
|
+
icon: Icons.IDcardIcon,
|
57
|
+
children: [
|
58
|
+
{
|
59
|
+
name: "朋友",
|
60
|
+
customClass: "friends",
|
61
|
+
icon: "local:solid.link",
|
62
|
+
link: "/friends",
|
63
|
+
},
|
64
|
+
{
|
65
|
+
name: "MC",
|
66
|
+
customClass: "MC",
|
67
|
+
icon: "local:solid.paper-plane",
|
68
|
+
link: "https://game.minearm.org",
|
69
|
+
},
|
70
|
+
],
|
71
|
+
},
|
72
|
+
{
|
73
|
+
name: "关于",
|
74
|
+
customClass: "about",
|
75
|
+
link: "/about",
|
76
|
+
icon: "local:solid.paper-plane",
|
77
|
+
},
|
78
|
+
],
|
79
|
+
buttons: [
|
80
|
+
{
|
81
|
+
icon: "local:solid.house",
|
82
|
+
link: "/",
|
83
|
+
customClass: "",
|
84
|
+
title: "返回主页",
|
85
|
+
},
|
86
|
+
],
|
87
|
+
functions: {
|
88
|
+
headerLogo: "left",
|
89
|
+
themeControl: true,
|
90
|
+
pagePercent: true,
|
91
|
+
},
|
92
|
+
},
|
93
|
+
aside: {
|
94
|
+
authorInfo: {
|
95
|
+
avatar: "/avatar.avif",
|
96
|
+
description: "localhost@root #~",
|
97
|
+
socialMedias: [
|
98
|
+
{
|
99
|
+
link: "https://github.com/Minearm-RPM",
|
100
|
+
customClass: "github",
|
101
|
+
icon: "local:brands.github",
|
102
|
+
title: "github",
|
103
|
+
},
|
104
|
+
{
|
105
|
+
link: "mailto:minearm@minearm.org",
|
106
|
+
customClass: "mail-minearm",
|
107
|
+
icon: "local:solid.envelope",
|
108
|
+
title: "mail",
|
109
|
+
},
|
110
|
+
{
|
111
|
+
link: "https://space.bilibili.com/1279178840",
|
112
|
+
customClass: "bilibili",
|
113
|
+
icon: "local:brands.bilibili",
|
114
|
+
title: "social-bili",
|
115
|
+
},
|
116
|
+
],
|
117
|
+
},
|
118
|
+
announcement: {
|
119
|
+
headline: "看公告啦!",
|
120
|
+
content:
|
121
|
+
"欢迎各位[找茬](https://github.com/Minearm-RPM/minearm-rpm-arch/issues)~",
|
122
|
+
},
|
123
|
+
siteInfo: {
|
124
|
+
busuanzi: false,
|
125
|
+
totalWordCounts: true,
|
126
|
+
totalPostCounts: true,
|
127
|
+
},
|
128
|
+
customCards: [
|
129
|
+
{
|
130
|
+
// icon: `<i class="fa-solid fa-star"></i>`,
|
131
|
+
icon: "local:solid.star",
|
132
|
+
title: "推荐文章",
|
133
|
+
content: "暂时莫有<br>T-T",
|
134
|
+
},
|
135
|
+
],
|
136
|
+
},
|
137
|
+
footer: {
|
138
|
+
text: "Design & Build with ❤ by Minearm-RPM",
|
139
|
+
copyright: `© 2023-${today.getFullYear()} By [Minearm-RPM](/about)`,
|
140
|
+
// 也可以使用 包裹函数体,并返回替换值
|
141
|
+
// You can also use to wrap the function body and return the replacement value.
|
142
|
+
// copyright: `© 2023-{{const today = new Date();return today.getFullYear();}} By [Minearm-RPM](/about)`,
|
143
|
+
},
|
144
|
+
homePage: {
|
145
|
+
heroShoot: "/heroimg.jpg",
|
146
|
+
heroTitle: "Minearm-RPM & Website",
|
147
|
+
heroDescription: "Welcome to Minearm & Website!",
|
148
|
+
defaultCover: "/heroimg.jpg",
|
149
|
+
paginationSize: 10,
|
150
|
+
aside: {
|
151
|
+
comps: ["AuthorInfo"],
|
152
|
+
stickyComps: ["Announcement", "SiteInfo"],
|
153
|
+
direct: "right",
|
154
|
+
},
|
155
|
+
},
|
156
|
+
postPage: {
|
157
|
+
aside: {
|
158
|
+
comps: ["AuthorInfo"],
|
159
|
+
stickyComps: [],
|
160
|
+
},
|
161
|
+
},
|
162
|
+
tagsPage: {
|
163
|
+
floating: true,
|
164
|
+
},
|
165
|
+
comments: {
|
166
|
+
// type: "twikoo",
|
167
|
+
// options: {
|
168
|
+
// envId: "",
|
169
|
+
// lang: "zh-CN",
|
170
|
+
// },
|
171
|
+
type: "waline",
|
172
|
+
options: {
|
173
|
+
serverURL: "https://api.minearm.org",
|
174
|
+
},
|
175
|
+
//type: true,
|
176
|
+
//options: null,
|
177
|
+
},
|
178
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import { utils } from "./utils";
|
3
|
+
// import { SiteConfig } from "../site_config";
|
4
|
+
|
5
|
+
interface SearchData {
|
6
|
+
title: string;
|
7
|
+
content: string;
|
8
|
+
url: string;
|
9
|
+
}
|
10
|
+
|
11
|
+
const searchDatas: SearchData[] = [];
|
12
|
+
|
13
|
+
export function generateSearchData() {
|
14
|
+
return (_: any, file: any) => {
|
15
|
+
if (file.history[0].includes(`content\\blog`)) {
|
16
|
+
const content = utils.cleanContent(file.value as string);
|
17
|
+
|
18
|
+
searchDatas.push({
|
19
|
+
title: file.data.astro.frontmatter.title,
|
20
|
+
content: content,
|
21
|
+
url: `/blog/${file.data.astro.frontmatter.abbrlink}`,
|
22
|
+
});
|
23
|
+
|
24
|
+
fs.writeFileSync(
|
25
|
+
"./public/scripts/searchData.json",
|
26
|
+
JSON.stringify(searchDatas, null, 2)
|
27
|
+
);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
}
|
package/src/utils/md.ts
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
import { visit } from "unist-util-visit";
|
2
|
+
import getReadingTime from "reading-time";
|
3
|
+
import { toString } from "mdast-util-to-string";
|
4
|
+
import { utils } from "./utils";
|
5
|
+
import { writeFileSync } from "fs";
|
6
|
+
import { processRemark, processRehype, processDir } from "./processMd";
|
7
|
+
|
8
|
+
import mdata from "../../public/scripts/mdata.json";
|
9
|
+
|
10
|
+
mdata.totalWordCounts = 0;
|
11
|
+
mdata.totalPostCounts = 0;
|
12
|
+
|
13
|
+
export function markdownDirectives() {
|
14
|
+
return (tree: any, file: any) => {
|
15
|
+
visit(tree, (node, index, parent) => {
|
16
|
+
switch (node.type) {
|
17
|
+
case "textDirective":
|
18
|
+
if (node.name === "color") processDir.dirColor(node);
|
19
|
+
break;
|
20
|
+
case "leafDirective":
|
21
|
+
if (node.name === "link") processDir.dirLink(node, parent);
|
22
|
+
if (node.name === "note") processDir.dirNoteL(node, index, parent);
|
23
|
+
break;
|
24
|
+
case "containerDirective":
|
25
|
+
if (node.name === "links") processDir.dirLinks(node);
|
26
|
+
else if (node.name === "timeline")
|
27
|
+
processDir.dirTimeline(node, index, parent);
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
};
|
32
|
+
}
|
33
|
+
|
34
|
+
export function remarkFrontmatter() {
|
35
|
+
return function (tree: any, { data }: any) {
|
36
|
+
// 阅读时长
|
37
|
+
const textOnPage = toString(tree);
|
38
|
+
const readingTime = getReadingTime(textOnPage);
|
39
|
+
data.astro.frontmatter.numberOfWords = textOnPage.length;
|
40
|
+
data.astro.frontmatter.minutesRead = readingTime.text;
|
41
|
+
mdata.totalWordCounts += textOnPage.length;
|
42
|
+
mdata.totalPostCounts += 1;
|
43
|
+
writeFileSync(
|
44
|
+
"./public/scripts/mdata.json",
|
45
|
+
JSON.stringify(mdata, null, 2)
|
46
|
+
);
|
47
|
+
};
|
48
|
+
}
|
49
|
+
|
50
|
+
export function rehypeFrontmatter() {
|
51
|
+
return function (tree: any, { data }: any) {
|
52
|
+
// 目录
|
53
|
+
const toc: {
|
54
|
+
level: string;
|
55
|
+
id: string;
|
56
|
+
value: string;
|
57
|
+
}[] = [];
|
58
|
+
const headings = ["h1", "h2", "h3"];
|
59
|
+
visit(tree, (node) => {
|
60
|
+
if (
|
61
|
+
headings.includes(node.tagName) &&
|
62
|
+
!("className" in node.properties)
|
63
|
+
) {
|
64
|
+
const id = utils.generateIdFromHeading(node.children[0].value);
|
65
|
+
toc.push({
|
66
|
+
level: node.tagName[1],
|
67
|
+
id: id,
|
68
|
+
value: node.children[0].value,
|
69
|
+
});
|
70
|
+
}
|
71
|
+
});
|
72
|
+
data.astro.frontmatter.toc = toc;
|
73
|
+
};
|
74
|
+
}
|
75
|
+
|
76
|
+
export function rehypeRestyling() {
|
77
|
+
return (tree: any) => {
|
78
|
+
visit(tree, (node, index, parent) => {
|
79
|
+
switch (node.tagName) {
|
80
|
+
case "blockquote":
|
81
|
+
processRemark.processBlockquote(node);
|
82
|
+
break;
|
83
|
+
case "table":
|
84
|
+
processRemark.processTable(node, parent, index);
|
85
|
+
break;
|
86
|
+
case "img":
|
87
|
+
if (!node.properties.className) {
|
88
|
+
processRemark.processImg(node, parent, index);
|
89
|
+
}
|
90
|
+
break;
|
91
|
+
case "a":
|
92
|
+
processRemark.processA(node);
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
});
|
96
|
+
};
|
97
|
+
}
|
98
|
+
|
99
|
+
export function remarkRestyling() {
|
100
|
+
return (tree: any, file: any) => {
|
101
|
+
visit(tree, (node, index, parent) => {
|
102
|
+
switch (node.type) {
|
103
|
+
case "code":
|
104
|
+
if (!node.meta?.lang) {
|
105
|
+
processRehype.processCode(node, parent, index);
|
106
|
+
}
|
107
|
+
break;
|
108
|
+
case "link":
|
109
|
+
processRehype.processLink(node);
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
});
|
113
|
+
};
|
114
|
+
}
|