Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
darrytai committed May 21, 2024
1 parent 9443552 commit 2e648af
Show file tree
Hide file tree
Showing 3 changed files with 772 additions and 4 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ jobs:
curl -o $css_file $css_url
font_urls=$(grep -oP 'url\(\K[^)]+' style.css | sort -u)
# curl -o "dist/fonts/TMicon.eot" "https://i.icomoon.io/public/a8317e20c1/TMIcons/TMicon.eot?73rtx5#iefix"
for url in $font_urls; do
clean_url=$(echo $url | sed 's/[?#].*//')
filename=$(basename "$clean_url")
full_url=$(echo $url | sed "s/'//g" | sed 's/"//g')
curl -o "$dist_dir/$filename" $full_url
done
git status
# rm $css_file
rm $css_file
echo "Font files downloaded successfully."
# echo "Font files downloaded successfully."
- name: Build SVG files
run: |
node ../script/buildSVGIcons.js
git status
# - name: Configure Git
# run: |
# git config --global user.name 'HIE UX Service'
Expand Down
50 changes: 50 additions & 0 deletions script/buildSVGIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require("fs");
const path = require("path");
const svgGen = require('./svgGenerator');
const preferences = require("../data/Preferences.json");
const icons = require("../data/Icons.json");
const svgTpl = fs.readFileSync(
path.join(__dirname, "..", "templates", "svg.tpl"),
"utf8"
);
const targetDir = path.join(__dirname, '..', 'dist', 'svg');
const defaultColor = `rgb(${preferences.imagePref.color
.toString(16)
.match(/\w\w/gi)
.map((color) => parseInt(color, 16))
.join(",")})`;
const viewBox = preferences.fontPref.metrics.emSize;
const files = fs.readdirSync(targetDir);
files.forEach(file => {
const filePath = path.join(targetDir, file);
if (fs.lstatSync(filePath).isFile()) {
fs.unlinkSync(filePath);
}
});

icons.sort(function (a, b) {
if (a.name > b.name) return 1;
if (a.name < b.name) return -1;
return 0;
});

icons.forEach((icon) => {
const targetPath = path.join(targetDir, `${icon.name}.svg`);
icon.width = icon.height = icon.grid;
icon.svgPath = svgGen(icon.paths);
const scale = icon.height / viewBox;
icon.scaledPath = icon.svgPath.scale(scale);
icon.scaledPathData = icon.scaledPath.getPathData(true);

let svgContent = svgTpl.replace(/_viewBox/gi, icon.grid);
let paths = [];
svgContent = svgContent.replace(/_title/gi, icon.name);
icon.paths.forEach((path, pathIndex) => {
let attr = Object.assign({ fill: defaultColor }, icon.attrs[pathIndex]);
let genAttrs = [];
Object.keys(attr).forEach((key) => genAttrs.push(`${key}="${attr[key]}"`));
paths.push(`<path ${genAttrs.join(' ')} d="${icon.scaledPathData[pathIndex]}"></path>`);
});
svgContent = svgContent.replace('<!--paths-->', paths.join('\n '));
fs.writeFileSync(targetPath, svgContent);
});
Loading

0 comments on commit 2e648af

Please sign in to comment.