Skip to content

Commit 3e08daa

Browse files
committed
docs: 添加自定义主题文档
1 parent f55559c commit 3e08daa

File tree

2 files changed

+306
-1
lines changed

2 files changed

+306
-1
lines changed

docs/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<script src="//cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js"></script>
3131
<!-- docsify内置的代码高亮 -->
3232
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-dart.min.js"></script>
33+
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-css.min.js"></script>
34+
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-json.min.js"></script>
35+
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-javascript.min.js"></script>
3336
<!-- vue3 -->
3437
<script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
3538
</body>

docs/zh-cn/docs/theme/custom.md

Lines changed: 303 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,303 @@
1-
# custom
1+
2+
# 主题自定义
3+
4+
> Glidea 提供了强大的主题自定义能力,你可以自行设计自定义配置提供给主题使用者
5+
6+
每一个主题都可选地搭配一个 `config.json` 配置文件和一个 `style-override.js` 样式覆盖文件
7+
8+
9+
## 示例 :id=example
10+
11+
### config.json
12+
13+
```json
14+
{
15+
"name": "Notes",
16+
"version": "1.0.0",
17+
"author": "EryouHao",
18+
"customConfig": [
19+
{
20+
"name": "skin",
21+
"label": "皮肤",
22+
"group": "皮肤",
23+
"value": "white",
24+
"type": "select",
25+
"options": [
26+
{
27+
"label": "简约白",
28+
"value": "white"
29+
},
30+
{
31+
"label": "低调黑",
32+
"value": "black"
33+
}
34+
]
35+
},
36+
{
37+
"name": "contentMaxWidth",
38+
"label": "内容区最大宽度",
39+
"group": "布局",
40+
"value": "800px",
41+
"type": "input",
42+
"note": "可填像素类型(如: 320px)或百分比类型(如: 38.2%)"
43+
},
44+
{
45+
"name": "textSize",
46+
"label": "正文内容文字大小",
47+
"group": "布局",
48+
"value": "16px",
49+
"type": "input",
50+
"note": "px 或 rem(如 16px 或 1rem)"
51+
},
52+
{
53+
"name": "pageBgColor",
54+
"label": "网页背景色",
55+
"group": "颜色",
56+
"value": "#ffffff",
57+
"type": "input",
58+
"card": "color",
59+
"note": "颜色字符串:(如:#EEEEEE、rgba(255, 255, 255, 0.9))"
60+
},
61+
{
62+
"name": "github",
63+
"label": "Github",
64+
"group": "社交",
65+
"value": "",
66+
"type": "input",
67+
"note": "链接地址"
68+
},
69+
{
70+
"name": "twitter",
71+
"label": "Twitter",
72+
"group": "社交",
73+
"value": "",
74+
"type": "input",
75+
"note": "链接地址"
76+
},
77+
{
78+
"name": "weibo",
79+
"label": "微博",
80+
"group": "社交",
81+
"value": "",
82+
"type": "input",
83+
"note": "链接地址"
84+
},
85+
{
86+
"name": "customCss",
87+
"label": "自定义CSS",
88+
"group": "自定义样式",
89+
"value": "",
90+
"type": "textarea",
91+
"note": ""
92+
},
93+
{
94+
"name": "ga",
95+
"label": "跟踪 ID",
96+
"group": "谷歌统计",
97+
"value": "",
98+
"type": "input",
99+
"note": "UA-xxxxxxxxx-x"
100+
}
101+
]
102+
}
103+
```
104+
105+
### style-override.js
106+
107+
```js
108+
const generateOverride = (params = {}) => {
109+
letresult = "";
110+
//暗黑皮肤
111+
if (params.skin && params.skin !== "white") {
112+
result += `
113+
body{
114+
color:#dee2e6;
115+
}
116+
a,.link{
117+
color:#e9ecef;
118+
}
119+
`;
120+
}
121+
//内容区最大宽度-contentMaxWidth
122+
if (params.contentMaxWidth && params.contentMaxWidth !== "800px") {
123+
result += `
124+
.main{
125+
max-width:${params.contentMaxWidth};
126+
}
127+
`;
128+
}
129+
//正文内容文字大小-textSize
130+
if (params.textSize && params.textSize !== "16px") {
131+
result += `
132+
.post-detail.post.post-contentp{
133+
font-size:${params.textSize};
134+
}
135+
`;
136+
}
137+
//网页背景色-pageBgColor
138+
if (params.pageBgColor && params.pageBgColor !== "#ffffff") {
139+
result += `
140+
body{
141+
background:${params.pageBgColor};
142+
}
143+
`;
144+
}
145+
//文字颜色-textColor
146+
if (params.textColor && params.textColor !== "#333333") {
147+
result += `
148+
body{
149+
color: ${params.textColor};
150+
}
151+
`;
152+
}
153+
//文字颜色-textColor
154+
if (params.textColor && params.textColor !== "#333333") {
155+
result += `
156+
body{
157+
color:${params.textColor};
158+
}
159+
`;
160+
}
161+
//自定义CSS-customCss
162+
if (params.customCss) {
163+
result += `
164+
${params.customCss}
165+
`;
166+
}
167+
returnresult;
168+
};
169+
170+
module.exports = generateOverride;
171+
```
172+
173+
是的,如你所见,自定义配置就是这么简单,清晰。下面让我们详细了解一下具体字段和使用方法:
174+
175+
176+
## 字段类型配置 :id=field-config
177+
178+
每个主题的根目录可包含一个 config.json 的文件。
179+
180+
此文件中包含了主题的基本信息如:`name`, `version`, `author`, `repository` 等,\
181+
其中有一个特殊的字段 `customConfig`,这便是自定义配置字段了,类型为数组,\
182+
每项元素的格式如下:
183+
184+
```json
185+
{
186+
"name": "字段变量名称,可在模版或样式覆盖文件中使用",
187+
"label": "字段展示名称,在软件中显示的名称",
188+
"group": "字段所属分组,在软件中显示的分组名称",
189+
"value": "字段默认值",
190+
"type": "字段输入类型,可选值:'input', 'select', 'textarea', 'radio', 'switch', 'picture-upload', 'markdown'(可提供一个 markdown 的输入框), 'array'",
191+
"note": "输入框 placeholder 提示文案, type 为 'input', 'textarea' 时可用, 若为其他type 类型,则展示在表单空间下面",
192+
"card": "字段附属 Card, 可选值: 'color'(提供一个推荐颜色卡片快捷选择),'post'(提供文章数据卡片提供选择), type 为 'input' 时可用",
193+
"options": [ // type 为 'select', 'radio' 时可用
194+
{
195+
"label": "选项显示名称",
196+
"value": "选项对应值"
197+
}
198+
]
199+
}
200+
```
201+
202+
203+
## 图片类型配置 :id=image-config
204+
205+
```json
206+
{
207+
"name": "sidebarBgImage",
208+
"label": "侧边栏背景图",
209+
"group": "图片",
210+
"value": "/media/images/sidebar-bg.jpg",
211+
"type": "picture-upload",
212+
"note": ""
213+
}
214+
```
215+
216+
217+
## 数组类型配置 :id=array-config
218+
219+
```json
220+
{
221+
222+
"name": "friends",
223+
"label": "友链",
224+
"group": "友链",
225+
"type": "array",
226+
"value": [
227+
{
228+
"siteName": "海岛心hey",
229+
"siteLink": "https://fehey.com",
230+
"siteLogo": "",
231+
"description": "一个前端"
232+
},
233+
{
234+
"siteName": "Glidea 官网",
235+
"siteLink": "https://glidea/nianian.cn",
236+
"siteLogo": "",
237+
"description": "一个静态博客写作客户端"
238+
}
239+
], // 若无默认数据,可写成 []
240+
"arrayItems": [
241+
{
242+
"label": "名称",
243+
"name": "siteName",
244+
"type": "input",
245+
"value": ""
246+
},
247+
{
248+
"label": "链接",
249+
"name": "siteLink",
250+
"type": "input",
251+
"value": ""
252+
},
253+
{
254+
"label": "Logo",
255+
"name": "siteLogo",
256+
"type": "picture-upload",
257+
"value": ""
258+
},
259+
{
260+
"label": "描述",
261+
"name": "description",
262+
"type": "textarea",
263+
"value": ""
264+
}
265+
], // 数组对象的字段定义
266+
"note": ""
267+
}
268+
```
269+
270+
大部分情况下,使用 input 类型的就够用了
271+
272+
273+
这些字段都可以在模版中(对应: [`site.customConfig.自定义字段`](#configjson))或样式覆盖文件(对应:入参)中使用
274+
275+
在模版中使用时,你可以尽情发挥你的想象,社交、统计、友链、外链背景图、背景音乐...
276+
277+
## 样式覆盖配置 :id=style-override
278+
279+
当然,在样式覆盖文件中也可以使用:
280+
281+
```js
282+
const generateOverride = (params = {}) => {
283+
// params 即自定义字段对象,可以根据字段值来添加自定义 css
284+
let result = ''
285+
// 正文内容文字大小 - textSize
286+
if (params.textSize && params.textSize !== '16px') {
287+
result += `
288+
body {
289+
font-size: ${params.textSize};
290+
}
291+
`
292+
}
293+
// 最终结果会放在 `main.css` 的文件末尾
294+
return result
295+
}
296+
module.exports = generateOverride
297+
```
298+
299+
到这里,相信你已经搞清楚如何给主题增加自定义配置能力了,快去开发一个属于自己的主题吧,分享给其他人会更佳呦!
300+
301+
若还是不清楚,可参考应用内置主题代码结构:
302+
303+
[Github themes zip](https://github.com/wonder-light/glidea/tree/main/assets/public/default-files.zip)

0 commit comments

Comments
 (0)