-
Notifications
You must be signed in to change notification settings - Fork 5
/
conf.py
510 lines (441 loc) · 18.1 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from __future__ import annotations
import os
import sys
from datetime import datetime
from enum import Enum, auto
sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = '银色子弹'
author = 'Shengyu Zhang'
author_id = 'SilverRainZ'
author_nick = 'LA'
copyright = '2020-%s, ' % datetime.now().year + author
# -- Non-standard project information ----------------------------------------
logo = '_static/logo.png'
description = 'Yes silver bullet here.'
datefmt = '%Y-%m-%d'
# -- Enviroment information -----------------------------------------------------
class Deployment(Enum):
Github = auto()
Gitee = auto()
Raspi = auto() # Raspberry Pi
Local = auto()
@classmethod
def current(cls) -> Deployment:
if os.environ.get('GITHUB_REPOSITORY') == 'SilverRainZ/ronin':
return Deployment.Raspi
if os.environ.get('GITHUB_WORKFLOW') == 'Publish Github Pages':
return Deployment.Github
if os.environ.get('GITHUB_WORKFLOW') == 'Publish Gitee Pages':
return Deployment.Gitee
return Deployment.Local
def is_private(self) -> bool:
return not self.is_public()
def is_public(self) -> bool:
return self in [Deployment.Github, Deployment.Gitee]
def is_mirror(self) -> bool:
return self is not Deployment.Github
def url(self) -> str:
if self == Deployment.Github:
return 'https://silverrainz.me/'
elif self == Deployment.Gitee:
return 'https://silverrainz.gitee.io/'
elif self == Deployment.Raspi:
return 'https://rpi3/bullet'
else:
# file:///build_dir/html/index.html
return 'TODO'
D = Deployment.current()
print('Deployment:', D)
# For `.. only::` directive.
if D.is_private():
tags.add('private') # type: ignore
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.graphviz',
'sphinxcontrib.email',
'sphinx.ext.githubpages',
'sphinxnotes.strike',
'sphinxcontrib.plantuml',
'sphinxcontrib.asciinema',
'sphinx_copybutton',
'sphinxcontrib.youtube',
'sphinxnotes.extweb',
'sphinx_last_updated_by_git',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'
language_full = '简体中文'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'README.rst']
# A string of reStructuredText that will be included at the end of every
# source file that is read.
rst_epilog = """
"""
# Provided by sphinxnotes.any
primary_domain = 'any'
# Use :code: as default role, so we can write `content` instead of ``content``.
default_role = 'code'
# Keep warnings as “system message” paragraphs in the built documents.
# Regardless of this setting, warnings are always written to the standard error
# stream when sphinx-build is run.
if D.is_private():
keep_warnings = True
# Auto numbered figures, tables and code-blocks if they have a caption.
# numfig = True
# Show codeauthor and sectionauthor directives produce any output in the built
# files.
show_authors = True
# A URL to cross-reference manpage directives.
manpages_url = 'https://man7.org/linux/man-pages/man{section}/{page}.{section}.html'
# -- Options for HTML output -------------------------------------------------
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_css_files = ['custom.css']
# A list of JavaScript filename.
# The entry must be a filename string or a tuple containing the filename string
# and the attributes dictionary. The filename must be relative to the
# html_static_path, or a full URI with scheme like https://example.org/script.js.
# The attributes is used for attributes of <script> tag. It defaults to an empty list.
html_js_files = []
html_baseurl = D.url()
html_title = project
html_logo = logo
html_favicon = '_static/favicon.png'
# HTML theme configuration
html_theme = 'sphinx_book_theme'
html_theme_options = {
'repository_url': f'https://github.com/{author_id}/bullet',
"use_repository_button": True,
"use_download_button": False,
"show_toc_level": 2,
"navigation_with_keys": False, # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/configuring.html#changing-pages-with-keyboard-presses
}
# Setup announcement as your need
# html_theme_options['announcement'] = '</p>blahblah… </p>
if D.is_mirror():
src = Deployment.Github
msg = f'<p> 这是部署于 {D} 的镜像,访问源站点:<a class="source-page" href="{src.url()}">{src}</a></p>'
if html_theme_options.get('announcement'):
html_theme_options['announcement'] += msg
else:
html_theme_options['announcement'] = msg
html_js_files.append('mirror-redirect.js')
html_css_files.append('sphinx-book-theme-custom.css')
nosidebar_page = ['nosidebar']
blog_post_page = [ # Provided by sphinx_book_theme
'navbar-logo',
# Provided by ABlog
'ablog/postcard', 'ablog/recentposts', 'ablog/tagcloud',
'ablog/categories', 'ablog/archives']
# TODO...
html_sidebars = {
# We have best toc on page content
'about/resume': nosidebar_page,
'about/resume-en': nosidebar_page,
'blog': blog_post_page, # ABlog's "All Posts" page
'blog/**': blog_post_page, # Inlucde posts and autogenerated pages
}
# If true, the reST sources are included in the HTML build as _sources/name.
# I don't want to public my sources, so set it to false.
html_copy_source = True
html_search_language = language
html_last_updated_fmt = datefmt
# A list of paths that contain extra files not directly related to the
# documentation.
html_extra_path = ['robots.txt', 'LICENSE']
# -- Pre extension configuration ---------------------------------------------------
extensions.append('sphinxnotes.mock')
mock_directives = []
mock_directives.append('contents') # Theme has built-in local-toc, see html_theme
extensions.append('sphinx.ext.todo')
todo_include_todos = True
extensions.append('sphinx.ext.extlinks')
extlinks = {
'zhwiki': ('https://zh.wikipedia.org/wiki/%s', '📖 %s'),
'enwiki': ('https://wikipedia.org/wiki/%s', '📖 %s'),
'search': ('https://duckduckgo.com/?q=%s', '🔍 %s'),
'twitter': ('https://twitter.com/%s', '👤 %s'),
'ghuser': ('https://github.com/%s', '👤 %s'),
'ghorg': ('https://github.com/%s', '👥 %s'),
'ghrepo': ('https://github.com/%s', '⛺ %s'),
'weibo': ('https://weibo.com/%s', '👤 %s'),
'aur': ('https://aur.archlinux.org/packages/%s', '📦 %s'),
'archpkg': ('https://archlinux.org/packages/%s', '📦 %s'),
'archwiki': ('https://wiki.archlinux.org/index.php/%s', '📖 %s'),
'zhihua': ('https://www.zhihu.com/answer/%s', '🙋 %s'),
'zhihuq': ('https://www.zhihu.com/question/%s', '🤔 %s'),
'zhihup': ('https://www.zhihu.com/people/%s', '👤 %s'),
'pypi': ('https://pypi.org/project/%s', '📦 %s'),
'lilydoc': ('https://lilypond.org/doc/v2.20/Documentation/%s', None),
'so.q': ('https://stackoverflow.com/a/%s', '🤔 %s'),
'so.a': ('https://stackoverflow.com/a/%s', '🙋 %s'),
'bili': ('https://www.bilibili.com/video/%s', '🎥 %s'),
}
extensions.append('sphinxnotes.any')
from sphinxnotes.any import Schema, Field as F
any_schemas = [
Schema('friend',
name=F(unique=True, referenceable=True, required=True, form=F.Form.LINES),
attrs={'avatar': F(), 'blog': F()},
content=F(form=F.Form.LINES),
description_template=open('_templates/friend.rst', 'r').read(),
reference_template='👤{{ title }}',
missing_reference_template='👤{{ title }}',
ambiguous_reference_template='👥{{ title }}'),
Schema('book',
name=F(required=True, referenceable=True, form=F.Form.LINES),
attrs={
'isbn': F(unique=True, referenceable=True),
'status': F(referenceable=True),
'startat': F(referenceable=True, form=F.Form.WORDS),
'endat': F(referenceable=True, form=F.Form.WORDS),
},
description_template=open('_templates/book.rst', 'r').read(),
reference_template='《{{ title }}》',
missing_reference_template='《{{ title }}》',
ambiguous_reference_template='《{{ title }}》'),
Schema('artwork',
name=F(referenceable=True),
attrs={
'id': F(unique=True, referenceable=True, required=True),
'date': F(referenceable=True),
'medium': F(referenceable=True, form=F.Form.WORDS),
'size': F(referenceable=True),
'image': F(),
'album': F(referenceable=True),
},
description_template=open('_templates/artwork.rst', 'r').read(),
reference_template='《{% if title %}{{ title }}{% else %}{{ id }}{% endif %}》',
missing_reference_template='《{{ title }}》',
ambiguous_reference_template='{{ title }}'),
Schema('artist',
name=F(unique=True, referenceable=True, required=True, form=F.Form.LINES),
attrs={
'movement': F(referenceable=True, form=F.Form.WORDS),
'gallery': F(referenceable=True, form=F.Form.WORDS),
'enwiki': F(),
'zhwiki': F(),
'artwork': F(form=F.Form.WORDS),
},
description_template=open('_templates/artist.rst', 'r').read(),
reference_template='🧑🎨{{ title }}',
missing_reference_template='🧑🎨{{ title }}',
ambiguous_reference_template='🧑🎨{{ title }}'),
Schema('gallery',
name=F(unique=True, referenceable=True, required=True, form=F.Form.LINES),
attrs={'website': F()},
description_template=open('_templates/gallery.rst', 'r').read(),
reference_template='🖼️{{ title }}',
missing_reference_template='🖼️{{ title }}'),
Schema('event',
name=F(referenceable=True, required=True),
attrs={
'date': F(referenceable=True, form=F.Form.LINES),
'location': F(referenceable=True),
},
description_template=open('_templates/event.rst', 'r').read(),
reference_template='📅{{ title }}',
missing_reference_template='📅{{ title }}',
ambiguous_reference_template='📅{{ title }}'),
Schema('leetcode',
name=F(referenceable=True, required=True),
attrs={
'id': F(unique=True, referenceable=True),
'diffculty': F(referenceable=True),
'language': F(referenceable=True, form=F.Form.WORDS),
'key': F(referenceable=True, form=F.Form.WORDS),
'date': F(referenceable=True, form=F.Form.WORDS),
'reference': F(referenceable=True),
},
description_template=open('_templates/leetcode.rst', 'r').read(),
reference_template='🧮{{ title }}',
missing_reference_template='🧮{{ title }}',
ambiguous_reference_template='🧮{{ title }}'),
Schema('term',
name=F(referenceable=True, required=True, form=F.Form.LINES),
attrs={
'field': F(referenceable=True),
'enwiki': F(),
'zhwiki': F(),
},
description_template=open('_templates/term.rst', 'r').read(),
reference_template='#️⃣{{ title }}',
missing_reference_template='#️⃣{{ title }}',
ambiguous_reference_template='#️⃣{{ title }}'),
Schema('jour',
name=F(referenceable=True, required=True),
attrs={
'date': F(),
'category': F(),
},
description_template=open('_templates/jour.rst', 'r').read(),
reference_template='📰{{ title }}',
missing_reference_template='📰{{ title }}',
ambiguous_reference_template='📰{{ title }}'),
Schema('okr',
name=F(referenceable=True, required=True),
attrs={
'id': F(unique=True, referenceable=True, required=True),
'krs': F(form=F.Form.LINES),
'scores': F(form=F.Form.WORDS),
'parent': F(),
},
description_template=open('_templates/okr.rst', 'r').read(),
reference_template='🥅{{ title }}'),
Schema('people',
name=F(unique=True, referenceable=True, required=True),
attrs={
'github': F(),
'blog': F(),
'enwiki': F(),
'zhwiki': F(),
'weibo': F(),
},
description_template=open('_templates/people.rst', 'r').read(),
reference_template='👤{{ title }}'),
Schema('rhythm',
name=F(referenceable=True),
attrs={
'time': F(referenceable=True, required=True),
'tempo': F(),
'grid': F(),
},
content=F(form=F.Form.LINES),
description_template=open('_templates/rhythm.rst', 'r').read(),
reference_template='🥁{{ title }}'),
Schema('dev',
name=F(referenceable=True),
attrs={
'id': F(unique=True, referenceable=True, required=True),
'type': F(referenceable=True, required=True),
'website': F(),
'man': F(),
'startat': F(referenceable=True),
'endat': F(referenceable=True),
},
description_template=open('_templates/dev.rst', 'r').read(),
reference_template='🎛️{{ title }}'),
]
extensions.append('ablog')
blog_path = 'blog'
blog_title = project
blog_baseurl = D.url()
blog_authors = {
author_nick: (author, blog_baseurl),
}
blog_default_author = author_nick
blog_languages = {
language: (language_full, None),
# FIXME: https://github.com/sunpy/ablog/issues/136
# 'en': ('English', None),
}
blog_default_language = language
post_date_format = datefmt
post_auto_image = 1
blog_feed_fulltext = True
blog_feed_subtitle = description
fontawesome_included = True
html_css_files.append('ablog-custom.css')
if D.is_public():
extensions.append('sphinxcontrib.gtagjs')
if D is Deployment.Github:
gtagjs_ids = ['G-FYHS50G6DL']
elif D is Deployment.Gitee:
gtagjs_ids = ['G-5MZDR9VPYN']
if D is Deployment.Local:
extensions.append('sphinxnotes.snippet.ext')
snippet_config = {}
snippet_patterns = {
'd': ['.*'],
's': ['man/.*', 'notes/.*', 'jour/.*', 'collections/.*', 'about/.*'],
'c': ['man/.*'],
}
extensions.append('sphinx_design')
if D.is_public():
extensions.append('sphinxnotes.isso')
isso_url = 'https://comments.silverrainz.me:30500'
from textwrap import dedent
# Require extensions 'sphinx_design'
rst_epilog += dedent("""
.. card:: 评论
如果你有任何意见,请在此评论。
如果你留下了电子邮箱,我可能会通过 :email:`comments@silverrainz.me` 回复你。
.. isso::
""")
if D.is_public():
extensions.append('sphinx_sitemap')
sitemap_filename = "sitemap.xml"
sitemap_url_scheme = "{link}"
# NOTE: required by ablog
extensions.append('sphinx.ext.intersphinx')
if D.is_public():
# Fetech intersphinx info too slow.
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'sphinx': ('https://www.sphinx-doc.org/en/stable/', None),
'srain': ('https://srainapp.github.io/docs', None),
}
# if D.is_public():
if True:
extensions.append('sphinx_reredirects')
# https://documatt.gitlab.io/sphinx-reredirects/usage.html
redirects = {
'notes/6-lectures-on-sketch': '/notes/zxsys/6-lectures-on-sketch.html'
}
# extensions.append('sphinxcontrib.images')
# images_config = {
# 'override_image_directive': True,
# 'cache_path': '_cache',
# 'download': True,
# }
extensions.append('sphinxnotes.lilypond')
lilypond_audio_volume = 300
lilypond_audio_format = 'mp3'
if D is not Deployment.Local:
extensions.append('sphinxnotes.recentupdate')
recentupdate_date_format = datefmt
recentupdate_exclude_path = ['_templates']
recentupdate_exclude_commit = ['skip-recentupdate', 'conf']
else:
mock_directives.append('recentupdate')
if D.is_public():
extensions.append('sphinxext.opengraph')
ogp_site_url = D.url()
ogp_site_name = project
ogp_image = D.url() + logo
if D is not Deployment.Local:
# Doesn't work locally
extensions.append('notfound.extension')
notfound_urls_prefix = ''
extensions.append('sphinxnotes.comboroles')
comboroles_roles = {
'parsed_literal': (['literal'], True),
# for ./blog/sphinxnotes-comboroles.rst
'strong_literal': ['strong', 'literal'],
'literal_enwiki': ['literal', 'enwiki'],
'literal_strike': ['literal', 'strike'],
}