zoukankan      html  css  js  c++  java
  • sh cssupdate 优化

    #!/bin/bash
    
    # 更新css文件内图片的版本
    # 如background:url('images/test.jpg'); 更新为 background:url('images/test.jpg?20130330121210');
    
    csstmpl_path="/home/fdipzone/php/csstmpl" # css tmpl path
    css_path="/home/fdipzone/php/css"         # css path
    replacetags=(".png" ".jpg" ".gif")        # file type
    convertnum=0
    search_child=$1                           # search child
    
    echo ${search_child:=0} > /dev/null
    
    function create(){
        tmplfile=$1
        dfile=$2
    
        dfolder=${dfile%/*}
    
        if [ ! -d "$dfolder" ]; then
            mkdir -p $dfolder
        fi
    
        cp "$tmplfile" "$dfile" #复制tmpl到目标文件
    
        for tag in ${replacetags[*]} ; do
            newtag="$tag?$(date +%Y%m%d%H%M%S)"
            sed -i "s/$tag/$newtag/g" "$dfile" #使用sed -i 替换文件内容
        done
    
        convertnum=$(($convertnum+1))
    
        tolog "$tmplfile convert to $dfile success"
    }
    
    function tolog(){
        echo $1
    }
    
    function update(){
        if [ -d "$csstmpl_path" ] && [ -d "$css_path" ]; then
            
            if [ "$search_child" -eq 0 ]; then
                maxdepth=" -maxdepth 1 "
            else
                maxdepth=""
            fi
    
            for file in $(find $csstmpl_path $maxdepth -name "*.css" -type f) ; do
                dfile=${file/$csstmpl_path/$css_path}
                create $file $dfile
            done
    
            echo "convert num: $convertnum"
    
        else
            tolog "$csstmpl_path or $css_path not exists"
        fi
    }
    
    update
    
    exit 0

    查看PHP版

    查看上一版

  • 相关阅读:
    基于Centos 7 vue+nginx+docker 的前端项目部署
    uni-app学习随笔
    微服务和Docker
    Ado.Net
    数据库(SQLServer)
    JavaScript
    CSS样式
    HTML前端标签
    vue中 拖动元素边框 改变元素宽度
    vue学习笔记14
  • 原文地址:https://www.cnblogs.com/fdipzone/p/3715123.html
Copyright © 2011-2022 走看看