Skip to content

Commit

Permalink
fix(docs): prevent duplicate package name replacement in UseFunnelImp…
Browse files Browse the repository at this point in the history
…ortReplace (#116)

* fix(docs): prevent duplicate package name replacement in UseFunnelImportReplace

* refactor(docs): Improve code readability
  • Loading branch information
LimChaeJune authored Feb 24, 2025
1 parent 560723a commit 0877d04
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions docs/src/components/UseFunnelCodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ function UseFunnelImportReplace({
.forEach((line) => {
const tokens = Array.from(line.querySelectorAll('[style*="token-string-expression"]'));
tokens.forEach((token) => {
for (const targetPackage of useFunnelPackages) {
if (token.textContent?.includes(targetPackage.packageName)) {
token.textContent = token.textContent.replace(targetPackage.packageName, packageName);
}
const matchingPackage = useFunnelPackages.find((pkg) => token.textContent?.includes(pkg.packageName));

if (!matchingPackage || !token.textContent) return;

const content = token.textContent.replace(/['"]/g, '');
const [prefix, packagePath] = content.split('@use-funnel/');

if (packagePath === matchingPackage.packageName) {
token.textContent = `"${prefix}@use-funnel/${packageName}"`;
}
});
});
Expand Down

0 comments on commit 0877d04

Please sign in to comment.