From 97d747020177781b0901efcfcf90b9a7b871125e Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Thu, 13 Jun 2024 23:07:26 +0800 Subject: [PATCH] fix: don't encode url for copy, support route param with regex (#1017) * fix: don't encode url for copy * fix: always rendering * fix: support route with regex --- src/lib/rsshub.ts | 7 +++++++ src/popup/RSSItem.tsx | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/rsshub.ts b/src/lib/rsshub.ts index 723dc44..53145bc 100644 --- a/src/lib/rsshub.ts +++ b/src/lib/rsshub.ts @@ -17,6 +17,13 @@ function ruleHandler(rule: Rule, params, url, html, success, fail) { resultWithParams = rule.target } + // clean params with regex requirements + // /npm/package/:name{(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*} -> /npm/package/:name + resultWithParams = resultWithParams.replace( + /\/:\w+\{[^}]*\}(?=\/|$)/g, + (match) => match.replace(/\{[^}]*\}/, ""), + ) + if (resultWithParams) { // if no :param in resultWithParams, requiredParams will be null // in that case, just skip the following steps and return resultWithParams diff --git a/src/popup/RSSItem.tsx b/src/popup/RSSItem.tsx index 4ddb00f..423a602 100644 --- a/src/popup/RSSItem.tsx +++ b/src/popup/RSSItem.tsx @@ -19,7 +19,9 @@ function RSSItem({ hidePreview?: boolean }) { const [config, setConfig] = useState(defaultConfig) - getConfig().then(setConfig) + useEffect(() => { + getConfig().then(setConfig) + }, []) const [_, copy] = useCopyToClipboard() const [copied, setCopied] = useState(false) useEffect(() => { @@ -43,7 +45,6 @@ function RSSItem({ chrome.i18n.getMessage("current"), ) } - url = encodeURI(url) const encodedUrl = encodeURIComponent(url) return (