1
- import { computed , reactive , watch , watchEffect } from "vue" ;
2
- import { notebook } from "../core/siyuan_type" ;
3
- import { deepAssign } from "@/util/deep_assign" ;
4
- import { storeDep } from "@/dependency" ;
1
+ import { computed , reactive , watch , watchEffect } from 'vue'
2
+ import { notebook } from '../core/siyuan_type'
3
+ import { deepAssign } from '@/util/deep_assign'
4
+ import { storeDep } from '@/dependency'
5
+ import { version } from 'jszip'
5
6
6
7
/** 不要在运行时修改这个对象,他只应该在代码中配置 */
7
8
const defaultConfig = {
8
- name : " default" ,
9
+ name : ' default' ,
9
10
/** 需要编译的笔记本 */
10
11
notebook : { } as notebook ,
11
12
/** 思源的鉴权key */
12
- authorized : "" ,
13
+ authorized : '' ,
13
14
/** 思源的api服务地址 */
14
- apiPrefix : " http://127.0.0.1:6806" ,
15
+ apiPrefix : ' http://127.0.0.1:6806' ,
15
16
/** 打包成 zip */
16
17
compressedZip : true ,
17
18
/** 不将 publicZip 打包到 zip 包中 */
@@ -27,39 +28,39 @@ const defaultConfig = {
27
28
* 则会生成 "https://shenzilong.cn/record/思源笔记.html" 这样的绝对路径
28
29
* 参见 https://www.sitemaps.org/protocol.html#escaping
29
30
*/
30
- sitePrefix : "." ,
31
+ sitePrefix : '.' ,
31
32
} ,
32
33
/** 开启增量编译,当开启增量编译时,
33
34
* 在编译过程中会依据 __skipBuilds__ 的内容来跳过一些没有变化不需要重新输出的内容
34
35
*/
35
36
enableIncrementalCompilation : false ,
36
- /** 增量编译文档
37
- * 当需要重新全量编译文档时,将此选项设置为false
37
+ /**
38
+ * 要全量编译文档时将此选项设置为false,当OceanPress版本和上次编译时不同时会忽略此属性全量编译文档
38
39
*/
39
40
enableIncrementalCompilation_doc : true ,
40
41
/** 跳过编译的资源 */
41
42
__skipBuilds__ : { } as {
42
43
[ id : string ] :
43
44
| {
44
- hash ?: string ;
45
- /** 此文档正向引用的其他文档的id */ refs ?: string [ ] ;
46
- /** 挂件快照的更新时间 */ updated ?: string ;
45
+ hash ?: string
46
+ /** 此文档正向引用的其他文档的id */ refs ?: string [ ]
47
+ /** 挂件快照的更新时间 */ updated ?: string
47
48
}
48
- | undefined ;
49
+ | undefined
49
50
} ,
50
51
51
52
cdn : {
52
53
/** 思源 js、css等文件的前缀 */
53
54
siyuanPrefix :
54
- " https://fastly.jsdelivr.net/gh/siyuan-note/oceanpress@main/apps/frontend/public/notebook/" ,
55
+ ' https://fastly.jsdelivr.net/gh/siyuan-note/oceanpress@main/apps/frontend/public/notebook/' ,
55
56
/** 思源 js、css等文件zip包地址 */
56
57
publicZip :
57
- " https://fastly.jsdelivr.net/gh/siyuan-note/oceanpress@main/apps/frontend/public/public.zip" ,
58
+ ' https://fastly.jsdelivr.net/gh/siyuan-note/oceanpress@main/apps/frontend/public/public.zip' ,
58
59
} ,
59
60
/** html模板嵌入代码块,会将此处配置中的代码嵌入到生成的html所对应的位置 */
60
61
embedCode : {
61
- head : "" ,
62
- beforeBody : "" ,
62
+ head : '' ,
63
+ beforeBody : '' ,
63
64
afterBody : `<footer>
64
65
<p style="text-align:center;margin:15px 0;">
65
66
技术支持:
@@ -69,59 +70,67 @@ const defaultConfig = {
69
70
</p>
70
71
</footer>` ,
71
72
} ,
72
- } ;
73
+ OceanPress : {
74
+ /** 此配置文件编译时的版本 */
75
+ version : '' ,
76
+ } ,
77
+ }
73
78
export const configs = reactive ( {
74
79
/** 当前所使用的配置项的 key */
75
- __current__ : " default" as const ,
80
+ __current__ : ' default' as const ,
76
81
/** 为true是表示是代码中设置的默认值,不会保存到本地,避免覆盖之前保存的数据,在加载本地配置后会自动修改为false */
77
82
__init__ : true ,
78
83
default : deepAssign < typeof defaultConfig > ( { } , defaultConfig ) ,
79
- } ) ;
84
+ } )
80
85
81
86
export function addConfig ( name : string , value ?: typeof defaultConfig ) {
82
- configs [ name as "default" ] = deepAssign < typeof defaultConfig > ( { } , value ?? defaultConfig ) ;
87
+ configs [ name as 'default' ] = deepAssign < typeof defaultConfig > (
88
+ { } ,
89
+ value ?? defaultConfig ,
90
+ )
83
91
}
84
92
/** 加载配置文件 */
85
93
export const loadConfigFile = ( c ?: typeof configs ) => {
86
94
if ( c ) {
87
- deepAssign ( configs , c ) ;
95
+ deepAssign ( configs , c )
88
96
} else {
89
- const localConfig = storeDep . getItem ( " configs" ) ;
97
+ const localConfig = storeDep . getItem ( ' configs' )
90
98
if ( localConfig ) {
91
99
/** 从本地存储加载配置 */
92
- deepAssign ( configs , JSON . parse ( localConfig ) ) ;
100
+ deepAssign ( configs , JSON . parse ( localConfig ) )
93
101
}
94
102
}
95
103
96
104
Object . entries ( configs )
97
- . filter ( ( [ key ] ) => key . startsWith ( "__" ) === false )
105
+ . filter ( ( [ key ] ) => key . startsWith ( '__' ) === false )
98
106
. forEach ( ( [ _key , obj ] ) => {
99
107
/** 将新增配置项更新到旧配置上 */
100
- deepAssign ( obj , defaultConfig , { update : false , add : true } ) ;
101
- } ) ;
102
- } ;
103
- export const currentConfig = computed ( ( ) => configs [ configs . __current__ ] ) ;
108
+ deepAssign ( obj , defaultConfig , { update : false , add : true } )
109
+ } )
110
+ }
111
+ export const currentConfig = computed ( ( ) => configs [ configs . __current__ ] )
104
112
105
113
export const saveConfig = ( ) => {
106
- if ( configs . __init__ === false ) storeDep . setItem ( "configs" , JSON . stringify ( configs ) ) ;
107
- } ;
114
+ if ( configs . __init__ === false )
115
+ storeDep . setItem ( 'configs' , JSON . stringify ( configs ) )
116
+ }
108
117
109
- let timer : NodeJS . Timeout | null = null ;
118
+ let timer : NodeJS . Timeout | null = null
110
119
/** 防抖的保存配置 */
111
120
export const debounceSaveConfig = ( ) => {
112
121
if ( timer ) {
113
- clearTimeout ( timer ) ;
122
+ clearTimeout ( timer )
114
123
}
115
124
timer = setTimeout ( ( ) => {
116
- saveConfig ( ) ;
117
- timer = null ;
118
- } , 700 ) ;
119
- } ;
120
- watch ( configs , debounceSaveConfig , { deep : true } ) ;
125
+ saveConfig ( )
126
+ timer = null
127
+ } , 700 )
128
+ }
129
+ watch ( configs , debounceSaveConfig , { deep : true } )
121
130
122
- configs . __init__ = false ;
131
+ configs . __init__ = false
123
132
124
133
/** 浏览器环境下,直接尝试加载配置 */
125
134
if ( globalThis . document ) {
126
- loadConfigFile ( ) ;
135
+ loadConfigFile ( )
127
136
}
0 commit comments