2013-12-20 31 views
0

gh-pages是移動文本文件。 。 。我們的CI構建服務器將一些構建工件複製到gh頁面。在網頁服務器上設置* .txt文件的文件編碼屬性

本地,我可以看到文件編碼是UTF-8,如果我下載文件並打開它,它在文本編輯器中呈現得很好。

但是,在Safari,Firefox和Chrome中,特殊字符(勾號,複選標記等)正在變得模糊不清。如何指示使用正確的文件編碼?

回答

1

沒有被指示,瀏覽器無法知道什麼文件編碼用於純文本文件。設置.htaccess可以幫助,但是依賴於Web服務器。更便攜的方法是確保文本文件以UTF8字節順序標記(BOM)開頭。一種方法如下:

#!/bin/sh 

if [ $# -eq 0 ]; 
then 
     echo usage $0 files ... 
     exit 1 
fi 

for file in $*; 
do 
     echo "# Processing: $file" 1>&2 
     if [ ! -f "$file" ]; 
     then 
       echo Not a file: "$file" 1>&2 
       exit 1 
     fi 
     TYPE=`file - < "$file" | cut -d: -f2` 
     if echo "$TYPE" | grep -q '(with BOM)'; 
     then 
       echo "# $file already has BOM, skipping." 1>&2 
     else 
       (mv ${file} ${file}~ && uconv -f utf-8 -t utf-8 --add-signature < "${file}~" > "${file}") || (echo Error processing "$file" 1>&2 ; exit 1) 
     fi 
done 
相關問題