allow for defining custom dark: variants, ignore querySelector, shrink margins
This commit is contained in:
+31
-7
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# scan all typescript and automatically add dark variants to color tags if they're not already present.
|
||||
|
||||
if [[ "$1" == "ts" ]]; then
|
||||
for f in $2/*.ts; do
|
||||
# FIXME: inline html
|
||||
@@ -11,17 +13,39 @@ if [[ "$1" == "ts" ]]; then
|
||||
echo $line | sed 's/.*classList//; s/).*//' | grep "~neutral\|~positive\|~urge\|~warning\|~info\|~critical" &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
# echo "found classList @ " $l
|
||||
for color in neutral positive urge warning info critical; do
|
||||
sed -i "${l},${l}s/\"~${color}\"/\"~${color}\", \"dark:~d_${color}\"/g" $f
|
||||
done
|
||||
echo $line | grep "dark:" &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
for color in neutral positive urge warning info critical; do
|
||||
sed -i "${l},${l}s/\"~${color}\"/\"~${color}\", \"dark:~d_${color}\"/g" $f
|
||||
done
|
||||
fi
|
||||
else
|
||||
echo "FIX: classList found, but color tag wasn't in it"
|
||||
fi
|
||||
else
|
||||
# echo "found inline in " $f " @ " $l ", " $(sed -n "${l}p" $f)
|
||||
for color in neutral positive urge warning info critical; do
|
||||
sed -i "${l},${l}s/~${color}/~${color} dark:~d_${color}/g" $f
|
||||
done
|
||||
echo $line | grep "querySelector" &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
# echo "found inline in " $f " @ " $l ", " $(sed -n "${l}p" $f)
|
||||
echo $line | grep "dark:" &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
for color in neutral positive urge warning info critical; do
|
||||
sed -i "${l},${l}s/~${color}/~${color} dark:~d_${color}/g" $f
|
||||
done
|
||||
fi
|
||||
else
|
||||
echo $line | sed 's/.*querySelector//; s/).*//' | grep "~neutral\|~positive\|~urge\|~warning\|~info\|~critical" &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo $line | grep "dark:" &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
# echo "found inline in " $f " @ " $l ", " $(sed -n "${l}p" $f)
|
||||
for color in neutral positive urge warning info critical; do
|
||||
sed -i "${l},${l}s/~${color}/~${color} dark:~d_${color}/g" $f
|
||||
done
|
||||
fi
|
||||
#else
|
||||
#echo "FIX: querySelector found, but color tag wasn't in it: " $line
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
@@ -2,6 +2,16 @@ let parser = require("jsdom");
|
||||
let fs = require("fs");
|
||||
let path = require("path");
|
||||
|
||||
const hasDark = (item) => {
|
||||
for (let i = 0; i < item.classList.length; i++) {
|
||||
if (item.classList[i].substring(0,5) == "dark:") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
const fixHTML = (infile, outfile) => {
|
||||
console.log(infile, outfile)
|
||||
let doc = new parser.JSDOM(fs.readFileSync(infile));
|
||||
@@ -14,13 +24,17 @@ const fixHTML = (infile, outfile) => {
|
||||
if (items[i].classList.contains("~"+color)) {
|
||||
hasColor = true;
|
||||
// console.log("adding to", items[i].classList)
|
||||
items[i].classList.add("dark:~d_"+color);
|
||||
if (!hasDark(items[i])) {
|
||||
items[i].classList.add("dark:~d_"+color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasColor) {
|
||||
items[i].classList.add("~neutral");
|
||||
items[i].classList.add("dark:~d_neutral");
|
||||
if (!hasDark(items[i])) {
|
||||
items[i].classList.add("dark:~d_neutral");
|
||||
}
|
||||
}
|
||||
if (!items[i].classList.contains("@low") && !items[i].classList.contains("@high")) {
|
||||
items[i].classList.add("@low");
|
||||
|
||||
Reference in New Issue
Block a user