use js script since the html template contains only a <script>
This commit is contained in:
parent
0475035d7f
commit
cfb21e7dcb
3 changed files with 35 additions and 36 deletions
33
static/js/custom_img_size.js
Normal file
33
static/js/custom_img_size.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
for (const item of document.getElementsByTagName("img")) {
|
||||||
|
// Check if we may need to resize the image
|
||||||
|
const possible_piece = item.alt.split(/\s?\|\s?/);
|
||||||
|
if (possible_piece.length > 1) {
|
||||||
|
// Check if 1 or 2 dimension(s) is provided
|
||||||
|
// Then, check if syntax is correct
|
||||||
|
//
|
||||||
|
// If everything is good, assign the width and/or the height
|
||||||
|
// to the image and remove the resize data from the alt text
|
||||||
|
const last_possible_piece =
|
||||||
|
possible_piece[possible_piece.length - 1].trim();
|
||||||
|
// Remove the resize data from the list
|
||||||
|
possible_piece.pop();
|
||||||
|
if (last_possible_piece.includes("x")) {
|
||||||
|
const verif = last_possible_piece.split(/\d+/);
|
||||||
|
if (
|
||||||
|
verif.length == 3 &&
|
||||||
|
verif[0] == "" &&
|
||||||
|
verif[1] == "x" &&
|
||||||
|
verif[2] == ""
|
||||||
|
) {
|
||||||
|
[item.width, item.height] = last_possible_piece.split("x");
|
||||||
|
item.alt = possible_piece.join("");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const verif = last_possible_piece.split(/\d+/);
|
||||||
|
if (verif.length == 2 && verif[0] == "" && verif[1] == "") {
|
||||||
|
item.width = last_possible_piece;
|
||||||
|
item.alt = possible_piece.join("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,4 +6,5 @@
|
||||||
{{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
{{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
||||||
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
||||||
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
||||||
{{/metadata}} {{/post}} {{/data}} {{>libs/custom_img_size.html}}
|
{{/metadata}} {{/post}} {{/data}}
|
||||||
|
<script src="/js/custom_img_size.js"></script>
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<script>
|
|
||||||
for (const item of document.getElementsByTagName("img")) {
|
|
||||||
// Check if we may need to resize the image
|
|
||||||
const possible_piece = item.alt.split(/\s?\|\s?/);
|
|
||||||
if (possible_piece.length > 1) {
|
|
||||||
// Check if 1 or 2 dimension(s) is provided
|
|
||||||
// Then, check if syntax is correct
|
|
||||||
//
|
|
||||||
// If everything is good, assign the width and/or the height
|
|
||||||
// to the image and remove the resize data from the alt text
|
|
||||||
const last_possible_piece =
|
|
||||||
possible_piece[possible_piece.length - 1].trim();
|
|
||||||
// Remove the resize data from the list
|
|
||||||
possible_piece.pop();
|
|
||||||
if (last_possible_piece.includes("x")) {
|
|
||||||
const verif = last_possible_piece.split(/\d+/);
|
|
||||||
if (
|
|
||||||
verif.length == 3 &&
|
|
||||||
verif[0] == "" &&
|
|
||||||
verif[1] == "x" &&
|
|
||||||
verif[2] == ""
|
|
||||||
) {
|
|
||||||
[item.width, item.height] = last_possible_piece.split("x");
|
|
||||||
item.alt = possible_piece.join("");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const verif = last_possible_piece.split(/\d+/);
|
|
||||||
if (verif.length == 2 && verif[0] == "" && verif[1] == "") {
|
|
||||||
item.width = last_possible_piece;
|
|
||||||
item.alt = possible_piece.join("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
Loading…
Reference in a new issue