diff --git a/compile.py b/compile.py index 43281a95..011b04c5 100644 --- a/compile.py +++ b/compile.py @@ -21,6 +21,8 @@ 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)') +parser.add_argument('--local-assets-china', dest="local_assets_china", action="store_true", help='Use local JS/Fonts for china (Default: don\'t use)') +parser.add_argument('--use-ext-html', dest='use_ext_html', action="store_true", help="Use .html extension (Default: don\' use)") ########################## Print ########################## @@ -70,20 +72,47 @@ def create_directory(dir): ('sourcecodepro', 'sourcecodepro.woff', 'https://fonts.gstatic.com/s/sourcecodepro/v5/mrl8jkM18OlOQN8JLgasDxM0YzuT7MdOe03otPbuUS0.woff') ] +def href_path_old(*args): + return "/".join(args) + +def href_path_html(*args): + return "/".join(args) + ".html" + +href_path = href_path_old +if args.use_ext_html: + href_path = href_path_html + +if args.local_assets_china: + # For reasons both known and unknown, + # googleapis.com isn't reachable for the people live in china. + # Because of that, to speed up assets downloading, use microsoft cdn instead. + args.local_assets = True + JS_LIBS[0] = ('jquery', 'jquery.min.js', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.11.1.min.js', None) + JS_LIBS[1] = ('jqueryui', 'jquery-ui.min.js', 'https://ajax.aspnetcdn.com/ajax/jquery.ui/1.11.1/jquery-ui.min.js', None) + if args.local_assets: + def local_assets_exists(fn): + if not os.path.exists(fn): + return False + if os.stat(fn).st_size == 0: + return False + return True for name, filename, url, suffix in JS_LIBS: path = 'html/copy/' + filename - if not os.path.exists(path): + if not local_assets_exists(path): dirname = os.path.dirname(path) create_directory(dirname) - url = url + filename + (suffix or '') + if url.endswith("/"): + url = url + filename + (suffix or '') + else: + url = url + (suffix or '') with open(path, 'wb') as f: print("Downloading " + url) f.write(urllib.request.urlopen(url).read()) for name, filename, url in FONTS: path = 'html/copy/' + filename - if not os.path.exists(path): + if not local_assets_exists(path): with open(path, 'wb') as f: print("Downloading " + url) f.write(urllib.request.urlopen(url).read()) @@ -105,13 +134,13 @@ def create_directory(dir): if file == 'Gruntfile.js': continue f.append(dirpath + "/" + file) - + for directory in d: create_directory(output_dir + directory) for file in f: shutil.copy("html/copy/" + file, output_dir + file) - + print("Copied " + str(len(f)) + " files") print("Reading templates...") @@ -173,6 +202,14 @@ def replace_js(markup, prefix): style_fp.write(style) style_fp.close() +######################## replace about.html jquery links ########################## + +with open(output_dir + "about.html", "r", encoding='utf-8') as about_f: + about = about_f.read() +about = replace_js(about, prefix="./") +with open(output_dir + "about.html", "w", encoding='utf-8') as about_f: + about_f.write(about) + ######################## Get Versions for Index.html ########################## #OpenGL @@ -247,7 +284,7 @@ def replace_js(markup, prefix): alias = aliases[version] if version in all_major_versions_available: - index_versions_commands += "" + version + "" + index_versions_commands += "" + version + "" else: index_versions_commands += "" + version + "" index_versions_commands += "\n" @@ -316,12 +353,13 @@ def replace_js(markup, prefix): if version in aliases: alias = aliases[version] - + if version in all_major_versions_available: + href = href_path(version, alias) if version[0:2] == "sl": - glsl_index_versions_commands += "glsl" + version[2:3] + "" + glsl_index_versions_commands += "glsl" + version[2:3] + "" else: - glsl_index_versions_commands += "glsl-es" + version[2:3] + "" + glsl_index_versions_commands += "glsl-es" + version[2:3] + "" else: if version[0:2] == "sl": glsl_index_versions_commands += "glsl" + version[2:3] + "" @@ -535,6 +573,7 @@ def replace_js(markup, prefix): search_versions_options += "" +header = header.replace("{$use_ext_html}", "true" if args.use_ext_html else "false") header = header.replace("{$search_versions}", search_versions_options) unhandled_commands = list(opengl.commands_version_flat.keys()) @@ -617,7 +656,7 @@ def spew_category(name, commands, current_command, api): major_versions += glsl_major_versions -major_versions.sort() +major_versions.sort() ######################## Where Everything comes together ########################## @@ -631,10 +670,10 @@ def spew_category(name, commands, current_command, api): written = 0 print("Compiling " + version + " ..." ) - header_for_version = header; - footer_for_version = footer; + header_for_version = header + footer_for_version = footer - all_versions = []; + all_versions = [] all_versions = list(opengl.version_commands.keys()) glsl_all_versions = list(glsl.version_commands.keys()) @@ -779,11 +818,12 @@ def spew_category(name, commands, current_command, api): if API_type == "gl": API="OpenGL" - command_versions += ""+API+" " + es + major_version[2] + "
" - + href = href_path(major_version, command) + command_versions += "" + API + " " + es + major_version[2] + "
" + header_for_command = header_for_command.replace("{$command_versions}", command_versions) header_for_command = header_for_command.replace("{$command}", command) - + editlink = "https://github.com/BSVino/docs.gl/blob/mainline/" + version + "/" + command + ".xhtml" improvepage = "Think you can improve this page? Edit this page on GitHub." footer_for_command = footer_for_command.replace("{$improvepage}", improvepage) @@ -942,7 +982,7 @@ def replace_alias(matchobj): output_html = header_for_command + command_html + footer_for_command - output_path = output_dir + version_dir + "/" + command + output_path = output_dir + version_dir + "/" + href_path(command) with codecs.open(output_path, mode="w", encoding="utf-8") as output: output_string = output_html if args.buildmode == 'full': @@ -988,7 +1028,7 @@ def replace_alias(matchobj): output_html = header_for_page + notfound_html + footer_for_page - output = open(output_dir + version + "/404", "w") + output = open(output_dir + version + "/" + href_path("404"), "w") output_string = output_html if args.buildmode == 'full': output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace').decode('ascii') diff --git a/html/copy/about.html b/html/copy/about.html index 59e478f0..c5475037 100644 --- a/html/copy/about.html +++ b/html/copy/about.html @@ -4,7 +4,7 @@ About docs.gl - +{$jquery} diff --git a/html/copy/docs.gl.js b/html/copy/docs.gl.js index f4bc7761..63458a80 100644 --- a/html/copy/docs.gl.js +++ b/html/copy/docs.gl.js @@ -65,6 +65,27 @@ window.api_version = ""; window.hide_deprecated = false; window.last_hide_deprecated = false; +function url_parts_join() +{ + let a = []; + for (let i = 0; i < arguments.length; ++i) { + a.push(arguments[i]); + } + return a.join("/"); +} + +function url_parts_join_ext_html() +{ + let a = []; + for (let i = 0; i < arguments.length; ++i) { + a.push(arguments[i]); + } + let first = a.join("/"); + return first + ".html" +} + +const href_path = window.use_ext_html ? url_parts_join_ext_html : url_parts_join; + function set_api_version(version) { window.api_version = version; $.cookie("api_version", version, {path: '/'}); @@ -78,7 +99,7 @@ function set_api_version(version) { version_directory = version.substring(0, 3); $(".rewritelink").each(function() { if ($(this).hasClass(version)) - $(this).attr("href", "../" + version_directory + "/" + $(this).text()); + $(this).attr("href", href_path("..", version_directory , $(this).text())); else { highest = 0; @@ -121,7 +142,7 @@ function set_api_version(version) { } } - $(this).attr("href", "../" + version.substring(0, 2) + highest + "/" + $(this).text()); + $(this).attr("href", href_path("..", version.substring(0, 2) + highest, $(this).text())); } }); @@ -207,6 +228,38 @@ $(function() { $("#versions_dropdown").val(window.current_api).selectmenu('refresh'); } + if (window.use_ext_html) + { + // FIXME: should we normalize the a which is referring to a command + // in *.xhtml files? + // e.g.: add class `citerefentry`? + + function is_relative(href) { + if (!href) return false; + if (href.startsWith("#")) return false; + if (href.startsWith("http:") || href.startsWith("https:")) return false; + return true; + } + + $("a[href*='gl']").each(function() { + let href = $(this).attr("href"); + + // skip rewritelink + if ($(this).hasClass("rewritelink")) return; + + // skip non relative href + if (!is_relative(href)) return; + + // this href is ok + if (href.endsWith(".html")) return; + + let fixed_href = href + ".html"; + + console.warn(`fix href from \`${href}\` to \`${fixed_href}\` of element:`, $(this)[0]); + $(this).attr("href", fixed_href); + }); + } + $("#style_light").click(function() { $("#pagestyle").attr("href", "../style_light.css"); $.cookie("pagestyle", "light", {path: '/'}); @@ -249,15 +302,14 @@ $(function() { if (alias in function_aliases[alias_api]) command_page = function_aliases[alias_api][alias] - window.location.href = window.base_directory + directory + command_page; + window.location.href = window.base_directory + directory + href_path(command_page); return true; } - - + function hide_tooltip (){ $("#search").trigger('mouseout'); } - + $( "#search_button" ).button().click(function(event) { if ( search_fn($("#search").val()) == false){ @@ -278,7 +330,7 @@ $(function() { } }); - + $( "#search" ).autocomplete({ source: search_versions["all"], minLength: 3, diff --git a/html/header.html b/html/header.html index 90c0bd95..9b047376 100644 --- a/html/header.html +++ b/html/header.html @@ -20,6 +20,7 @@ @@ -30,7 +31,7 @@
Light | Dark
-

docs.GL

+

docs.GL