mirror of
https://github.com/konpa/devicon.git
synced 2025-08-31 10:02:12 +02:00
Optimized SVG using SVGO (#597)
* Added script to optimize svgs * Updated the svgs using svgo * Made the optimize svg script into a workflow * Added npm install step * Change the env variable bug * Clean up and updated check svg * Change label name
This commit is contained in:
14
.github/scripts/check_svgs_on_pr.py
vendored
14
.github/scripts/check_svgs_on_pr.py
vendored
@@ -69,21 +69,11 @@ def check_svgs(svg_file_paths: List[Path]):
|
||||
if root.get("viewBox") != "0 0 128 128":
|
||||
err_msg.append("-'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg")
|
||||
|
||||
acceptable_size = [None, "128px", "128"]
|
||||
if root.get("height") not in acceptable_size:
|
||||
err_msg.append("-'height' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
|
||||
|
||||
if root.get("width") not in acceptable_size:
|
||||
err_msg.append("-'width' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
|
||||
|
||||
if root.get("style") is not None and "enable-background" in root.get("style"):
|
||||
err_msg.append("-deprecated 'enable-background' in style attribute -> Remove it")
|
||||
|
||||
if root.get("x") is not None:
|
||||
err_msg.append("-unneccessary 'x' attribute in svg element -> Remove it")
|
||||
err_msg.append("-unneccessary 'x' attribute in svg root element -> Remove it")
|
||||
|
||||
if root.get("y") is not None:
|
||||
err_msg.append("-unneccessary 'y' attribute in svg element -> Remove it")
|
||||
err_msg.append("-unneccessary 'y' attribute in svg root element -> Remove it")
|
||||
|
||||
style = root.findtext(f".//{namespace}style")
|
||||
if style != None and "fill" in style:
|
||||
|
33
.github/workflows/optimize_svg.yml
vendored
Normal file
33
.github/workflows/optimize_svg.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: Optimize the added/changed svgs
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
jobs:
|
||||
peek:
|
||||
name: Optimize the added/changed svgs
|
||||
if: github.event.label.name == 'bot:optimize'
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
- name: Set up gulp
|
||||
run: npm install
|
||||
|
||||
- name: Get Changed Files and generate files_added.json & files_modified.json
|
||||
uses: lots0logs/gh-action-get-changed-files@2.1.4
|
||||
id: get_added_and_modified_files
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run the update_id.py
|
||||
env:
|
||||
ADDED_FILES: ${{ steps.get_added_and_modified_files.outputs.added }}
|
||||
MODIFIED_FILES: ${{ steps.get_added_and_modified_files.outputs.modified }}
|
||||
run: npm run optimize-svg -- --filesAddedJson=$ADDED_FILES --filesModifiedJson=$MODIFIED_FILES
|
||||
|
||||
- name: Commit the changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: Optimized the SVGs
|
Reference in New Issue
Block a user