From 44f0a418d6893431504759f2a14632513ba76fd9 Mon Sep 17 00:00:00 2001 From: TRMSC Date: Sun, 5 Nov 2023 22:52:26 +0100 Subject: [PATCH] build path correctly for github & server, close #9 --- docs/src/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/src/script.js b/docs/src/script.js index 137918a..1f19d85 100644 --- a/docs/src/script.js +++ b/docs/src/script.js @@ -273,8 +273,13 @@ generateScene = () => { // Get template let templateName = document.getElementById('imagescene-template').value; - //let templatePath = '../templates/' + templateName + '.raw'; - let templatePath = 'https://raw.githubusercontent.com/TRMSC/imagescene-generator/main/templates/' + templateName + '.raw'; + + // Build path + const baseUrl = new URL(window.location.href); + let relativePath = '../templates/' + templateName + '.raw'; + let absolutePath = new URL(relativePath, baseUrl).href; + let templatePath = absolutePath.includes('github') ? absolutePath.replace('/blob/', '/raw/') : relativePath; + console.log('path is ' + templatePath); // Fetch template content let templateContent = '';