mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 09:36:59 +00:00
[Build_CDN] Generate CDN prefix URL based on Git tag
This commit is contained in:
@@ -85,4 +85,14 @@ const __FlashStringHelper * get_board_name() {
|
||||
#else
|
||||
return F("");
|
||||
#endif
|
||||
}
|
||||
|
||||
const __FlashStringHelper * get_CDN_url_prefix() {
|
||||
#ifdef CUSTOM_BUILD_CDN_URL
|
||||
return F(CUSTOM_BUILD_CDN_URL);
|
||||
#elif defined(SET_BUILD_CDN_URL)
|
||||
return F(SET_BUILD_CDN_URL);
|
||||
#else
|
||||
return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/");
|
||||
#endif
|
||||
}
|
||||
@@ -14,6 +14,7 @@ const __FlashStringHelper * get_build_origin();
|
||||
const __FlashStringHelper * get_build_platform();
|
||||
const __FlashStringHelper * get_git_head();
|
||||
const __FlashStringHelper * get_board_name();
|
||||
const __FlashStringHelper * get_CDN_url_prefix();
|
||||
|
||||
|
||||
#endif // CUSTOMBUILD_COMPILETIMEDEFINES_H
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "../Static/WebStaticData.h"
|
||||
|
||||
#include "../CustomBuild/CompiletimeDefines.h"
|
||||
#include "../Globals/Cache.h"
|
||||
#include "../Helpers/ESPEasy_Storage.h"
|
||||
#include "../WebServer/HTML_wrappers.h"
|
||||
@@ -8,7 +9,7 @@
|
||||
String generate_external_URL(const String& fname) {
|
||||
String url;
|
||||
url.reserve(80 + fname.length());
|
||||
url = F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20211224/static/");
|
||||
url = get_CDN_url_prefix();
|
||||
url += fname;
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -428,10 +428,10 @@ void getWebPageTemplateDefaultHead(WebTemplateParser& parser, bool addMeta, bool
|
||||
if (parser.isTail()) return;
|
||||
parser.process(F("<!DOCTYPE html><html lang='en'>"
|
||||
"<head>"
|
||||
"<link rel='stylesheet' href='codemirror.min.css'>"
|
||||
"<script src='codemirror.min.js'></script>"
|
||||
"<script src='espeasy.min.js'></script>"
|
||||
"<script src='cm-plugins.min.js' id='anyword'></script>"
|
||||
"<link rel='stylesheet' href='https://cdn.jsdelivr.net/gh/chromoxdor/EasyColorCode/codemirror.min.css'>"
|
||||
"<script src='https://cdn.jsdelivr.net/gh/chromoxdor/EasyColorCode/codemirror.min.js'></script>"
|
||||
"<script src='https://cdn.jsdelivr.net/gh/chromoxdor/EasyColorCode/espeasy.min.js'></script>"
|
||||
"<script src='https://cdn.jsdelivr.net/gh/chromoxdor/EasyColorCode/cm-plugins.min.js' id='anyword'></script>"
|
||||
"<meta charset='utf-8'/>"
|
||||
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
|
||||
"<title>{{name}}</title>"));
|
||||
|
||||
@@ -24,6 +24,21 @@ def get_board_name():
|
||||
return env.BoardConfig().get("name").replace('"', "")
|
||||
|
||||
|
||||
def get_cdn_url_prefix():
|
||||
try:
|
||||
from pygit2 import Repository
|
||||
import re
|
||||
try:
|
||||
regex = re.compile('^/tags/mega-{0}'.format(date.today().strftime("%Y%m%d")))
|
||||
repo = Repository('.')
|
||||
tag_today = [r for r in repo.references if regex.match(restr)][0]
|
||||
return "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@{0}/static/".format(tag_today)
|
||||
except:
|
||||
return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/'
|
||||
except ImportError:
|
||||
return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/'
|
||||
|
||||
|
||||
def get_git_description():
|
||||
try:
|
||||
from pygit2 import Repository
|
||||
@@ -67,6 +82,7 @@ def gen_compiletime_defines(node):
|
||||
+ [("SET_BOARD_NAME", '\\"%s\\"' % get_board_name())]
|
||||
+ [("SET_BUILD_PLATFORM", '\\"%s\\"' % platform.platform())]
|
||||
+ [("SET_BUILD_GIT_HEAD", '\\"%s\\"' % get_git_description())]
|
||||
+ [("SET_BUILD_CDN_URL", '\\"%s\\"' % get_cdn_url_prefix())]
|
||||
+ [("SET_BUILD_VERSION", compute_version_date())],
|
||||
CCFLAGS=env["CCFLAGS"]
|
||||
)
|
||||
@@ -80,6 +96,7 @@ print("\u001b[33m PROGNAME: \u001b[0m {}".format(env['PROGNAME']))
|
||||
print("\u001b[33m BOARD_NAME: \u001b[0m {}".format(get_board_name()))
|
||||
print("\u001b[33m BUILD_PLATFORM: \u001b[0m {}".format(platform.platform()))
|
||||
print("\u001b[33m GIT_HEAD: \u001b[0m {}".format(get_git_description()))
|
||||
print("\u001b[33m CDN_URL: \u001b[0m {}".format(get_cdn_url_prefix()))
|
||||
print("\u001b[33m BUILD_VERSION: \u001b[0m {}".format(compute_version_date()))
|
||||
|
||||
print("\u001b[32m ------------------------------- \u001b[0m")
|
||||
|
||||
Reference in New Issue
Block a user