diff --git a/build.py b/build.py index 05017116..8d64942b 100755 --- a/build.py +++ b/build.py @@ -8,7 +8,14 @@ import base64 import sys import os import shutil +import json +import shelve +import hashlib +try: + import urllib2 +except ImportError: + import urllib.request as urllib2 # load settings file from buildsettings import buildSettings @@ -66,6 +73,33 @@ def loaderRaw(var): fn = var.group(1) return readfile(fn) +def loaderMD(var): + fn = var.group(1) + # use different MD.dat's for python 2 vs 3 incase user switches versions, as they are not compatible + db = shelve.open('build/MDv' + str(sys.version_info.major) + '.dat') + if 'files' in db: + files = db['files'] + else: + files = {} + file = readfile(fn) + filemd5 = hashlib.md5(file.encode('utf8')).hexdigest() + # check if file has already been parsed by the github api + if fn in files and filemd5 in files[fn]: + # use the stored copy if nothing has changed to avoid hiting the api more then the 60/hour when not signed in + db.close() + return files[fn][filemd5] + else: + url = 'https://api.github.com/markdown' + payload = {'text': file, 'mode': 'markdown'} + headers = {'Content-Type': 'application/json'} + req = urllib2.Request(url, json.dumps(payload).encode('utf8'), headers) + md = urllib2.urlopen(req).read().decode('utf8').replace('\n', '').replace('\'', '\\\'') + files[fn] = {} + files[fn][filemd5] = md + db['files'] = files + db.close() + return md + def loaderImage(var): fn = var.group(1) return 'data:image/png;base64,{0}'.format(base64.encodestring(open(fn, 'rb').read()).decode('utf8').replace('\n', '')) @@ -86,6 +120,7 @@ def doReplacements(script,updateUrl,downloadUrl): script = re.sub('@@INCLUDERAW:([0-9a-zA-Z_./-]+)@@', loaderRaw, script) script = re.sub('@@INCLUDESTRING:([0-9a-zA-Z_./-]+)@@', loaderString, script) + script = re.sub('@@INCLUDEMD:([0-9a-zA-Z_./-]+)@@', loaderMD, script) script = re.sub('@@INCLUDEIMAGE:([0-9a-zA-Z_./-]+)@@', loaderImage, script) script = script.replace('@@BUILDDATE@@', buildDate) diff --git a/code/utils_misc.js b/code/utils_misc.js index 84562c92..4d12fcd9 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -1,7 +1,8 @@ // UTILS + MISC /////////////////////////////////////////////////////// window.aboutIITC = function(){ - var v = '@@BUILDNAME@@-@@BUILDDATE@@' + var v = '@@BUILDNAME@@-@@BUILDDATE@@'; + var attrib = '@@INCLUDEMD:ATTRIBUTION.md@@'; var a = '' + '
About IITC
' + '
Ingress Intel Total Conversion
' @@ -20,8 +21,11 @@ window.aboutIITC = function(){ + ' MapQuest OSM tiles Courtesy of MapQuest ' + ' ' + '
' - + '
Version: ' + v + '
'; - alert(a); + + '
Version: ' + v + '
' + + '
' + + '
' + attrib + '
'; + alert(a, true, function() {$('.ui-dialog').removeClass('ui-dialog-aboutIITC');}); + $('.ui-dialog').addClass('ui-dialog-aboutIITC'); } diff --git a/style.css b/style.css index d8f6743b..5ebfdb69 100644 --- a/style.css +++ b/style.css @@ -766,6 +766,11 @@ h3 { text-decoration: underline; } +.ui-dialog-aboutIITC { + max-width: 600px !important; + width: 600px !important; +} + td { padding: 0; vertical-align: top;