mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
./mkdocs.py -p opens a preview in your default browser. Tested on Mac, but should work on windows and Linux as well.
This commit is contained in:
parent
3b258d69c9
commit
cba181f4bc
13
mkdocs.py
13
mkdocs.py
|
@ -11,6 +11,7 @@ docs_dir = os.path.join(root_dir, 'docs')
|
||||||
html_dir = os.path.join(root_dir, 'html')
|
html_dir = os.path.join(root_dir, 'html')
|
||||||
|
|
||||||
local = not '--deploy' in sys.argv
|
local = not '--deploy' in sys.argv
|
||||||
|
preview = '-p' in sys.argv
|
||||||
|
|
||||||
if local:
|
if local:
|
||||||
base_url = 'file://%s/' % os.path.normpath(os.path.join(os.getcwd(), html_dir))
|
base_url = 'file://%s/' % os.path.normpath(os.path.join(os.getcwd(), html_dir))
|
||||||
|
@ -80,3 +81,15 @@ for (dirpath, dirnames, filenames) in os.walk(docs_dir):
|
||||||
output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)
|
output = re.sub(r'<pre>', r'<pre class="prettyprint lang-py">', output)
|
||||||
output = re.sub(r'<a class="github" href="([^"]*)"></a>', code_label, output)
|
output = re.sub(r'<a class="github" href="([^"]*)"></a>', code_label, output)
|
||||||
open(output_path, 'w').write(output.encode('utf-8'))
|
open(output_path, 'w').write(output.encode('utf-8'))
|
||||||
|
|
||||||
|
if preview:
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
url = 'html/index.html'
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.Popen(["open", url]) # Mac
|
||||||
|
except OSError:
|
||||||
|
subprocess.Popen(["xdg-open", url]) # Linux
|
||||||
|
except:
|
||||||
|
os.startfile(url) # Windows
|
||||||
|
|
Loading…
Reference in New Issue
Block a user