diff --git a/packages/website/components/MarkdownTocBar/tools.ts b/packages/website/components/MarkdownTocBar/tools.ts index 5682c7504..e2bb0ca86 100644 --- a/packages/website/components/MarkdownTocBar/tools.ts +++ b/packages/website/components/MarkdownTocBar/tools.ts @@ -4,6 +4,7 @@ export interface NavItem { listNo: string; text: string; } + export const washMarkdownContent = (source: string) => { if (!source) return ""; return ( @@ -19,6 +20,7 @@ export const washMarkdownContent = (source: string) => { .trim() + "\n" ); }; + export const parseNavStructure = (source: string): NavItem[] => { const contentWithoutCode = washMarkdownContent(source); const pattOfTitle = /#+\s(.+)\n/g; diff --git a/packages/website/utils/hasToc.ts b/packages/website/utils/hasToc.ts index c5b3958ad..734e34027 100644 --- a/packages/website/utils/hasToc.ts +++ b/packages/website/utils/hasToc.ts @@ -1,6 +1,6 @@ import { washMarkdownContent } from "../components/MarkdownTocBar/tools"; -export function hasToc(content: string) { - const r = /#+\s+/; - return r.test(washMarkdownContent(content)); -} +const HASH_REG = /#+\s+/; + +export const hasToc = (content: string) => + HASH_REG.test(washMarkdownContent(content)); diff --git a/packages/website/utils/isIp.ts b/packages/website/utils/isIp.ts index f292885b2..902e4ea95 100644 --- a/packages/website/utils/isIp.ts +++ b/packages/website/utils/isIp.ts @@ -1,4 +1,3 @@ -export const isIp = (str: string) => { - const re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; - return re.test(str); -}; +const IP_REGEXP = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; + +export const isIp = (maybeIP: string): boolean => IP_REGEXP.test(maybeIP); diff --git a/packages/website/utils/loadConfig.ts b/packages/website/utils/loadConfig.ts index c3893cce1..8966f2a08 100644 --- a/packages/website/utils/loadConfig.ts +++ b/packages/website/utils/loadConfig.ts @@ -1,16 +1,15 @@ +const normalizeURL = (url: string) => new URL(url).toString(); + // 从环境变量中读取. export const config = { - baseUrl: washUrl(process.env.VAN_BLOG_SERVER_URL ?? "http://localhost:3000"), + baseUrl: normalizeURL( + process.env.VAN_BLOG_SERVER_URL ?? "http://localhost:3000" + ), }; -function washUrl(url: string) { - // 带反斜杠的 - const u = new URL(url); - return u.toString(); -} - // 改为服务端触发 isr // export const revalidate = {}; -export const revalidate = process.env.VAN_BLOG_REVALIDATE == 'true' - ? { revalidate: parseInt(process.env.VAN_BLOG_REVALIDATE_TIME || "10") } - : {}; +export const revalidate = + process.env.VAN_BLOG_REVALIDATE == "true" + ? { revalidate: parseInt(process.env.VAN_BLOG_REVALIDATE_TIME || "10") } + : {};