@mintlify/common 1.0.1061 → 1.0.1062

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,20 @@
1
1
  import { posix } from 'path';
2
2
  import { visit } from 'unist-util-visit';
3
+ import { replaceSlashIndex } from '../../../slug/replaceSlashIndex.js';
3
4
  const isRelative = (url) => url.startsWith('./') || url.startsWith('../');
4
- const resolveRelative = (baseDir, url) => {
5
+ const resolveRelative = (baseDir, url, isPageLink) => {
5
6
  // Preserve any fragment or query string verbatim.
6
7
  const splitIndex = url.search(/[#?]/);
7
8
  const pathPart = splitIndex === -1 ? url : url.slice(0, splitIndex);
8
9
  const tail = splitIndex === -1 ? '' : url.slice(splitIndex);
9
10
  const resolved = posix.normalize(posix.join(baseDir, pathPart));
10
- const absolute = resolved.startsWith('/') && !resolved.startsWith('//') ? resolved : `/${resolved}`;
11
+ let absolute = resolved.startsWith('/') && !resolved.startsWith('//') ? resolved : `/${resolved}`;
12
+ if (isPageLink) {
13
+ const withoutExtension = absolute.replace(/\.mdx?$/i, '');
14
+ if (withoutExtension !== absolute) {
15
+ absolute = replaceSlashIndex(withoutExtension) || '/';
16
+ }
17
+ }
11
18
  return absolute + tail;
12
19
  };
13
20
  const ATTR_BY_TAG = {
@@ -28,7 +35,7 @@ export const remarkResolveRelativeLinks = (options = {}) => {
28
35
  if (node.type === 'link' || node.type === 'image') {
29
36
  const linkOrImg = node;
30
37
  if (linkOrImg.url && isRelative(linkOrImg.url)) {
31
- linkOrImg.url = resolveRelative(baseDir, linkOrImg.url);
38
+ linkOrImg.url = resolveRelative(baseDir, linkOrImg.url, node.type === 'link');
32
39
  }
33
40
  return;
34
41
  }
@@ -41,7 +48,7 @@ export const remarkResolveRelativeLinks = (options = {}) => {
41
48
  return;
42
49
  const attr = jsxNode.attributes.find((a) => a.type === 'mdxJsxAttribute' && a.name === attrName);
43
50
  if (attr && 'value' in attr && typeof attr.value === 'string' && isRelative(attr.value)) {
44
- attr.value = resolveRelative(baseDir, attr.value);
51
+ attr.value = resolveRelative(baseDir, attr.value, attrName === 'href');
45
52
  }
46
53
  });
47
54
  };