-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathpropagate_docs.py
More file actions
74 lines (59 loc) · 1.92 KB
/
Copy pathpropagate_docs.py
File metadata and controls
74 lines (59 loc) · 1.92 KB
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
import os
import re
import subprocess
import sys
import mistune
CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
""" This script overrides the README with parts contained in the docs :
index.md => Intro, Why, Main Features
get-started => Get Started
"""
res = subprocess.check_output(["git", "branch"])
if "* master" not in res:
print "you have to be on master to run this !"
sys.exit(1)
def get_path(filename):
return os.path.join(CURRENT_DIRECTORY, "..", "docs", "%s.md" % filename)
readme_path = os.path.join(CURRENT_DIRECTORY, "..", "README.md")
with open(readme_path, 'r') as readme_file:
readme = readme_file.read()
for filename, title_begin, title_end in (
("index", "MRQ", "Dashboard Screenshots"),
("get-started", "Get Started", "More"),
):
with open(get_path(filename), 'r') as f:
raw = f.read()
# remove first 2 lines
cropped = "\n".join(raw.split("\n")[2:])
readme = re.sub(
"(# %s\n\n)(.*)(\n\n^# %s)" % (title_begin, title_end),
r"\1%s\3" % cropped,
readme,
flags=re.MULTILINE | re.DOTALL
)
with open(readme_path, 'w') as readme_file:
readme_file.write(readme)
subprocess.call(["git", "add", "-p", "README.md"])
subprocess.call(["git", "commit"])
# II. index.html
raw = ""
for filename in ["index", "dashboard", "get-started"]:
with open(get_path(filename), 'r') as f:
raw += f.read()
raw += "\n\n"
subprocess.call(["git", "checkout", "gh-pages"])
html = mistune.markdown(raw)
index_path = os.path.join("index.html")
with open(index_path, 'r') as index_file:
index = index_file.read()
index = re.sub(
r"(<div class=\"row marketing\">)(.*)(</div><!-- row marketing -->)",
r"\1%s\3" % html,
index,
flags=re.MULTILINE | re.DOTALL
)
with open(index_path, 'w') as index_file:
index_file.write(index)
subprocess.call(["git", "add", "-p", "index.html"])
subprocess.call(["git", "commit"])
# subprocess.call(["git", "checkout", "master"])