Skip to content

Commit

Permalink
Merge pull request BSVino#71 from cyclopsian/local-assets
Browse files Browse the repository at this point in the history
Support local copies of all remote assets
  • Loading branch information
BSVino authored Aug 3, 2019
2 parents 1f50148 + 54da8dc commit 439e7fd
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
/*.pyc
/html/copy/jquery-ui.min.js
/html/copy/jquery.min.js
/html/copy/MathJax.js
/html/copy/config
/html/copy/jax
/html/copy/*.woff
.DS_Store
81 changes: 69 additions & 12 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import shared_glsl
import subprocess
import platform
import urllib2

########################## Command Line Arguments ##########################

parser = argparse.ArgumentParser(description="Compile OpenGL documentation, generate a static webpage.")

parser.add_argument('--full', dest='buildmode', action='store_const', const='full', default='fast', help='Full build (Default: fast build)')
parser.add_argument('--local-assets', dest='local_assets', action='store_true', help='Use local JS/Fonts (Default: don\'t use)')

########################## Print ##########################

Expand Down Expand Up @@ -51,6 +53,40 @@ def create_directory(dir):
except:
pass # It gives an error sometimes. If it didn't work try again.

########################## Fetch Remote Assets ##########################

JS_LIBS = [
('jquery', 'jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/', None),
('jqueryui', 'jquery-ui.min.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/', None),
('mathjax', 'MathJax.js', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/', '?config=MML_HTMLorMML'),
(None, 'config/MML_HTMLorMML.js', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/', '?V=2.7.5'),
(None, 'jax/output/HTML-CSS/jax.js', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/', '?V=2.7.5'),
(None, 'jax/output/HTML-CSS/fonts/TeX/fontdata.js', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/', '?V=2.7.5')
]

FONTS = [
('roboto', 'roboto.woff', 'https://fonts.gstatic.com/s/roboto/v13/2UX7WLTfW3W8TclTUvlFyQ.woff'),
('sourcecodepro', 'sourcecodepro.woff', 'https://fonts.gstatic.com/s/sourcecodepro/v5/mrl8jkM18OlOQN8JLgasDxM0YzuT7MdOe03otPbuUS0.woff')
]

if args.local_assets:
for name, filename, url, suffix in JS_LIBS:
path = 'html/copy/' + filename
if not os.path.exists(path):
dirname = os.path.dirname(path)
create_directory(dirname)
url = url + filename + suffix
with open(path, 'w') as f:
print "Downloading " + url
f.write(urllib2.urlopen(url).read())

for name, filename, url in FONTS:
path = 'html/copy/' + filename
if not os.path.exists(path):
with open(path, 'wb') as f:
print "Downloading " + url
f.write(urllib2.urlopen(url).read())

#################### Copy "html/copy" Files To Output Directory ####################

f = []
Expand All @@ -63,7 +99,7 @@ def create_directory(dir):

d.append(dirpath)
for file in filenames:
if file[-3:] != '.js' and file[-4:] != '.css' and file[-4:] != '.png' and file[-5:] != '.html':
if file[-3:] != '.js' and file[-4:] != '.css' and file[-4:] != '.png' and file[-5:] != '.html' and file[-5:] != '.woff':
continue
if file == 'Gruntfile.js':
continue
Expand Down Expand Up @@ -102,18 +138,39 @@ def create_directory(dir):
index_fp = open(index_path)
index = index_fp.read()
index_fp.close()
print "Done."

if os.path.exists('html/copy/jquery.min.js'):
index = index.replace("{$jquery}", "<script src='jquery.min.js'></script>")
else:
index = index.replace("{$jquery}", "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>")

if os.path.exists('html/copy/jquery-ui.min.js'):
index = index.replace("{$jqueryui}", "<script src='jquery-ui.min.js'></script>")
else:
index = index.replace("{$jqueryui}", '<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>')

def replace_js(markup, prefix):
for name, filename, url, suffix in JS_LIBS:
if name:
template = "{$" + name + "}"
if args.local_assets:
url = prefix + filename
else:
url = url + filename
if suffix:
url = url + suffix
tag = "<script src='" + url + "'></script>"
markup = markup.replace(template, tag)
return markup

index = replace_js(index, prefix="./")
header = replace_js(header, prefix="../")

######################## Write Style.css ##########################

style_fp = open("html/style.css")
style = style_fp.read()
style_fp.close()

for name, filename, url in FONTS:
template = "{$" + name + "}"
if args.local_assets:
url = "./" + filename
style = style.replace(template, url)

style_fp = open(output_dir + "/style.css", "w")
style_fp.write(style)
style_fp.close()

######################## Get Versions for Index.html ##########################

Expand Down
6 changes: 3 additions & 3 deletions html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<title>{$command} - {$api_name} {$command_major_version} - docs.gl</title>

<link rel="shortcut icon" href="/favicon.ico" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
{$jquery}
<link rel="stylesheet" href="../jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
{$jqueryui}
<script src="../jquery-bonsai/jquery.bonsai.js"></script>
<link href="../jquery-bonsai/jquery.bonsai.css" rel="stylesheet" type="text/css" />
<script src="../jquery-cookie/jquery.cookie.js"></script>

<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML"></script>
{$mathjax}

<link href="../style.css" rel="stylesheet" type="text/css" />
<link id="pagestyle" href="../style_light.css" rel="stylesheet" type="text/css" />
Expand Down
4 changes: 2 additions & 2 deletions html/copy/style.css → html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ table {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src: local('Roboto Regular'), local('Roboto-Regular'), url(http://fonts.gstatic.com/s/roboto/v13/2UX7WLTfW3W8TclTUvlFyQ.woff) format('woff');
src: local('Roboto Regular'), local('Roboto-Regular'), url({$roboto}) format('woff');
}

@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
src: local('Source Code Pro'), local('SourceCodePro-Regular'), url(http://fonts.gstatic.com/s/sourcecodepro/v5/mrl8jkM18OlOQN8JLgasDxM0YzuT7MdOe03otPbuUS0.woff) format('woff');
src: local('Source Code Pro'), local('SourceCodePro-Regular'), url({$sourcecodepro}) format('woff');
}

body {
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ HTML minification and Unicode processing as well. It looks like this:

python compile.py --full

If you want to build a copy that can be used offline, then you can use the `--local-assets`
parameter which downloads the fonts and Javascript libraries. It then builds the HTML and CSS
using the local copies. It looks like this:

python compile.py --local-assets

If you are running Windows, there are a build.bat and a build_full.bat for convenience. When
the script is done building, the completed site will be in a folder named `htdocs`.

Expand Down

0 comments on commit 439e7fd

Please sign in to comment.