Upgrade UI design and improve some functions

This commit is contained in:
PrinOrange
2024-01-15 11:44:48 +08:00
parent aadaa3f216
commit 7befbc5b63
26 changed files with 230 additions and 73 deletions

View File

@@ -2,6 +2,7 @@ import { CopyrightAnnouncement, LatestPostCountInHomePage, WebsiteURL } from "@/
import { Config } from "@/data/config";
import { Feed } from "feed";
import fs from "fs";
import { JSDOM } from "jsdom";
import { MDXRemote } from "next-mdx-remote";
import { serialize } from "next-mdx-remote/serialize";
import { renderToString } from "react-dom/server";
@@ -17,6 +18,25 @@ import { getPostFileContent, sortedPosts } from "./post-process";
const NoticeForRSSReaders = `\n---\n**NOTE:** Different RSS reader may have deficient even no support for svg formulations rendering. If it happens, please read the origin page to have better experience.`;
function minifyHTMLCode(htmlString: string): string {
const dom = new JSDOM(htmlString);
const document = dom.window.document;
const elements = document.querySelectorAll("*");
const unusedElements = document.querySelectorAll("script, style");
// Remove all class attributes.
elements.forEach((element) => {
element.removeAttribute("class");
});
// Remove all script and style tags.
unusedElements.forEach((element) => {
element.parentElement?.removeChild(element);
});
return dom.serialize();
}
/**
* Generate the RSS Feed File in `./public` so it could be visited by https://domain/rss.xml
*/
@@ -49,7 +69,7 @@ export const generateRSSFeed = async () => {
format: "md",
},
});
const htmlContent = renderToString(<MDXRemote {...mdxSource} />);
const htmlContent = minifyHTMLCode(renderToString(<MDXRemote {...mdxSource} />));
feed.addItem({
title: post.frontMatter.title,

View File

@@ -1,5 +1,7 @@
import { cutForSearch } from "@node-rs/jieba";
import Colors from "colors";
import minisearch from "minisearch";
import sizeof from "object-sizeof";
import { getPostFileContent, sortedPosts } from "./post-process";
// Due to the flaws of the word tokenizer,
@@ -30,6 +32,8 @@ function makeSearchIndex() {
content: content,
});
}
const sizeofIndex = (sizeof(miniSearch) / 1024 ** 2).toFixed(3);
console.log(Colors.cyan(`Search index is ready. And the size of index is ${sizeofIndex} mb`));
return miniSearch;
}