fumadocs-core 16.0.0 → 16.0.2

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.
@@ -5,6 +5,11 @@ import 'shiki/themes';
5
5
  import 'hast-util-to-jsx-runtime';
6
6
  import 'hast';
7
7
 
8
+ /**
9
+ * get highlighted results, should be used with React Suspense API.
10
+ *
11
+ * note: results are cached with (lang, code) as keys, if this is not the desired behaviour, pass a `deps` instead.
12
+ */
8
13
  declare function useShiki(code: string, options: HighlightOptions, deps?: DependencyList): ReactNode;
9
14
 
10
15
  export { useShiki };
@@ -5,18 +5,12 @@ import {
5
5
  import "../chunk-U67V476Y.js";
6
6
 
7
7
  // src/highlight/client.tsx
8
- import {
9
- use,
10
- useId,
11
- useMemo
12
- } from "react";
8
+ import { use, useMemo } from "react";
13
9
  var promises = {};
14
10
  function useShiki(code, options, deps) {
15
- const id = useId();
16
11
  const key = useMemo(() => {
17
- const state = deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
18
- return `${id}:${state}`;
19
- }, [code, deps, id, options.lang]);
12
+ return deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
13
+ }, [code, deps, options.lang]);
20
14
  return use(promises[key] ??= highlight(code, options));
21
15
  }
22
16
  export {
@@ -1,4 +1,4 @@
1
- import { NextMiddleware } from 'next/dist/server/web/types';
1
+ import { NextProxy } from 'next/dist/server/web/types';
2
2
  import { I18nConfig } from './index.js';
3
3
 
4
4
  interface MiddlewareOptions extends I18nConfig {
@@ -7,6 +7,6 @@ interface MiddlewareOptions extends I18nConfig {
7
7
  */
8
8
  format?: (locale: string, path: string) => string;
9
9
  }
10
- declare function createI18nMiddleware({ languages, defaultLanguage, format, hideLocale, }: MiddlewareOptions): NextMiddleware;
10
+ declare function createI18nMiddleware({ languages, defaultLanguage, format, hideLocale, }: MiddlewareOptions): NextProxy;
11
11
 
12
12
  export { createI18nMiddleware };
@@ -20,50 +20,44 @@ function createI18nMiddleware({
20
20
  format = defaultFormat,
21
21
  hideLocale = "never"
22
22
  }) {
23
- function getUrl(request, pathname, locale) {
24
- if (!locale) {
25
- return new URL(
26
- pathname.startsWith("/") ? pathname : `/${pathname}`,
27
- request.url
28
- );
29
- }
30
- return new URL(
31
- format(locale, pathname.startsWith("/") ? pathname.slice(1) : pathname),
32
- request.url
33
- );
23
+ function getLocaleUrl(request, locale) {
24
+ const next = new URL(request.url);
25
+ next.pathname = format(locale, forceSlashPrefix(request.nextUrl.pathname));
26
+ return next;
34
27
  }
35
28
  return (request) => {
36
- const inputPath = `${request.nextUrl.pathname}${request.nextUrl.search}`;
29
+ const url = request.nextUrl;
37
30
  const pathLocale = languages.find(
38
- (locale) => inputPath.startsWith(`/${locale}/`) || inputPath === `/${locale}`
31
+ (locale) => url.pathname.startsWith(`/${locale}/`) || url.pathname === `/${locale}`
39
32
  );
40
33
  if (!pathLocale) {
41
34
  if (hideLocale === "default-locale") {
42
- return NextResponse.rewrite(
43
- getUrl(request, inputPath, defaultLanguage)
44
- );
35
+ return NextResponse.rewrite(getLocaleUrl(request, defaultLanguage));
45
36
  }
46
37
  const preferred = getLocale(request, languages, defaultLanguage);
47
38
  if (hideLocale === "always") {
48
39
  const locale = request.cookies.get(COOKIE)?.value ?? preferred;
49
- return NextResponse.rewrite(getUrl(request, inputPath, locale));
40
+ return NextResponse.rewrite(getLocaleUrl(request, locale));
50
41
  }
51
- return NextResponse.redirect(getUrl(request, inputPath, preferred));
42
+ return NextResponse.redirect(getLocaleUrl(request, preferred));
52
43
  }
53
- if (hideLocale === "always") {
54
- const path = inputPath.slice(`/${pathLocale}`.length);
55
- const res = NextResponse.redirect(getUrl(request, path));
44
+ if (hideLocale === "always" || hideLocale === "default-locale" && pathLocale === defaultLanguage) {
45
+ const res = NextResponse.redirect(
46
+ new URL(
47
+ forceSlashPrefix(url.pathname.slice(`/${pathLocale}`.length)),
48
+ request.url
49
+ )
50
+ );
56
51
  res.cookies.set(COOKIE, pathLocale);
57
52
  return res;
58
53
  }
59
- if (hideLocale === "default-locale" && pathLocale === defaultLanguage) {
60
- return NextResponse.redirect(
61
- getUrl(request, inputPath.slice(`/${pathLocale}`.length))
62
- );
63
- }
64
54
  return NextResponse.next();
65
55
  };
66
56
  }
57
+ function forceSlashPrefix(v) {
58
+ if (v.startsWith("/")) return v;
59
+ return "/" + v;
60
+ }
67
61
  export {
68
62
  createI18nMiddleware
69
63
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.0.0",
3
+ "version": "16.0.2",
4
4
  "description": "The library for building a documentation website in any React.js framework",
5
5
  "keywords": [
6
6
  "Fumadocs",