Skip to content

Commit

Permalink
feat: 简化参数 search 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
rowthan committed Aug 25, 2024
1 parent 3d4159b commit cc03b25
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
24 changes: 17 additions & 7 deletions apps/web/components/form/UrlRuleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,46 @@ export default function UrlRuleForm(props: Props) {
</FormLabel>
<FormDescription>
将不同网址认定为同一个网址的规则。如
https://pagenote.cn/author#line1?from=a
https://pagenote.cn/author#line2?from=b
https://pagenote.cn/author#line1?from=web
https://pagenote.cn/author#line2?from=app
经过格式化、忽略无关的URL参数后,处理为 https://pagenote.cn/author
</FormDescription>
<FormControl>
<Textarea className={''} placeholder={`如:${demoTemplate}`} {...field} />
</FormControl>
<div>
<FormDescription>
<b className={'text-red-500'}>[]</b> 为变量占位符,支持以下几种类型:
</FormDescription>
<ul>
<li>
<FormDescription>
1. [origin] 表示服务器主机地址,对应如 https://pagenote.cn
1. [origin] 表示服务器主机地址,替换后如 <b>https://pagenote.cn</b>
</FormDescription>
</li>
<li>
<FormDescription>
2. [pathname] 表示网址路径地址,对应 /author
2. [pathname] 表示网址路径地址,替换后如 <b>/author</b>
</FormDescription>
</li>
<li>
<FormDescription>
2. [hash] 表示网址路径hash地址,对应如 #line1
2. [hash] 表示网址路径hash地址,替换后如 <b>#line1</b>
</FormDescription>
</li>
<li>
<FormDescription>
3. [search] 表示网址中的所有参数
3. [search] 表示网址中的所有参数,替换后如 <b>?a=1&b=2</b>
</FormDescription>
</li>
<li>
<FormDescription>
4. [searchParams.from] 表示单独获取参数名为 from 的变量值,替换后如 <b>web/app</b>
</FormDescription>
</li>
<li>
<FormDescription>
4. [searchParams.a] 表示单独获取参数名为 a 的变量
5. [?:from,b,c] 表示保留URL中的参数白名单列表: from,b,c。替换结果如 <b>from=web&b=2&c=3</b>
</FormDescription>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/popup/Achieve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Achieve() {
<div className={'flex gap-4 items-center'}>
<CaptureButton pageUrl={content?.pageUrl || tab?.url || ''} pageKey={content?.pageKey || content?.pageUrl || tab?.url || ''} />
<PageInfo pageUrl={content?.pageUrl || tab?.url || ''} />
<LightInfo pageUrl={content?.pageUrl || tab?.url || ''} />
<LightInfo pageKey={content?.pageKey || tab?.url || ''} />
</div>
<DisableButton />
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/popup/state/PageInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export function PageInfo(props:{pageUrl: string}) {
)
}

export function LightInfo(props:{pageUrl: string}) {
export function LightInfo(props:{pageKey: string}) {
const { data: lights } = useTableQuery<Step>(Collection.light, {
limit: 999,
query: {
pageKey: props.pageUrl,
pageKey: props.pageKey,
},
projection: {
lightId: 1,
Expand Down
23 changes: 14 additions & 9 deletions apps/web/components/setting/LinkedRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ interface Props {
children?: ReactNode;
}


const KEYS = ["DBCODE","dbcode","dbname","FileName","filename","TABLEName"]
const PRESET_RULES: Record<string, Config[]> = {
zhiwang: [{
key: 'ZHIWANG_PRESET_XML_READ_XML',
matchUrl: 'https://kns.cnki.net/nzkhtml/xmlRead/xml.html*',
template: '[origin][pathname]?fileName=[searchParams.fileName]&tableName=[searchParams.tableName]&dbCode=[searchParams.dbCode]&fileSourceType=[searchParams.fileSourceType]'
},{
key: 'ZHIWANG_PRESET_XML_TRIAL_READ_XML',
matchUrl: 'https://x.cnki.net/web/trilalread/article/trialXmlRead.html*',
template: '[origin][pathname]?fileName=[searchParams.fileName]&tableName=[searchParams.tableName]&dbCode=[searchParams.dbCode]&fileSourceType=[searchParams.fileSourceType]'
}]
zhiwang: [
{
key: "CNKI_NET",
matchUrl: 'https://www.cnki.net/*',
template: `[origin][pathname]?[?:${KEYS.toString()}]&title=[title]`
},
{
key: "KNS_CNKI_NET",
matchUrl: 'https://kns.cnki.net/*',
template: `[origin][pathname]?[?:${KEYS.toString()}]&title=[title]`
},
]
}

const KEY_PREFIX = 'extension.linkRule.'
Expand Down

0 comments on commit cc03b25

Please sign in to comment.