Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Mar 2, 2023
1 parent 497434b commit 102f360
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/website/components/MarkdownTocBar/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface NavItem {
listNo: string;
text: string;
}

export const washMarkdownContent = (source: string) => {
if (!source) return "";
return (
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions packages/website/utils/hasToc.ts
Original file line number Diff line number Diff line change
@@ -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));
7 changes: 3 additions & 4 deletions packages/website/utils/isIp.ts
Original file line number Diff line number Diff line change
@@ -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);
19 changes: 9 additions & 10 deletions packages/website/utils/loadConfig.ts
Original file line number Diff line number Diff line change
@@ -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") }
: {};

0 comments on commit 102f360

Please sign in to comment.