通过 Hexo 程序生成的页面,其源代码会产生大量的空行,不仅影响排错,且会占用本地、网络资源。今天杜老师为大家分享一段 Python 的代码,可以对其进行压缩!压缩脚本123456789101112131415161718192021222324252627#!/usr/bin/env python3# coding: UTF-8importre,osdefminify_html(filename):withopen(filename,'r',encoding='utf-8')asp:withopen(filename+'.tmp','w',encoding='utf-8')ast:whileTrue:l = p.readline()ifnotl:breakelse:ifre.search('\S',l):t.write(l)os.remove(filename)os.rename(filename+'.tmp',filename)print('%s 已压缩!'%filename)defyasuo(dir_path):ifdir_path[len(dir_path)-1] =='/':dir_path
...
继续阅读
(3)