@vuepress_shared.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // node_modules/@vuepress/shared/dist/index.js
  2. var isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith("//");
  3. var markdownLinkRegexp = /.md((\?|#).*)?$/;
  4. var isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || // absolute link that does not start with `base` and does not end with `.md`
  5. link.startsWith("/") && !link.startsWith(base) && !markdownLinkRegexp.test(link);
  6. var isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
  7. var inferRoutePath = (rawPath) => {
  8. if (!rawPath || rawPath.endsWith("/")) return rawPath;
  9. let routePath = rawPath.replace(/(^|\/)README.md$/i, "$1index.html");
  10. if (routePath.endsWith(".md")) {
  11. routePath = `${routePath.substring(0, routePath.length - 3)}.html`;
  12. } else if (!routePath.endsWith(".html")) {
  13. routePath = `${routePath}.html`;
  14. }
  15. if (routePath.endsWith("/index.html")) {
  16. routePath = routePath.substring(0, routePath.length - 10);
  17. }
  18. return routePath;
  19. };
  20. var FAKE_HOST = "http://.";
  21. var normalizeRoutePath = (pathname, current) => {
  22. if (!pathname.startsWith("/") && current) {
  23. const loc = current.slice(0, current.lastIndexOf("/"));
  24. return inferRoutePath(new URL(`${loc}/${pathname}`, FAKE_HOST).pathname);
  25. }
  26. return inferRoutePath(pathname);
  27. };
  28. var resolveLocalePath = (locales, routePath) => {
  29. const localePaths = Object.keys(locales).sort((a, b) => {
  30. const levelDelta = b.split("/").length - a.split("/").length;
  31. if (levelDelta !== 0) {
  32. return levelDelta;
  33. }
  34. return b.length - a.length;
  35. });
  36. for (const localePath of localePaths) {
  37. if (routePath.startsWith(localePath)) {
  38. return localePath;
  39. }
  40. }
  41. return "/";
  42. };
  43. var resolveRoutePathFromUrl = (url, base = "/") => {
  44. const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
  45. return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
  46. };
  47. var SPLIT_CHAR_REGEXP = /(#|\?)/;
  48. var splitPath = (path) => {
  49. const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP);
  50. return {
  51. pathname,
  52. hashAndQueries: hashAndQueries.join("")
  53. };
  54. };
  55. var TAGS_ALLOWED = ["link", "meta", "script", "style", "noscript", "template"];
  56. var TAGS_UNIQUE = ["title", "base"];
  57. var resolveHeadIdentifier = ([tag, attrs, content]) => {
  58. if (TAGS_UNIQUE.includes(tag)) {
  59. return tag;
  60. }
  61. if (!TAGS_ALLOWED.includes(tag)) {
  62. return null;
  63. }
  64. if (tag === "meta" && attrs.name) {
  65. return `${tag}.${attrs.name}`;
  66. }
  67. if (tag === "template" && attrs.id) {
  68. return `${tag}.${attrs.id}`;
  69. }
  70. return JSON.stringify([
  71. tag,
  72. Object.entries(attrs).map(([key, value]) => {
  73. if (typeof value === "boolean") {
  74. return value ? [key, ""] : null;
  75. }
  76. return [key, value];
  77. }).filter((item) => item != null).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
  78. content
  79. ]);
  80. };
  81. var dedupeHead = (head) => {
  82. const identifierSet = /* @__PURE__ */ new Set();
  83. const result = [];
  84. head.forEach((item) => {
  85. const identifier = resolveHeadIdentifier(item);
  86. if (identifier && !identifierSet.has(identifier)) {
  87. identifierSet.add(identifier);
  88. result.push(item);
  89. }
  90. });
  91. return result;
  92. };
  93. var ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
  94. var ensureEndingSlash = (str) => str.endsWith("/") || str.endsWith(".html") ? str : `${str}/`;
  95. var formatDateString = (str, defaultDateString = "") => {
  96. const dateMatch = str.match(/\b(\d{4})-(\d{1,2})-(\d{1,2})\b/);
  97. if (dateMatch === null) {
  98. return defaultDateString;
  99. }
  100. const [, yearStr, monthStr, dayStr] = dateMatch;
  101. return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
  102. };
  103. var omit = (obj, ...keys) => {
  104. const result = { ...obj };
  105. for (const key of keys) {
  106. delete result[key];
  107. }
  108. return result;
  109. };
  110. var removeEndingSlash = (str) => str.endsWith("/") ? str.slice(0, -1) : str;
  111. var removeLeadingSlash = (str) => str.startsWith("/") ? str.slice(1) : str;
  112. var isFunction = (val) => typeof val === "function";
  113. var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
  114. var isString = (val) => typeof val === "string";
  115. export {
  116. dedupeHead,
  117. ensureEndingSlash,
  118. ensureLeadingSlash,
  119. formatDateString,
  120. inferRoutePath,
  121. isFunction,
  122. isLinkExternal,
  123. isLinkHttp,
  124. isLinkWithProtocol,
  125. isPlainObject,
  126. isString,
  127. normalizeRoutePath,
  128. omit,
  129. removeEndingSlash,
  130. removeLeadingSlash,
  131. resolveHeadIdentifier,
  132. resolveLocalePath,
  133. resolveRoutePathFromUrl,
  134. splitPath
  135. };
  136. //# sourceMappingURL=@vuepress_shared.js.map