Skip to content

Commit 19a49e3

Browse files
authored
add the ICP number to the footer (#10)
* add the ICP number to the footer * connect new method * bugfix * fix link
1 parent 68f34f4 commit 19a49e3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This package should be used in all sphinx projects under the [@deepmodeling](htt
44

55
## Features
66

7-
- Adding the DeepModeling banner
7+
- Add the DeepModeling banner
8+
- Add the ICP number to the footer
89
- Minify HTML, Javascript, and CSS files
910

1011
## How to use it

deepmodeling_sphinx/inject.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ def render(self, template, render_context):
5959
app.builder.templates)
6060

6161

62+
def insert_icp(app, pagename, templatename, context, doctree):
63+
if (
64+
not hasattr(app.builder.templates.render, '_deepmodeling_icp_patched')
65+
):
66+
old_render = app.builder.templates.render
67+
68+
def render(self, template, render_context):
69+
content = old_render(template, render_context)
70+
comment_begin = r"<!--deepmodeling icp begin-->"
71+
comment_end = r"<!--deepmodeling icp end-->"
72+
if comment_begin in content:
73+
return content
74+
footer = content.lower().find('</footer>')
75+
icp_footer = '<p><a href="https://beian.miit.gov.cn" target="_blank">京ICP备20010051号-8</a></p>'
76+
if footer != -1:
77+
content = content[:footer] + comment_begin + \
78+
icp_footer + comment_end + content[footer:]
79+
return content
80+
81+
render._deepmodeling_icp_patched = True
82+
app.builder.templates.render = types.MethodType(render,
83+
app.builder.templates)
84+
85+
6286
def minify_html_files(app, pagename, templatename, context, doctree):
6387
if (
6488
not hasattr(app.builder.templates.render, '_deepmodeling_minified')
@@ -105,6 +129,7 @@ def minify_css_files(app, exception):
105129
def setup(app: Sphinx) -> Dict[str, Any]:
106130
app.connect('builder-inited', copy_custom_files)
107131
app.connect('html-page-context', insert_sidebar)
132+
app.connect('html-page-context', insert_icp)
108133
app.connect('build-finished', minify_js_files)
109134
app.connect('build-finished', minify_css_files)
110135

0 commit comments

Comments
 (0)