Merge pull request #2512 from element-hq/feature/bma/fixHtml

Fix GitHub page rendering
This commit is contained in:
Benoit Marty 2024-03-08 12:20:38 +01:00 committed by GitHub
commit 04c2c68db5
4 changed files with 1016 additions and 985 deletions

View file

@ -28,6 +28,8 @@ jobs:
- name: Run World screenshots generation script - name: Run World screenshots generation script
run: | run: |
./tools/test/generateWorldScreenshots.py ./tools/test/generateWorldScreenshots.py
mkdir -p screenshots/en
cp tests/uitests/src/test/snapshots/images/* screenshots/en
- name: Deploy GitHub Pages - name: Deploy GitHub Pages
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:

File diff suppressed because it is too large Load diff

View file

@ -15,8 +15,18 @@
*/ */
import { screenshots } from './data.js'; import { screenshots } from './data.js';
// Get the base url of the current page
const baseUrl = window.location.href.split('/').slice(0, -1).join('/');
// On localhost, get the English screenshots from the location `../tests/uitests/src/test/snapshots/images`
const isLocalHost = window.location.hostname === "localhost"
let englishBasePath
if (isLocalHost) {
englishBasePath = `../tests/uitests/src/test/snapshots/images`
} else {
englishBasePath = `en`
}
const dataLanguages = screenshots[0]; const dataLanguages = screenshots[0];
const dataPaths = screenshots[1];
// Read default visible languages from the fragment // Read default visible languages from the fragment
const fragment = new URLSearchParams(window.location.hash.substring(1)); const fragment = new URLSearchParams(window.location.hash.substring(1));
@ -100,6 +110,23 @@ function getNiceName(name) {
return name.substring(indices[2] + 1, indices[3]); return name.substring(indices[2] + 1, indices[3]);
} }
function createMissingImageElement() {
const text = document.createElement('p');
text.className = "missing";
text.textContent = 'No image';
return text;
}
function createImageElement(fullFile) {
const img = document.createElement('img');
img.className = "screenshot";
img.src = `${baseUrl}/${fullFile}`;
img.title = fullFile;
img.alt = "Missing image";
img.width = imageWidth;
return img;
}
function addTable() { function addTable() {
// Remove any previous table // Remove any previous table
document.getElementById('screenshots_container').innerHTML = ''; document.getElementById('screenshots_container').innerHTML = '';
@ -121,10 +148,9 @@ function addTable() {
languagesHeaderRow.appendChild(th); languagesHeaderRow.appendChild(th);
} }
const numVisibleLanguages = languagesHeaderRow.childElementCount const numVisibleLanguages = languagesHeaderRow.childElementCount
// Second item contains the paths
// Next items are the data // Next items are the data
var currentHeaderValue = ""; var currentHeaderValue = "";
for (let screenshotIndex = 2; screenshotIndex < screenshots.length; screenshotIndex++) { for (let screenshotIndex = 1; screenshotIndex < screenshots.length; screenshotIndex++) {
let englishFile = screenshots[screenshotIndex][0]; let englishFile = screenshots[screenshotIndex][0];
const tr = document.createElement('tr'); const tr = document.createElement('tr');
let hasTranslatedFiles = false; let hasTranslatedFiles = false;
@ -134,33 +160,26 @@ function addTable() {
} }
const td = document.createElement('td'); const td = document.createElement('td');
if (languageIndex == 0) { if (languageIndex == 0) {
const fullFile = `${dataPaths[0]}/${englishFile}.png`; // English file
const img = document.createElement('img'); td.appendChild(createImageElement(`${englishBasePath}/${englishFile}.png`));
img.className = "screenshot"; } else if (languageIndex == 1) {
img.src = `../${fullFile}`; // Dark English file
img.title = fullFile; if (screenshots[screenshotIndex][1].length > 0) {
img.alt = "Missing image"; hasTranslatedFiles = true;
img.width = imageWidth; td.appendChild(createImageElement(`${englishBasePath}/${screenshots[screenshotIndex][1]}.png`));
td.appendChild(img); } else {
td.appendChild(createMissingImageElement());
}
} else { } else {
let hasFile = screenshots[screenshotIndex][languageIndex]; let hasFile = screenshots[screenshotIndex][languageIndex];
if (hasFile === 0) { if (hasFile === 0) {
const text = document.createElement('p'); td.appendChild(createMissingImageElement());
text.className = "missing";
text.textContent = 'No image';
td.appendChild(text);
} else { } else {
hasTranslatedFiles = true; hasTranslatedFiles = true;
// Foreign file is the same as the english file, replacing the language // Foreign file is the same as the english file, replacing the language
const foreignFile = englishFile.replace("en]", `${dataLanguages[languageIndex]}]`).replace("_S_", "_T_") const foreignFile = englishFile.replace("en]", `${dataLanguages[languageIndex]}]`).replace("_S_", "_T_")
const fullForeignFile = `${dataPaths[languageIndex]}/${foreignFile}.png`; const fullForeignFile = `${dataLanguages[languageIndex]}/${foreignFile}.png`;
const img = document.createElement('img'); td.appendChild(createImageElement(fullForeignFile));
img.className = "screenshot";
img.src = `../${fullForeignFile}`;
img.title = fullForeignFile;
img.alt = "Missing image";
img.width = imageWidth;
td.appendChild(img);
} }
} }
tr.appendChild(td); tr.appendChild(td);

View file

@ -100,23 +100,34 @@ def detectRecordedLanguages():
return sorted([f for f in os.listdir("screenshots") if len(f) == 2]) return sorted([f for f in os.listdir("screenshots") if len(f) == 2])
def computeDarkFileName(lightFileName):
if "-Day_0" in lightFileName:
return lightFileName.replace("-Day_0", "-Night_1")
match = re.match("(.*)-Day-(\d+)_(\d+)(.*)", lightFileName, flags=re.ASCII)
if match:
return match.group(1) + "-Night-" + match.group(2) + "_" + str((int(match.group(3)) + 1)) + match.group(4)
return ""
def generateJavascriptFile(): def generateJavascriptFile():
__doc__ = "Generate a javascript file to load the screenshots" __doc__ = "Generate a javascript file to load the screenshots"
print("Generating javascript file...") print("Generating javascript file...")
languages = detectRecordedLanguages() languages = detectRecordedLanguages()
# First item is the list of languages, adding "en" at the beginning # First item is the list of languages, adding "en" and "en-dark" at the beginning
data = [["en"] + languages] data = [["en", "en-dark"] + languages]
# Second item is the path of the containing file
data.append(["./tests/uitests/src/test/snapshots/images"] + ["./screenshots/" + l for l in languages])
files = sorted( files = sorted(
os.listdir("tests/uitests/src/test/snapshots/images/"), os.listdir("tests/uitests/src/test/snapshots/images/"),
key=lambda file: file[file.find("_", 6):], key=lambda file: file[file.find("_", 6):],
) )
for file in files: for file in files:
# Continue if file contains "-Night", keep only light screenshots (maybe the night screenshots could be on the second column?) # Continue if file contains "-Night", keep only light screenshots
if "-Night" in file: if "-Night" in file:
continue continue
dataForFile = [file[:-4]] dataForFile = [file[:-4]]
darkFile = computeDarkFileName(file)
if os.path.exists("./tests/uitests/src/test/snapshots/images/" + darkFile):
dataForFile.append(darkFile[:-4])
else:
dataForFile.append("")
for l in languages: for l in languages:
simpleFile = file[:3] + "T" + file[4:-7] + l + file[-5:-4] simpleFile = file[:3] + "T" + file[4:-7] + l + file[-5:-4]
translatedFile = "./screenshots/" + l + "/" + simpleFile + ".png" translatedFile = "./screenshots/" + l + "/" + simpleFile + ".png"