From 2b6099dff9f6890e3c6b7f534b85be0ffbfaa107 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 25 Nov 2020 01:52:53 +0100 Subject: [PATCH] Deploy --- .github/workflows/config.patch | 4 ++-- config.toml | 2 +- static/js/PubliData.js | 5 +++-- static/js/data.js | 3 ++- static/js/getFullDataPath.js | 3 ++- static/js/getTextFromFile.js | 3 ++- static/js/indexDB.js | 5 +++-- tools/generate_data.py | 13 ++++++++++++- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/config.patch b/.github/workflows/config.patch index d9888591..58b0860c 100644 --- a/.github/workflows/config.patch +++ b/.github/workflows/config.patch @@ -3,9 +3,9 @@ index 88ba656e..5d97890c 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,5 @@ --baseURL = "/" +-baseURL = "http://localhost:1313/QUESTDB_website/" -#baseURL = "https://lcpq.github.io/QUESTDB_website/" -+#baseURL = "/" ++#baseURL = "http://localhost:1313/QUESTDB_website/" +baseURL = "https://lcpq.github.io/QUESTDB_website/" canonifyurls = true diff --git a/config.toml b/config.toml index 2390395d..32cb78db 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ -baseURL = "/" +baseURL = "http://localhost:1313/QUESTDB_website/" #baseURL = "https://lcpq.github.io/QUESTDB_website/" canonifyurls = true diff --git a/static/js/PubliData.js b/static/js/PubliData.js index f5f8b285..03f75fcd 100644 --- a/static/js/PubliData.js +++ b/static/js/PubliData.js @@ -28,7 +28,8 @@ class PubliData{ } static GetPathForDOI(DOI){ - return `/data/publis/${DOI.replaceAll(".","/")}` + var site_url = window.location.origin; + return site_url + `/data/publis/${DOI.replaceAll(".","/")}` } static GetAbstractURLForDOI(DOI){ return `${PubliData.GetPathForDOI(DOI)}/abstract.html` @@ -41,4 +42,4 @@ class PubliData{ static async getAbstractTexForDOIAsync(DOI){ return await getTextFromFileUrlAsync(PubliData.GetAbstractURLForDOI(DOI)) } -} \ No newline at end of file +} diff --git a/static/js/data.js b/static/js/data.js index 19a87c6c..3146c28c 100644 --- a/static/js/data.js +++ b/static/js/data.js @@ -232,8 +232,9 @@ class dataFileBase { return /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/; } async getGeometryAsync(state = null) { + var site_url = "/"+window.location.pathname.split('/')[1]; // var text = await getTextFromFileUrlAsync(`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`) - var text = getTextFromFileUrl(`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`) + var text = getTextFromFileUrl(site_url+`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`) var lines = text.split("\n") var indexes = lines.findAllIndexes((line) => { return line.match(/^\d+$/) diff --git a/static/js/getFullDataPath.js b/static/js/getFullDataPath.js index ecb45a4e..e96c25b4 100644 --- a/static/js/getFullDataPath.js +++ b/static/js/getFullDataPath.js @@ -1,3 +1,4 @@ function getFullDataPath(path) { - return '/data/' + path; + var site_url = "/"+window.location.pathname.split('/')[1]; + return site_url+'/data/' + path; } diff --git a/static/js/getTextFromFile.js b/static/js/getTextFromFile.js index 447d7148..6c6850ef 100644 --- a/static/js/getTextFromFile.js +++ b/static/js/getTextFromFile.js @@ -1,5 +1,6 @@ var fileCache = function () { - var json_url = "/data/database.json"; + var site_url = "/"+window.location.pathname.split('/')[1]; + var json_url = site_url+"/data/database.json"; var req = new XMLHttpRequest(); req.open("GET",json_url, false); req.send(); diff --git a/static/js/indexDB.js b/static/js/indexDB.js index f5d3bb88..fa97363d 100644 --- a/static/js/indexDB.js +++ b/static/js/indexDB.js @@ -5,11 +5,12 @@ class indexDB { } var db = new indexDB const maxAge= (DebugMode.Enabled,0,600) - const text = await getTextFromFileUrlAsync("/data/index.yaml",{"Cache-Control":`max-age=${maxAge}`}) + var site_url = "/"+window.location.pathname.split('/')[1]; + const text = await getTextFromFileUrlAsync(site_url+"/data/index.yaml",{"Cache-Control":`max-age=${maxAge}`}) const myYaml = jsyaml.load(text); db.sets = ((myYaml.sets === null) ? new Map() : new Map(Object.entries(myYaml.sets))); db.others = ((myYaml.others === null) ? [] : Array.from(myYaml.others)); window.indexDB=db return db } -} \ No newline at end of file +} diff --git a/tools/generate_data.py b/tools/generate_data.py index cd29320e..c905d636 100755 --- a/tools/generate_data.py +++ b/tools/generate_data.py @@ -5,8 +5,19 @@ import os.path import json + def main(): + baseURL = "/" + with open("config.toml","r") as f: + for line in f.readlines(): + if line.startswith("baseURL"): + baseURL = line.split('=')[1].strip()[1:-1] + break + if baseURL.startswith("http"): + baseURL = '/'+baseURL.split('/')[3]+'/' + print (baseURL) + d = {} os.chdir("static") try: @@ -18,7 +29,7 @@ def main(): filename = os.path.join(root,name) with open(filename,'r',encoding="utf8") as f: try: - d["/"+filename] = f.read() + d[baseURL+filename] = f.read() except UnicodeDecodeError: pass