Espeasy: 从源文件自动生成 WebStaticData.h

创建于 2018-08-22  ·  5评论  ·  资料来源: letscontrolit/ESPEasy

以原始文件格式(例如favicon.icogithub-icon.svg )存储静态资产并使用脚本将它们转换为WebStaticData.h所需的 C 代码将是有益的。 这样就可以维护资产,而无需在 C 代码中闲逛或在编辑 CSS 后忘记空终止符

额外的好处是可以在将文件写入文件之前使用svgojsmin等外部插件优化文件。 虽然我会使用一个简单的 (bash/python/...) 脚本来生成文件,但可以查看WI-PWN以获得灵感。

Build Enhancement

所有5条评论

这是一个很好的建议,我们将来需要做这样的事情。 感谢您提出问题。 :+1:

这是将来会添加的一件事。
它还允许用户自己添加新图标。

它还没有的唯一原因是因为我还不确定格式,而且我还在考虑将这些资产作为文件加载到 SPIFF。

谢谢你的链接!

只是为了完整性:我不久前为此任务创建了一个脚本。 它基本上是 Erick B. Tedeschi 和 spacehuhn 脚本的副本。 esp8266_deauther 的 repo 还包含用于此任务的另一个 (python) 脚本

#!/bin/bash

#
# This script walks through the assets folder and minifys all JS, HTML, CSS and SVG files. It also generates
# the corresponding constants that are added to the data.h file on esp8266_deauther folder.
#
# <strong i="8">@Author</strong> Erick B. Tedeschi < erickbt86 [at] gmail [dot] com >
# <strong i="9">@Author</strong> Wandmalfarbe https://github.com/Wandmalfarbe
#

outputfile="$(pwd)/data_h_temp"

rm $outputfile

function minify_html_css {
    file=$1
    curl -X POST -s --data-urlencode "input@$file" http://html-minifier.com/raw > /tmp/converter.temp
}

function minify_js {
    file=$1
    curl -X POST -s --data-urlencode "input@$file" https://javascript-minifier.com/raw > /tmp/converter.temp
}

function minify_svg {
    file=$1
    svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
}

function ascii2hexCstyle {
    file_name=$(constFileName $1)
    result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
    result=$(echo $result | sed 's/,$//')
    echo "const char DATA_${file_name}[] PROGMEM = {$result};"
}

function constFileName {
    extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
    file=$(echo $1 | sed 's/\.json//' | sed 's/\.svg//' | sed 's/\.css//' | sed 's/\.html//' | sed 's/\.js//' | sed 's/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
    underscore="_"
    echo $file$underscore$extension
}


cd assets
file_list=$(find . -type f)

for file in $file_list; do
    echo "Processing: $file"
    file_name=$(constFileName $file)
    echo "  Array Name: $file_name"

    if [[ "$file" == *.min.js ]]; then
        echo "  JS already minified"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.js ]]; then
        echo "  JS minify"
        minify_js $file
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.min.css ]]; then
        echo "  CSS already minified"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.html ]] || [[ "$file" == *.css ]]; then
        echo "  HTML and CSS minify"
        minify_html_css $file
        ascii2hexCstyle $file >> $outputfile
    elif [[ "$file" == *.svg ]]; then
        echo "  SVG minify"
        minify_svg $file
        ascii2hexCstyle $file >> $outputfile
    else
        echo "  without minifier"
        cat $file > /tmp/converter.temp
        ascii2hexCstyle $file >> $outputfile
    fi
    echo ""
    sleep 1
done

我将尝试这样做,以便我们可以缩小所有嵌入的 JavaScript。
对于具有 4 MB 闪存的构建,让代码可读也是一个好主意。

哦哦,美妙的音乐在我耳边@TD-er :)

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Grovkillen picture Grovkillen  ·  6评论

jobst picture jobst  ·  5评论

TD-er picture TD-er  ·  4评论

Barracuda09 picture Barracuda09  ·  5评论

ronnythomas picture ronnythomas  ·  3评论