pref: 优化临时访问中的目录样样式

This commit is contained in:
xiaozzzi 2024-04-17 16:13:13 +08:00
parent e59bd36110
commit d48048d306
2 changed files with 49 additions and 27 deletions

View File

@ -103,7 +103,7 @@ public class ArticleUtil {
/** /**
* *
*/ */
private static final String HEAD_SCRIPT_BLOG_COLOR = " <script>\n" + private static final String HEAD_SCRIPT_BLOG_COLOR = " <script>\n" +
" window.addEventListener('load', function() {\n" + " window.addEventListener('load', function() {\n" +
" const rgb = '{BLOSSOM_WEB_BLOG_COLOR}'\n" + " const rgb = '{BLOSSOM_WEB_BLOG_COLOR}'\n" +
" if (rgb && !rgb.toLowerCase().startsWith('rgb(')) {\n" + " if (rgb && !rgb.toLowerCase().startsWith('rgb(')) {\n" +
@ -123,10 +123,9 @@ public class ArticleUtil {
" .item(0)\n" + " .item(0)\n" +
" .appendChild(themeStyleTag)\n" + " .appendChild(themeStyleTag)\n" +
" });\n" + " });\n" +
" </script>" + " </script>\n";
"</head>";
private static final String HEAD_SCRIPT_WATERMARK = "<script>\n" + private static final String HEAD_SCRIPT_WATERMARK = " <script>\n" +
" window.addEventListener(\"load\", function () {\n" + " window.addEventListener(\"load\", function () {\n" +
" const FontGap = 3\n" + " const FontGap = 3\n" +
"\n" + "\n" +
@ -326,25 +325,31 @@ public class ArticleUtil {
"\n" + "\n" +
" renderWatermark()\n" + " renderWatermark()\n" +
" })\n" + " })\n" +
" </script>"; " </script>\n";
private static final String BODY_HEADER_AND_TOC = "\n" + private static final String BODY_HEADER = "\n" +
"<body><div class=\"header\">\n" + "<body>\n" +
" <div class=\"copyright\">本文作者:{BLOSSOM_EXPORT_HTML_AUTHOR}。著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。</div><a\n" + " <div class=\"header\">\n" +
" <div class=\"copyright\">本文作者:{BLOSSOM_EXPORT_HTML_AUTHOR}。著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。</div><a\n" +
" href=\"https://github.com/blossom-editor/blossom\" target=\"_blank\"><span>Export by Blossom</span><svg\n" + " href=\"https://github.com/blossom-editor/blossom\" target=\"_blank\"><span>Export by Blossom</span><svg\n" +
" xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" class=\"bi bi-github\"\n" + " xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" class=\"bi bi-github\"\n" +
" viewBox=\"0 0 16 16\">\n" + " viewBox=\"0 0 16 16\">\n" +
" <path\n" + " <path\n" +
" d=\"M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z\" />\n" + " d=\"M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z\" />\n" +
"</svg></a>\n" + " </svg></a>\n" +
"</div><div class=\"content \">\n" + " </div>\n" +
" <div class=\"content \">\n" +
" <div class=\"main\">\n" +
" <div class=\"bl-preview\" id=\"blossom-view\">";
private static final String BODY_CONTENT_TOC = "\n" +
" <div class=\"toc\" id=\"blossom-toc\">\n" + " <div class=\"toc\" id=\"blossom-toc\">\n" +
" <div style=\"font-size: 15px;color:#727272;padding:10px 0\">《{BLOSSOM_EXPORT_HTML_ARTICLE_NAME}》</div>\n" + " <div style=\"font-size: 15px;color:#727272;padding:10px 0\">《{BLOSSOM_EXPORT_HTML_ARTICLE_NAME}》</div>\n" +
" <div style=\"font-size: 20px;color:#727272;border-bottom:2px solid #eaeaea;padding-bottom: 10px;margin-bottom: 10px;\">目录</div>\n" + " <div style=\"font-size: 20px;color:#727272;border-bottom:2px solid #eaeaea;padding-bottom: 10px;margin-bottom: 10px;\">目录</div>\n" +
" </div><div class=\"main\"><div class=\"bl-preview\" id=\"blossom-view\">"; " </div>\n";
private static final String suffix = "</div></div></div></body></html>"; private static final String suffix = "</div></body></html>";
private static String htmlTemplate; private static String htmlTemplate;
@ -381,14 +386,10 @@ public class ArticleUtil {
String WEB_BLOG_WATERMARK_COLOR, String WEB_BLOG_WATERMARK_COLOR,
String WEB_BLOG_WATERMARK_GAP) { String WEB_BLOG_WATERMARK_GAP) {
return htmlTemplate return htmlTemplate
+ appendHeadScript(blogColor, + appendHeadScript(blogColor, WEB_BLOG_WATERMARK_ENABLED, WEB_BLOG_WATERMARK_CONTENT, WEB_BLOG_WATERMARK_FONTSIZE, WEB_BLOG_WATERMARK_COLOR, WEB_BLOG_WATERMARK_GAP)
WEB_BLOG_WATERMARK_ENABLED, + appendBodyHeader(user)
WEB_BLOG_WATERMARK_CONTENT, + appendArticleContent(article)
WEB_BLOG_WATERMARK_FONTSIZE, + appendToc(article)
WEB_BLOG_WATERMARK_COLOR,
WEB_BLOG_WATERMARK_GAP)
+ appendBodyHeader(article, user)
+ article.getHtml()
+ suffix; + suffix;
} }
@ -421,15 +422,35 @@ public class ArticleUtil {
} }
/** /**
* 加页面顶部的文章作者和目录顶部的文章名称 * 加页面顶部的文章作者和目录顶部的文章名称
* *
* @param article 文章 * @param article 文章
* @param user 用户, 用户获取作者 * @param user 用户, 用户获取作者
* @return 页面顶部的文章作者和文章名称 * @return 页面顶部的文章作者和文章名称
*/ */
private static String appendBodyHeader(ArticleEntity article, UserEntity user) { private static String appendBodyHeader(UserEntity user) {
return BODY_HEADER_AND_TOC return BODY_HEADER
.replaceAll("\\{BLOSSOM_EXPORT_HTML_AUTHOR}", user.getNickName()) .replaceAll("\\{BLOSSOM_EXPORT_HTML_AUTHOR}", user.getNickName());
}
/**
* 添加正文
*
* @param article 文章
*/
private static String appendArticleContent(ArticleEntity article) {
return article.getHtml()
+ "\n </div>"
+ "\n </div>";
}
/**
* 添加目录
*
* @param article 文章
*/
private static String appendToc(ArticleEntity article) {
return BODY_CONTENT_TOC
.replaceAll("\\{BLOSSOM_EXPORT_HTML_ARTICLE_NAME}", article.getName()); .replaceAll("\\{BLOSSOM_EXPORT_HTML_ARTICLE_NAME}", article.getName());
} }
} }

View File

@ -1398,8 +1398,9 @@
.toc { .toc {
height: 100%; height: 100%;
width: 300px; width: 300px;
padding-left: 15px; padding-left: 10px;
border-right: 1px solid #eeeeee; padding-bottom: 10px;
border-left: 1px solid #eeeeee;
overflow-x: hidden; overflow-x: hidden;
overflow-y: scroll; overflow-y: scroll;
margin-top: 30px; margin-top: 30px;