Skip to content

Commit

Permalink
perf(generator): use regex to match domain
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Feb 18, 2024
1 parent c3a2c90 commit 59b94e5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ function addConfig(module: string, base: string) {

const url = new URL(base)
const hostname = url.hostname
const parts = hostname.split('.')
const mainDomain = parts.slice(-3).join('.') // 拿到根域名
// 检查一下 hostnames 里面有没有这个根域名,没有的话就加进去
const regex = /(?:https?:\/\/)?(?:www\.)?([^\/]+)\/?.*/
const mainDomain = hostname.match(regex)?.[1] || hostname
// 检查一下 hostnames 里面有没有这个域名,没有的话就加进去
if (!hostnames.includes(`${mainDomain}`))
hostnames.push(`${mainDomain}`)

Expand Down

0 comments on commit 59b94e5

Please sign in to comment.