Răsfoiți Sursa

refs 120355: fix prefix

Futa Arai 3 ani în urmă
părinte
comite
0a4342531f

+ 1 - 4
packages/remark-attachment-refs/src/client/components/Ref.tsx

@@ -18,10 +18,7 @@ const RefSubstance = React.memo(({
   isImmutable,
 }: Props): JSX.Element => {
   const refsContext = useMemo(() => {
-    const options = {
-      fileNameOrId, pagePath,
-    };
-    return new RefsContext('ref', options);
+    return new RefsContext('ref', pagePath, { fileNameOrId });
   }, [fileNameOrId, pagePath]);
 
   const { data, error, isLoading } = useSWRxRef(pagePath, fileNameOrId, isImmutable);

+ 2 - 2
packages/remark-attachment-refs/src/client/components/RefImg.tsx

@@ -30,9 +30,9 @@ const RefImgSubstance = React.memo(({
 }: Props): JSX.Element => {
   const refsContext = useMemo(() => {
     const options = {
-      fileNameOrId, pagePath, width, height, maxWidth, maxHeight, alt,
+      fileNameOrId, width, height, maxWidth, maxHeight, alt,
     };
-    return new RefsContext('refimg', options);
+    return new RefsContext('refimg', pagePath, options);
   }, [fileNameOrId, pagePath, width, height, maxWidth, maxHeight, alt]);
 
   const { data, error, isLoading } = useSWRxRef(pagePath, fileNameOrId, isImmutable);

+ 2 - 2
packages/remark-attachment-refs/src/client/components/Refs.tsx

@@ -25,9 +25,9 @@ const RefsSubstance = React.memo(({
 }: Props): JSX.Element => {
   const refsContext = useMemo(() => {
     const options = {
-      pagePath, prefix, depth, regexp,
+      prefix, depth, regexp,
     };
-    return new RefsContext('refs', options);
+    return new RefsContext('refs', pagePath, options);
   }, [pagePath, prefix, depth, regexp]);
 
   const { data, error, isLoading } = useSWRxRefs(pagePath, prefix, { depth, regexp }, isImmutable);

+ 4 - 4
packages/remark-attachment-refs/src/client/components/RefsImg.tsx

@@ -24,7 +24,7 @@ type Props = {
 };
 
 const RefsImgSubstance = React.memo(({
-  prefix, pagePath, depth, regexp,
+  pagePath, prefix, depth, regexp,
   width, height, maxWidth, maxHeight,
   display, grid, gridGap, noCarousel,
 
@@ -32,8 +32,8 @@ const RefsImgSubstance = React.memo(({
 }: Props): JSX.Element => {
   const refsContext = useMemo(() => {
     const options = {
-      prefix,
       pagePath,
+      prefix,
       depth,
       regexp,
       width,
@@ -45,8 +45,8 @@ const RefsImgSubstance = React.memo(({
       gridGap,
       noCarousel,
     };
-    return new RefsContext('refsimg', options);
-  }, [prefix, pagePath, depth, regexp,
+    return new RefsContext('refsimg', pagePath, options);
+  }, [pagePath, prefix, depth, regexp,
       width, height, maxWidth, maxHeight,
       display, grid, gridGap, noCarousel]);
 

+ 6 - 2
packages/remark-attachment-refs/src/client/components/util/refs-context.ts

@@ -22,11 +22,15 @@ export class RefsContext {
 
   tag: tags;
 
+  pagePath: string;
+
   options?: Record<string, string|undefined>;
 
-  constructor(tag: tags, options: Record<string, string|undefined>) {
+  constructor(tag: tags, pagePath: string, options: Record<string, string|undefined>) {
     this.tag = tag;
 
+    this.pagePath = pagePath;
+
     // remove undefined keys
     Object.keys(options).forEach(key => options[key] === undefined && delete options[key]);
 
@@ -34,7 +38,7 @@ export class RefsContext {
   }
 
   getStringifiedAttributes(separator = ', '): string {
-    const attributeStrs: string[] = [];
+    const attributeStrs = [`page=${this.pagePath}`];
     if (this.options != null) {
       const optionEntries = Object.entries(this.options).sort();
       attributeStrs.push(

+ 7 - 1
packages/remark-attachment-refs/src/client/services/renderer/refs.ts

@@ -113,8 +113,14 @@ export const rehypePlugin: Plugin<[RefRehypePluginParams]> = (options = {}) => {
         return;
       }
 
+      const prefix = refElem.properties.prefix;
+      // set basePagePath when prefix is undefined or invalid
+      if (prefix != null && typeof prefix === 'string') {
+        refElem.properties.prefix = decodeURI(pathResolver(prefix, basePagePath));
+      }
+
       refElem.properties.pagePath = refElem.properties.page;
-      const pagePath = refElem.properties.pag1ePath;
+      const pagePath = refElem.properties.pagePath;
 
       // set basePagePath when pagePath is undefined or invalid
       if (pagePath == null || typeof pagePath !== 'string') {