Skip to content

Commit

Permalink
优化部分主页,尝试使用fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
white0dew committed Jun 19, 2024
1 parent 4675ed6 commit 27174a3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/s/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import siteMetadata from "@/assets/siteMetadata";
import MDViewer from "@/components/markdown/MarkdownView";
import Image from "next/image";
import { ContentPrefixPath } from "@/constants/path";
import { Suspense } from "react";

export const dynamicParams = true;
export const revalidate = 60 * 60 * 1; //60*60*1 s
Expand Down Expand Up @@ -181,6 +182,13 @@ export async function generateMetadata({
};
}

const LoadingSpinner = () => (
<div className="spinner">
{/* 你可以使用你喜欢的加载指示器样式 */}
<div>Loading...</div>
</div>
);

export default function ArticlePage({
params,
}: {
Expand All @@ -195,6 +203,7 @@ export default function ArticlePage({
}
// mylog(curArticle?.body.raw)
return (
// <Suspense fallback={<LoadingSpinner />}>
<div
className="relative mx-auto max-w-screen-xl justify-center space-x-3 px-4 py-2
md:flex md:flex-row md:py-2 lg:space-x-16"
Expand Down Expand Up @@ -267,5 +276,6 @@ export default function ArticlePage({
)}
</div>
</div>
// </Suspense>
);
}
12 changes: 6 additions & 6 deletions components/home/ProductShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@ import Link from "next/link";
// TODO 改成语雀可配置
const products = [
{
name: "程序员自我修养",
name: "🔥程序员自我修养",
description:
"软技能同样重要。提升沟通、团队协作能力,培养解决问题的思维,助你成为更全面的开发者。",
path: "/s/self_improve/screct_qas",
},
// ...更多产品
{
name: "编程语言",
name: "📚编程语言",
description:
"掌握流行的编程语言是开发者的基础。详解Java、Golang、Python、JavaScript等语言特性,助你深入理解语法和应用场景。",
path: "/s/language",
},
{
name: "计算机基础",
name: "💻计算机基础",
description:
"精炼的计算机基础讲解,包括数据结构、算法、计算机网络等计算机基础知识,帮助你通过技术面试的第一关。",
path: "/s/cs_base",
},
{
name: "实践项目",
name: "🧰实践项目",
description:
"实战项目经验分享,包括项目规划、开发到部署的全过程,提升你的项目构建与管理能力。",
path: "/s/project",
},
{
name: "大厂面经",
name: "💹大厂面经",
description:
"来自一线大厂的真实面试经验总结,涵盖前端、后端到AI等多个领域,为你的求职之路增添砝码。",
path: "/s/interview/chat_view",
},
{
name: "区区算法",
name: "⬇️区区算法",
description:
"汲取大厂资深面试官的智慧精华,提供全面的前端、后端及人工智能面试策略,助你在职场竞争中脱颖而出。",
path: "/s/algorithm/hogrunp9g0bggri2",
Expand Down
84 changes: 84 additions & 0 deletions lib/friend-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const fs = require("fs");
// function extractWebsiteInfoFromMarkdown(markdown: string): WebsiteInfo[] {
// // 移除YAML头部
// const contentWithoutYaml = markdown.replace(/---[\s\S]?---/, '');
// console.log("contentWithoutYaml",contentWithoutYaml)
// // 定义正则表达式来匹配所需信息
// const regex = /> 网站名称:(.?)\n> 网站介绍:(.?)\n> 网站地址:(.?)\n> 网站头图:(.*?)(?=\n|$)/g;

// // 存储所有匹配的信息
// const websitesInfo: WebsiteInfo[] = [];
// let match;

// // 使用循环来找到所有匹配项
// while ((match = regex.exec(contentWithoutYaml))) {
// const [_, name, description, url, imageUrl] = match;
// websitesInfo.push({
// name: name.trim(),
// description: description.trim(),
// url: url.trim(),
// imageUrl: imageUrl.trim(),
// });
// }

// // 返回提取的网站信息
// return websitesInfo;
// }

interface WebsiteInfo {
name: string;
description: string;
url: string;
imageUrl: string;
}

function extractInfoFromMarkdownTable(markdownTable: string): WebsiteInfo[] {
// 分割字符串为行
const lines = markdownTable.split("\n").filter((line) => line.trim() !== "");

// 假设第一行是标题,从第三行开始是数据(第二行是分隔符)
const dataLines = lines.slice(2);

// 提取信息
const websites: WebsiteInfo[] = dataLines.map((line) => {
// 移除行首尾的 "|" 字符,然后按 "|" 分割每列
const columns = line
.slice(1, -1)
.split("|")
.map((col) => col.trim());

// 根据列的位置提取数据
return {
name: columns[1],
description: columns[2],
url: columns[3],
imageUrl: columns[4],
};
});

return websites;
}

// 示例使用
const markdownTable = `
网站名称 网站介绍 网站地址 网站头图
OfferNow 让每个人了解计算机、编程、AI1111fasfasfafafsafasfafasfsfasfafsafaafas https://www.offernow.cn https://offernow.cn/img1.png
OfferNow2 让每个人了解计算机、编程、AI2 https://www.offernow.cn2 https://offernow.cn/img2.png
`;
const websitesInfo = extractInfoFromMarkdownTable(markdownTable);
console.log(websitesInfo);
// 将提取的信息保存为JSON文件
const saveInfoAsJson = (data: object[], filePath: string) => {
const jsonData = JSON.stringify(data, null, 2); // 格式化JSON字符串,使其更易于阅读

fs.writeFile(filePath, jsonData, "utf8", (err: any) => {
if (err) {
console.error("An error occurred while writing JSON Object to File.");
return console.error(err);
}
console.log("JSON file has been saved.");
});
};

// 调用函数,保存信息到websitesInfo.json文件
saveInfoAsJson(websitesInfo, "./public/websitesInfo.json");

0 comments on commit 27174a3

Please sign in to comment.