forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostprocess_docs.py
42 lines (35 loc) · 1.71 KB
/
postprocess_docs.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
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
NEEDLE1 = '<a href="#" class="icon icon-home"> ParlAI'
NEEDLE2 = '<a href="index.html" class="icon icon-home"> ParlAI'
REPLACEMENT = """
<a href="/" style="float: left">
<img style="padding: 0px; background-color: #fff; width: 53px; height: 53px; margin-left: 70px;" src="/static/img/icon.png">
</a>
<a href="/" style="color: #000; float: left; margin-top: 12px; font-size: 20px; font-weight: 600">
ParlAI
</a>
""" # noqa: E501
NEEDLE3 = '<title>ParlAI Documentation — ParlAI documentation</title>'
REPLACEMENT3 = """
<title>ParlAI Documentation — ParlAI documentation</title>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-32x32.png" sizes="32x32"/>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-16x16.png" sizes="16x16"/>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-96x96.png" sizes="96x96"/>
""" # noqa: E501
if __name__ == '__main__':
for root, _, files in os.walk("build/docs/"):
for file in files:
if file.endswith(".html"):
file_path = os.path.join(root, file)
print("Postprocessing ", file_path)
with open(file_path, 'r') as fin:
content = fin.read()
content = content.replace(NEEDLE1, REPLACEMENT)
content = content.replace(NEEDLE2, REPLACEMENT)
content = content.replace(NEEDLE3, REPLACEMENT3)
with open(file_path, 'w') as fout:
fout.write(content)