Hexo file name escape issue and solution

I’m working on reorganize posts today, and found some filename issue with Hexo.

Speical symbols are not escaped properly

Just found this issue today.

To ensure filename generate from title is legal as either file name or url path, Hexo uses hexo.util.escape.filename to escape the illegal symbols. filename does escape some symbols, but it doesn’t cover all illegal symbols, such as +, =, &, etc. If these symbols are not escaped properly, which generates illegal url link. As a result, your post will never be acessible.

I found this issue is because, I have a post with +3 trainer in its title, since + is not escaped, and + will be treated as space by http. As a consequence, my post will never be able to open, unless I escape + as %2B. To avoid this kind of problem, I wish all the symbols in post name are escaped as -.

Besides this issue, Hexo has another issue with name escaping that the escaped file name might contains continues -. For example, your post title is “A great introduction - part 1”, you will get escaped name a-great-introduction---part-1.md. I wish the continues - in the file name should be replaced with single -, name a-great-introduction-part-1.md is more readable than previous one.

To fix the 2 issues, I just created a pull request, hope it will be merged soon.

I cared about this issue so much is because I uses hexo-consle-rename plug-in, which also uses util.escape to handle file name. To keep naming consistency when between different version of Hexo, I addd a kind of evil monkey patch in the v0.1.2. So make sure the plug in can work properly even with old Hexo.

File name case issue

Besides the Hexo naming issue, I also met the case of the filename today. Although it depends on the blog hosting, but it might cause 404 if the file name case changed.

To avoid this kind of issue, I strongly recommend to set filename_case: 1 in _config.yml, which will make sure all file name are in lower case.

There is common pitfall here for Windows or Mac with case-insensitive file system. If you have deploy the website once with wrong filename casing. Regenerate after updated filename_case won’t help, because file system won’t treat case change in filename as “change”. So you cannot really commit the “change” to fix the 404 issue.

To fix this issue, there is easy and efficient trick. Go to .deploy folder, execute following commands:

1
2
3
4
$ git rm -rf *
$ git ci -m "Clean all file"
$ hexo clean
$ hexo d -g

To force clean the repo once enforce git to treat 2 files with same name but different casing as different ones. So the name casing issue can be fixed.

HTML codes to put special characters on your Web page

尝试了一下用 LinqPad 把各种诡异的字母转成 Html 编码~结果发现不是左右字符都能转过去~
.net 内置的工具并不能完美的处理所有的 Html 编码~

字符来源

Query

Get html escaped unicodes
1
2
3
"A,a,À,à,Á,á,Â,â,Ã,ã,Ä,ä,Å,å,Ā,ā,Ă,ă,Ą,ą,Ǟ,ǟ,Ǻ,ǻ,Æ,æ,Ǽ,ǽ,B,b,Ḃ,ḃ,C,c,Ć,ć,Ç,ç,Č,č,Ĉ,ĉ,Ċ,ċ,D,d,Ḑ,ḑ,Ď,ď,Ḋ,ḋ,Đ,đ,Ð,ð,DZ,dz,DŽ,dž,E,e,È,è,É,é,Ě,ě,Ê,ê,Ë,ë,Ē,ē,Ĕ,ĕ,Ę,ę,Ė,ė,Ʒ,ʒ,Ǯ,ǯ,F,f,Ḟ,ḟ,ƒ,ff,fi,fl,ffi,ffl,ſt,G,g,Ǵ,ǵ,Ģ,ģ,Ǧ,ǧ,Ĝ,ĝ,Ğ,ğ,Ġ,ġ,Ǥ,ǥ,H,h,Ĥ,ĥ,Ħ,ħ,I,i,Ì,ì,Í,í,Î,î,Ĩ,ĩ,Ï,ï,Ī,ī,Ĭ,ĭ,Į,į,İ,ı,IJ,ij,J,j,Ĵ,ĵ,K,k,Ḱ,ḱ,Ķ,ķ,Ǩ,ǩ,ĸ,L,l,Ĺ,ĺ,Ļ,ļ,Ľ,ľ,Ŀ,ŀ,Ł,ł,LJ,lj,M,m,Ṁ,ṁ,N,n,Ń,ń,Ņ,ņ,Ň,ň,Ñ,ñ,ʼn,Ŋ,ŋ,NJ,nj,O,o,Ò,ò,Ó,ó,Ô,ô,Õ,õ,Ö,ö,Ō,ō,Ŏ,ŏ,Ø,ø,Ő,ő,Ǿ,ǿ,Œ,œ,P,p,Ṗ,ṗ,Q,q,R,r,Ŕ,ŕ,Ŗ,ŗ,Ř,ř,ɼ,S,s,Ś,ś,Ş,ş,Š,š,Ŝ,ŝ,Ṡ,ṡ,ſ,ß,T,t,Ţ,ţ,Ť,ť,Ṫ,ṫ,Ŧ,ŧ,Þ,þ,U,u,Ù,ù,Ú,ú,Û,û,Ũ,ũ,Ü,ü,Ů,ů,Ū,ū,Ŭ,ŭ,Ų,ų,Ű,ű,V,v,W,w,Ẁ,ẁ,Ẃ,ẃ,Ŵ,ŵ,Ẅ,ẅ,X,x,Y,y,Ỳ,ỳ,Ý,ý,Ŷ,ŷ,Ÿ,ÿ,Z,z,Ź,ź,Ž,ž,Ż,ż"
.Split(',')
.ToDictionary(k=>k,HttpUtility.HtmlEncode)

Result

Dictionary<String,String>
(304 items)



















































































































































































































































































































KeyValue
AA
aa
À&#192;
à&#224;
Á&#193;
á&#225;
Â&#194;
â&#226;
Ã&#195;
ã&#227;
Ä&#196;
ä&#228;
Å&#197;
å&#229;
ĀĀ
āā
ĂĂ
ăă
ĄĄ
ąą
ǞǞ
ǟǟ
ǺǺ
ǻǻ
Æ&#198;
æ&#230;
ǼǼ
ǽǽ
BB
bb
CC
cc
ĆĆ
ćć
Ç&#199;
ç&#231;
ČČ
čč
ĈĈ
ĉĉ
ĊĊ
ċċ
DD
dd
ĎĎ
ďď
ĐĐ
đđ
Ð&#208;
ð&#240;
DZDZ
dzdz
DŽDŽ
dždž
EE
ee
È&#200;
è&#232;
É&#201;
é&#233;
ĚĚ
ěě
Ê&#202;
ê&#234;
Ë&#203;
ë&#235;
ĒĒ
ēē
ĔĔ
ĕĕ
ĘĘ
ęę
ĖĖ
ėė
ƷƷ
ʒʒ
ǮǮ
ǯǯ
FF
ff
ƒƒ
GG
gg
ǴǴ
ǵǵ
ĢĢ
ģģ
ǦǦ
ǧǧ
ĜĜ
ĝĝ
ĞĞ
ğğ
ĠĠ
ġġ
ǤǤ
ǥǥ
HH
hh
ĤĤ
ĥĥ
ĦĦ
ħħ
II
ii
Ì&#204;
ì&#236;
Í&#205;
í&#237;
Î&#206;
î&#238;
ĨĨ
ĩĩ
Ï&#207;
ï&#239;
ĪĪ
īī
ĬĬ
ĭĭ
ĮĮ
įį
İİ
ıı
IJIJ
ijij
JJ
jj
ĴĴ
ĵĵ
KK
kk
ĶĶ
ķķ
ǨǨ
ǩǩ
ĸĸ
LL
ll
ĹĹ
ĺĺ
ĻĻ
ļļ
ĽĽ
ľľ
ĿĿ
ŀŀ
ŁŁ
łł
LJLJ
ljlj
MM
mm
NN
nn
ŃŃ
ńń
ŅŅ
ņņ
ŇŇ
ňň
Ñ&#209;
ñ&#241;
ʼnʼn
ŊŊ
ŋŋ
NJNJ
njnj
OO
oo
Ò&#210;
ò&#242;
Ó&#211;
ó&#243;
Ô&#212;
ô&#244;
Õ&#213;
õ&#245;
Ö&#214;
ö&#246;
ŌŌ
ōō
ŎŎ
ŏŏ
Ø&#216;
ø&#248;
ŐŐ
őő
ǾǾ
ǿǿ
ŒŒ
œœ
PP
pp
QQ
qq
RR
rr
ŔŔ
ŕŕ
ŖŖ
ŗŗ
ŘŘ
řř
ɼɼ
SS
ss
ŚŚ
śś
ŞŞ
şş
ŠŠ
šš
ŜŜ
ŝŝ
ſſ
ß&#223;
TT
tt
ŢŢ
ţţ
ŤŤ
ťť
ŦŦ
ŧŧ
Þ&#222;
þ&#254;
UU
uu
Ù&#217;
ù&#249;
Ú&#218;
ú&#250;
Û&#219;
û&#251;
ŨŨ
ũũ
Ü&#220;
ü&#252;
ŮŮ
ůů
ŪŪ
ūū
ŬŬ
ŭŭ
ŲŲ
ųų
ŰŰ
űű
VV
vv
WW
ww
ŴŴ
ŵŵ
XX
xx
YY
yy
Ý&#221;
ý&#253;
ŶŶ
ŷŷ
ŸŸ
ÿ&#255;
ZZ
zz
ŹŹ
źź
ŽŽ
žž
ŻŻ
żż