6
6
7
7
# -- Path setup --------------------------------------------------------------
8
8
9
- # If extensions (or modules to document with autodoc) are in another directory,
10
- # add these directories to sys.path here. If the directory is relative to the
11
- # documentation root, use os.path.abspath to make it absolute, like shown here.
12
- #
13
9
from __future__ import annotations
14
- import os
15
10
from datetime import datetime
16
- from enum import Enum , auto
17
11
import yaml
18
12
19
13
# -- Split configurations ----------------------------------------------------
20
14
21
15
from _conf .schemas import _schemas
16
+ from _conf .deploy import D
17
+
18
+ # For `.. only::` directive.
19
+ if D .is_private ():
20
+ tags .add ('private' ) # type: ignore
22
21
23
22
with open ('./_conf/redirect.yml' ) as data :
24
23
_redirects = yaml .safe_load (data )
39
38
40
39
# -- Enviroment information -----------------------------------------------------
41
40
42
- class Deployment (Enum ):
43
- Github = auto ()
44
- Gitee = auto ()
45
- Raspi = auto () # Raspberry Pi
46
- Local = auto ()
47
-
48
- @classmethod
49
- def current (cls ) -> Deployment :
50
- if os .environ .get ('GITHUB_REPOSITORY' ) == 'SilverRainZ/ronin' :
51
- return Deployment .Raspi
52
- if os .environ .get ('GITHUB_WORKFLOW' ) == 'Publish Github Pages' :
53
- return Deployment .Github
54
- if os .environ .get ('GITHUB_WORKFLOW' ) == 'Publish Gitee Pages' :
55
- return Deployment .Gitee
56
- return Deployment .Local
57
-
58
- def is_private (self ) -> bool :
59
- return not self .is_public ()
60
-
61
- def is_public (self ) -> bool :
62
- return self in [Deployment .Github , Deployment .Gitee ]
63
-
64
- def is_mirror (self ) -> bool :
65
- return self is not Deployment .Github
66
-
67
- def url (self ) -> str :
68
- if self == Deployment .Github :
69
- return 'https://silverrainz.me/'
70
- elif self == Deployment .Gitee :
71
- return 'https://silverrainz.gitee.io/'
72
- elif self == Deployment .Raspi :
73
- return 'https://rpi3/bullet'
74
- else :
75
- # file:///build_dir/html/index.html
76
- return 'TODO'
77
-
78
- D = Deployment .current ()
79
- print ('Deployment:' , D )
80
- # For `.. only::` directive.
81
- if D .is_private ():
82
- tags .add ('private' ) # type: ignore
83
-
84
41
# -- General configuration ---------------------------------------------------
85
42
86
43
# Add any Sphinx extension module names here, as strings. They can be
@@ -179,7 +136,7 @@ def url(self) -> str:
179
136
# html_theme_options['announcement'] = '</p>blahblah… </p>
180
137
181
138
if D .is_mirror ():
182
- src = Deployment .Github
139
+ src = D .Github
183
140
msg = f'<p> 这是部署于 { D } 的镜像,访问源站点:<a class="source-page" href="{ src .url ()} ">{ src } </a></p>'
184
141
if html_theme_options .get ('announcement' ):
185
142
html_theme_options ['announcement' ] += msg
@@ -277,12 +234,12 @@ def url(self) -> str:
277
234
278
235
if D .is_public ():
279
236
extensions .append ('sphinxcontrib.gtagjs' )
280
- if D is Deployment .Github :
237
+ if D is D .Github :
281
238
gtagjs_ids = ['G-FYHS50G6DL' ]
282
- elif D is Deployment .Gitee :
239
+ elif D is D .Gitee :
283
240
gtagjs_ids = ['G-5MZDR9VPYN' ]
284
241
285
- if D is Deployment .Local :
242
+ if D is D .Local :
286
243
extensions .append ('sphinxnotes.snippet.ext' )
287
244
snippet_config = {}
288
245
snippet_patterns = {
@@ -339,7 +296,7 @@ def url(self) -> str:
339
296
lilypond_audio_volume = 300
340
297
lilypond_audio_format = 'mp3'
341
298
342
- if D is not Deployment .Local :
299
+ if D is not D .Local :
343
300
extensions .append ('sphinxnotes.recentupdate' )
344
301
recentupdate_date_format = datefmt
345
302
recentupdate_exclude_path = ['_templates' ]
@@ -353,7 +310,7 @@ def url(self) -> str:
353
310
ogp_site_name = project
354
311
ogp_image = D .url () + logo
355
312
356
- if D is not Deployment .Local :
313
+ if D is not D .Local :
357
314
# Doesn't work locally
358
315
extensions .append ('notfound.extension' )
359
316
notfound_urls_prefix = ''
@@ -390,13 +347,13 @@ def url(self) -> str:
390
347
'rst' : 'reStructuredText' ,
391
348
}
392
349
393
- if D is not Deployment .Local :
350
+ if D is not D .Local :
394
351
# Speed up local build (prevent read git timestamp).
395
352
extensions .append ('sphinx_last_updated_by_git' )
396
353
397
354
# For .. pdf-include:: directive.
398
355
extensions .append ('sphinx_simplepdf' )
399
356
400
- if D is Deployment .Local :
357
+ if D is D .Local :
401
358
# Speed up local incremental HTML build (may cause document inconsistencies).
402
359
extensions .append ('sphinxnotes.fasthtml' )
0 commit comments