fi3ework / hexo-theme-archer

🎯 A smart and modern theme for Hexo.
https://fi3ework.github.io/hexo-theme-archer
MIT License
1.49k stars 274 forks source link

html文件产生了大量的空行 #374

Open ted423 opened 1 year ago

ted423 commented 1 year ago

「描述遇到的问题」或「发现的 bug」(Describe the problem or bug you encounter)

你是否已经阅读过以下内容,并确认你的行为是正确的,在 [ ] 中填入 x 选中(Ensure that you had consulted followings and confirm the validity of your operation, fill x in [ ] to select)

如何复现(To Reproduce) 特意挑选了看了下以前就开始了 存在问题或 bug 的已部署上线的页面地址(A deployed page link that with bug or problem) https://github.com/ted423/ted423.github.io/blob/1bfb5b9c6930d27f10fd18fb0e6661b3a0cb2f34/Document/67%E4%BB%A3U%E5%BC%BA%E8%A3%85%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8/index.html#L1322-L5075

如果可能是与 markdown 内容相关的问题或 bug,请粘贴对应的 markdown 内容(If the problem or bug that may be related to markdown, paste it here)

打开控制台,填写控制台中打印的主题的版本,如果脚本出错可直接提供控制台截图(Open the console and report the version of hexo-theme-archer. You can paste the screenshot on console directly if there is error with script)

信息 (please complete the following information):

其他信息(Additional context)

Stark-X commented 1 year ago

https://github.com/fi3ework/hexo-theme-archer/blob/0a012d5d12e7a9680503329c133f75bddc07d8df/layout/_partial/sidebar/sidebar-archives.ejs#L3-L24

搜索关键字 “在 ejs 中将 archive 按照时间排序” 找到这部分的代码,搜索 ejs 相关的文档,找到 ejs 特性中的这个功能 https://github.com/mde/ejs#features ,使用 <%_ _%> 把空行去掉:

Whitespace-trim mode (slurp all whitespace) for control flow with <% %>

应该可以把所有判断语句输出的空行去掉,我有空尝试一下

LolipopJ commented 1 month ago

Hexo 基于 EJS 模版生成的 HTML 文档存在空行,更好的办法应该是在 Hexo 根目录添加插件 hexo-html-minifier,在构建后自动压缩得到的 HTML 文件:

yarn add hexo-html-minifier