Просмотр исходного кода

remove trailing shash from prefix

Yuki Takei 2 лет назад
Родитель
Сommit
b6121d6c36

+ 2 - 2
packages/remark-lsx/src/server/routes/list-pages/index.ts

@@ -14,7 +14,7 @@ import { generateBaseQuery, type PageQuery } from './generate-base-query';
 import { getToppageViewersCount } from './get-toppage-viewers-count';
 
 
-const { addTrailingSlash } = pathUtils;
+const { addTrailingSlash, removeTrailingSlash } = pathUtils;
 
 /**
  * add filter condition that filter fetched pages
@@ -65,7 +65,7 @@ export const listPages = async(req: Request & { user: IUser }, res: Response): P
   }
 
   const params: LsxApiParams = {
-    pagePath: req.query.pagePath.toString(),
+    pagePath: removeTrailingSlash(req.query.pagePath.toString()),
     offset: req.query?.offset != null ? Number(req.query.offset) : undefined,
     limit: req.query?.limit != null ? Number(req.query?.limit) : undefined,
     options: req.query?.options != null ? JSON.parse(req.query.options.toString()) : {},

+ 2 - 2
packages/remark-lsx/src/services/renderer/lsx.ts

@@ -11,7 +11,7 @@ import { visit } from 'unist-util-visit';
 const NODE_NAME_PATTERN = new RegExp(/ls|lsx/);
 const SUPPORTED_ATTRIBUTES = ['prefix', 'num', 'depth', 'sort', 'reverse', 'filter', 'except', 'isSharedPage'];
 
-const { hasHeadingSlash } = pathUtils;
+const { hasHeadingSlash, removeTrailingSlash } = pathUtils;
 
 type DirectiveAttributes = Record<string, string>
 
@@ -70,7 +70,7 @@ const pathResolver = (href: string, basePath: string): string => {
   const baseUrl = new URL(pathUtils.addTrailingSlash(basePath), 'https://example.com');
   const relativeUrl = new URL(href, baseUrl);
 
-  return relativeUrl.pathname;
+  return removeTrailingSlash(relativeUrl.pathname);
 };
 
 export const rehypePlugin: Plugin<[LsxRehypePluginParams]> = (options = {}) => {