Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
ted423 opened this issue Jun 6, 2023 · 2 comments · Fixed by #375
Closed
2 tasks done

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

ted423 opened this issue Jun 6, 2023 · 2 comments · Fixed by #375
Assignees
Labels

Comments

@ted423
Copy link

ted423 commented Jun 6, 2023

「描述遇到的问题」或「发现的 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):

  • 操作系统(OS): [e.g. iOS]
  • 浏览器(Browser) [e.g. chrome, safari]
  • 浏览器版本(Version)[e.g. 22][可选]

其他信息(Additional context)

@Stark-X
Copy link
Collaborator

Stark-X commented Jun 6, 2023

<% var resortAllPosts = site.posts.map(function (item) { %>
<% let title = item.title; %>
<% let link = url_for(item.path) ; %>
<% let _date = date(item.date, "YYYY-MM-DD HH:MM:SS"); %>
<% let returnDate = {
title : title,
link : link,
date : _date }; %>
<% return returnDate; %>
<% }) %>
<% resortAllPosts.sort(function compare(v1, v2){ %>
<% let result = (new Date(v1.date)) > (new Date(v2.date)); %>
<% return result == true ? -1 : 1; %>
<% }) %>
<% let showYear = NaN; %>
<% let currPagePosts; %>
<% let showDate = NaN; %>
<% currPagePosts = resortAllPosts; %>
<div class="total-and-search">
<div class="total-archive">
Total : <%= currPagePosts.length %>
</div>

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

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

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

@LolipopJ
Copy link
Collaborator

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

yarn add hexo-html-minifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants