@koine/next 2.0.0-beta.4 → 2.0.0-beta.41
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.
- package/12/AnalyticsGoogle.d.ts +0 -1
- package/12/DisableErrorOverlay.d.ts +0 -5
- package/12/NextProgress.d.ts +1 -4
- package/12/Seo.d.ts +0 -24
- package/12/SeoDefaults.d.ts +0 -3
- package/12/seoBuildTags.d.ts +0 -15
- package/12/types-seo.d.ts +0 -0
- package/12/types.d.ts +1 -0
- package/12.cjs.d.ts +1 -0
- package/12.cjs.default.js +1 -0
- package/12.cjs.js +28 -0
- package/12.cjs.mjs +2 -0
- package/12.d.ts +3 -0
- package/12.esm.js +18 -0
- package/config.cjs.d.ts +1 -0
- package/config.cjs.default.js +1 -0
- package/config.cjs.js +9 -0
- package/config.cjs.mjs +2 -0
- package/config.d.ts +106 -0
- package/config.esm.js +5 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +25 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +4 -2
- package/index.esm.js +14 -0
- package/package.json +28 -83
- package/theme/ThemeContext.d.ts +11 -0
- package/theme/ThemeProvider.d.ts +17 -0
- package/theme/useTheme.d.ts +4 -0
- package/utils/load.d.ts +1 -0
- package/12/AnalyticsGoogle.js +0 -79
- package/12/AnalyticsGoogle.mjs +0 -60
- package/12/DisableErrorOverlay.js +0 -31
- package/12/DisableErrorOverlay.mjs +0 -16
- package/12/DynamicNamespaces.d.ts +0 -13
- package/12/DynamicNamespaces.js +0 -23
- package/12/DynamicNamespaces.mjs +0 -8
- package/12/Favicon.d.ts +0 -4
- package/12/Favicon.js +0 -29
- package/12/Favicon.mjs +0 -10
- package/12/Link.d.ts +0 -10
- package/12/Link.js +0 -38
- package/12/Link.mjs +0 -20
- package/12/NextProgress.js +0 -69
- package/12/NextProgress.mjs +0 -51
- package/12/Seo.js +0 -29
- package/12/Seo.mjs +0 -30
- package/12/SeoDefaults.js +0 -31
- package/12/SeoDefaults.mjs +0 -14
- package/12/T.d.ts +0 -16
- package/12/T.js +0 -43
- package/12/T.mjs +0 -27
- package/12/ThemeContext.d.ts +0 -17
- package/12/ThemeContext.js +0 -25
- package/12/ThemeContext.mjs +0 -7
- package/12/ThemeProvider.d.ts +0 -35
- package/12/ThemeProvider.js +0 -256
- package/12/ThemeProvider.mjs +0 -245
- package/12/TransText.d.ts +0 -3
- package/12/TransText.js +0 -23
- package/12/TransText.mjs +0 -4
- package/12/app/AppHead.d.ts +0 -3
- package/12/app/AppHead.js +0 -31
- package/12/app/AppHead.mjs +0 -12
- package/12/app/AppMain.d.ts +0 -35
- package/12/app/AppMain.js +0 -6
- package/12/app/AppMain.mjs +0 -1
- package/12/app/css/AppMain.d.ts +0 -9
- package/12/app/css/AppMain.js +0 -39
- package/12/app/css/AppMain.mjs +0 -24
- package/12/app/css/AppTheme.d.ts +0 -11
- package/12/app/css/AppTheme.js +0 -33
- package/12/app/css/AppTheme.mjs +0 -17
- package/12/app/css/auth/index.d.ts +0 -11
- package/12/app/css/auth/index.js +0 -40
- package/12/app/css/auth/index.mjs +0 -24
- package/12/app/css/index.d.ts +0 -54
- package/12/app/css/index.js +0 -36
- package/12/app/css/index.mjs +0 -65
- package/12/app/index.d.ts +0 -2
- package/12/app/index.js +0 -7
- package/12/app/index.mjs +0 -2
- package/12/app/sc/AppMain.d.ts +0 -11
- package/12/app/sc/AppMain.js +0 -70
- package/12/app/sc/AppMain.mjs +0 -58
- package/12/app/sc/AppTheme.d.ts +0 -14
- package/12/app/sc/AppTheme.js +0 -33
- package/12/app/sc/AppTheme.mjs +0 -16
- package/12/app/sc/auth/index.d.ts +0 -11
- package/12/app/sc/auth/index.js +0 -40
- package/12/app/sc/auth/index.mjs +0 -24
- package/12/app/sc/index.d.ts +0 -56
- package/12/app/sc/index.js +0 -36
- package/12/app/sc/index.mjs +0 -67
- package/12/document/Document.d.ts +0 -15
- package/12/document/Document.js +0 -49
- package/12/document/Document.mjs +0 -38
- package/12/document/css/index.d.ts +0 -17
- package/12/document/css/index.js +0 -60
- package/12/document/css/index.mjs +0 -53
- package/12/document/index.d.ts +0 -2
- package/12/document/index.js +0 -19
- package/12/document/index.mjs +0 -2
- package/12/document/sc/index.d.ts +0 -19
- package/12/document/sc/index.js +0 -73
- package/12/document/sc/index.mjs +0 -65
- package/12/getT.d.ts +0 -9
- package/12/getT.js +0 -23
- package/12/getT.mjs +0 -8
- package/12/index.d.ts +0 -24
- package/12/index.js +0 -100
- package/12/index.mjs +0 -27
- package/12/seoBuildTags.js +0 -126
- package/12/seoBuildTags.mjs +0 -121
- package/12/to.d.ts +0 -24
- package/12/to.js +0 -31
- package/12/to.mjs +0 -19
- package/12/translationAsOptions.d.ts +0 -3
- package/12/translationAsOptions.js +0 -19
- package/12/translationAsOptions.mjs +0 -9
- package/12/types-i18n.d.ts +0 -118
- package/12/types-i18n.js +0 -15
- package/12/types-i18n.mjs +0 -12
- package/12/types-seo.js +0 -4
- package/12/types-seo.mjs +0 -1
- package/12/useBackUrl.d.ts +0 -2
- package/12/useBackUrl.js +0 -47
- package/12/useBackUrl.mjs +0 -28
- package/12/useDateFormat.d.ts +0 -7
- package/12/useDateFormat.js +0 -42
- package/12/useDateFormat.mjs +0 -26
- package/12/useForm.d.ts +0 -27
- package/12/useForm.js +0 -65
- package/12/useForm.mjs +0 -47
- package/12/useLocale.d.ts +0 -2
- package/12/useLocale.js +0 -25
- package/12/useLocale.mjs +0 -6
- package/12/useT.d.ts +0 -4
- package/12/useT.js +0 -58
- package/12/useT.mjs +0 -39
- package/12/useTheme.d.ts +0 -7
- package/12/useTheme.js +0 -23
- package/12/useTheme.mjs +0 -7
- package/12/useTo.d.ts +0 -3
- package/12/useTo.js +0 -26
- package/12/useTo.mjs +0 -8
- package/config/index.d.ts +0 -160
- package/config/index.js +0 -317
- package/config/index.mjs +0 -315
- package/getSiteUrl.d.ts +0 -8
- package/getSiteUrl.js +0 -24
- package/getSiteUrl.mjs +0 -10
- package/index.js +0 -20
- package/index.mjs +0 -2
- package/load.d.ts +0 -10
- package/load.js +0 -31
- package/load.mjs +0 -13
- package/typings.d.ts +0 -72
package/config/index.d.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import type { NextConfig } from "next";
|
|
2
|
-
import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
|
|
3
|
-
type Route = string | {
|
|
4
|
-
[key: string]: Route | string;
|
|
5
|
-
};
|
|
6
|
-
type Routes = Record<string, Route>;
|
|
7
|
-
type RoutesMapRoute = {
|
|
8
|
-
template: string;
|
|
9
|
-
pathname: string;
|
|
10
|
-
wildcard?: boolean;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Normalise pathname
|
|
14
|
-
*
|
|
15
|
-
* From a path like `/some//malformed/path///` it returns `some/malformed/path`
|
|
16
|
-
*
|
|
17
|
-
* - Removes subsequent slashes
|
|
18
|
-
* - Removing initial and ending slashes
|
|
19
|
-
* - Returns an empty string `"""` if only slashes are given
|
|
20
|
-
*/
|
|
21
|
-
export declare function normaliseUrlPathname(pathname?: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Transform to path any absolute or relative URL
|
|
24
|
-
*
|
|
25
|
-
* Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
|
|
26
|
-
* setup](https://nextjs.org/docs/advanced-features/multi-zones).
|
|
27
|
-
*
|
|
28
|
-
* From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
|
|
29
|
-
*
|
|
30
|
-
* @see {@link normaliseUrlPathname}
|
|
31
|
-
*/
|
|
32
|
-
export declare function toPath(urlOrPathname?: string): string;
|
|
33
|
-
/**
|
|
34
|
-
* Clean a pathname and encode each part
|
|
35
|
-
*
|
|
36
|
-
* @see {@link normaliseUrlPathname}
|
|
37
|
-
*/
|
|
38
|
-
export declare function encodePathname(pathname?: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Get path rewrite
|
|
41
|
-
*/
|
|
42
|
-
export declare function getPathRewrite(route: RoutesMapRoute): {
|
|
43
|
-
source: string;
|
|
44
|
-
destination: string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Get path redirect
|
|
48
|
-
*/
|
|
49
|
-
export declare function getPathRedirect(locale: string | undefined, route: RoutesMapRoute, permanent?: boolean): {
|
|
50
|
-
source: string;
|
|
51
|
-
destination: string;
|
|
52
|
-
permanent: boolean;
|
|
53
|
-
locale: false;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
*/
|
|
57
|
-
export declare function getRedirects(defaultLocale: string, routes: Routes, permanent?: boolean, debug?: boolean): Promise<Redirect[]>;
|
|
58
|
-
/**
|
|
59
|
-
*/
|
|
60
|
-
export declare function getRewrites(routes: Routes, debug?: boolean): Promise<Rewrite[]>;
|
|
61
|
-
type KoineNextConfig = {
|
|
62
|
-
/** @default true Nx monorepo setup */
|
|
63
|
-
nx?: boolean;
|
|
64
|
-
/** @default true Svg to react components */
|
|
65
|
-
svg?: boolean;
|
|
66
|
-
/** @default true Styled components enabled */
|
|
67
|
-
sc?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* When true uses `*.page.ts` or `*.page.tsx` extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory). When `true` it enables the same for `next-translate`
|
|
70
|
-
* @default false
|
|
71
|
-
*/
|
|
72
|
-
page?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* A JSON file containing the routes definition mapping template folders
|
|
75
|
-
* to localised slugs. It supports slugs's dynamic portions.
|
|
76
|
-
* All translated slugs needs to be defined starting from root `/`.
|
|
77
|
-
* The `require("...json")` file for each locale should look like:
|
|
78
|
-
*
|
|
79
|
-
* ```json
|
|
80
|
-
* {
|
|
81
|
-
* "home": "/",
|
|
82
|
-
* "products": {
|
|
83
|
-
* "list": "/products",
|
|
84
|
-
* "[category]": "/products/{{ category }}",
|
|
85
|
-
* "[tag]": {
|
|
86
|
-
* "view": "/products/{{ category }}/{{ tag }}",
|
|
87
|
-
* "related": "/products/{{ category }}/{{ tag }}/related"
|
|
88
|
-
* }
|
|
89
|
-
* },
|
|
90
|
-
* "company": {
|
|
91
|
-
* "about": "/about",
|
|
92
|
-
* "contact": "/contact"
|
|
93
|
-
* }
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* Here we also account for wildcards, those should only be defined in the
|
|
98
|
-
* pathname part of the JSON file, e.g.:
|
|
99
|
-
*
|
|
100
|
-
* ```json
|
|
101
|
-
* {
|
|
102
|
-
* "category": {
|
|
103
|
-
* "[slug]": {
|
|
104
|
-
* "[id]": "/categories/{{ slug }}/{{ id }}*"
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
* This might be desired when we want to have param-based pagination, e.g. when
|
|
110
|
-
* we have the following folder structure:
|
|
111
|
-
*
|
|
112
|
-
* ```yml
|
|
113
|
-
* |__/category
|
|
114
|
-
* |__/[slug]
|
|
115
|
-
* |__/[id]
|
|
116
|
-
* |__/[[...page]].tsx
|
|
117
|
-
* ```
|
|
118
|
-
*
|
|
119
|
-
* NOTE1:
|
|
120
|
-
* You cannot name your dynamic template file "index.tsx" when they have nested
|
|
121
|
-
* segments or the rewrites won't work. So while this is allowed:
|
|
122
|
-
* `/pages/cats/[category]/index.tsx` it is not when you also have e.g.:
|
|
123
|
-
* `/pages/cats/[category]/reviews.tsx`
|
|
124
|
-
* TODO: This might be fixable? Is this fixed now?
|
|
125
|
-
*
|
|
126
|
-
* NOTE2:
|
|
127
|
-
* When `routes` is used be sure to pass before than the `i18n.defaultLocale`
|
|
128
|
-
* configuration. That is used for localised routing. By default we set `i18n`
|
|
129
|
-
* as such:
|
|
130
|
-
* ```js
|
|
131
|
-
* {
|
|
132
|
-
* // ...nextConfig,
|
|
133
|
-
* i18n: {
|
|
134
|
-
* defaultLocale: "en",
|
|
135
|
-
* locales: ["en"],
|
|
136
|
-
* }
|
|
137
|
-
* }
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
routes?: Routes;
|
|
141
|
-
/**
|
|
142
|
-
* Whether the routes redirecting should be permanent. Switch this on once you
|
|
143
|
-
* go live and the routes structure is stable.
|
|
144
|
-
*/
|
|
145
|
-
permanent?: boolean;
|
|
146
|
-
debug?: boolean;
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Get Next.js config with some basic opinionated defaults
|
|
150
|
-
*
|
|
151
|
-
* @param {object} options
|
|
152
|
-
* @property {boolean} [options.nx=false] Nx monorepo setup
|
|
153
|
-
* @property {boolean} [options.svg=false] Svg to react components
|
|
154
|
-
* @property {boolean} [options.sc=false] Styled components enabled
|
|
155
|
-
* @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
|
|
156
|
-
* extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory)
|
|
157
|
-
* and it enables the same for `next-translate`.
|
|
158
|
-
*/
|
|
159
|
-
export declare function withKoine({ nx, svg, sc, page, routes, permanent, debug, ...custom }?: NextConfig & KoineNextConfig): NextConfig;
|
|
160
|
-
export default withKoine;
|
package/config/index.js
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
normaliseUrlPathname: function() {
|
|
13
|
-
return normaliseUrlPathname;
|
|
14
|
-
},
|
|
15
|
-
toPath: function() {
|
|
16
|
-
return toPath;
|
|
17
|
-
},
|
|
18
|
-
encodePathname: function() {
|
|
19
|
-
return encodePathname;
|
|
20
|
-
},
|
|
21
|
-
getPathRewrite: function() {
|
|
22
|
-
return getPathRewrite;
|
|
23
|
-
},
|
|
24
|
-
getPathRedirect: function() {
|
|
25
|
-
return getPathRedirect;
|
|
26
|
-
},
|
|
27
|
-
getRedirects: function() {
|
|
28
|
-
return getRedirects;
|
|
29
|
-
},
|
|
30
|
-
getRewrites: function() {
|
|
31
|
-
return getRewrites;
|
|
32
|
-
},
|
|
33
|
-
withKoine: function() {
|
|
34
|
-
return withKoine;
|
|
35
|
-
},
|
|
36
|
-
default: function() {
|
|
37
|
-
return _default;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
function normaliseUrlPathname(pathname = "") {
|
|
41
|
-
// with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
42
|
-
// we would instead return a single slash if only slashes are given
|
|
43
|
-
return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
|
|
44
|
-
}
|
|
45
|
-
function toPath(urlOrPathname = "") {
|
|
46
|
-
let pathname = "";
|
|
47
|
-
try {
|
|
48
|
-
const parsed = new URL(urlOrPathname);
|
|
49
|
-
pathname = parsed.pathname;
|
|
50
|
-
} catch (e) {
|
|
51
|
-
pathname = urlOrPathname;
|
|
52
|
-
}
|
|
53
|
-
// with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
|
|
54
|
-
// we would instead return a single slash if only slashes are given
|
|
55
|
-
return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
|
|
56
|
-
}
|
|
57
|
-
function encodePathname(pathname = "") {
|
|
58
|
-
const parts = normaliseUrlPathname(pathname).split("/");
|
|
59
|
-
return parts.filter((part)=>!!part).map((part)=>encodeURIComponent(part)).join("/");
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Transform the route translated defintion into a `pathname` and a `template`.
|
|
63
|
-
*
|
|
64
|
-
* Here we add the wildcard flag maybe found in the pathname to the template
|
|
65
|
-
* name too, this is because we do not want to have the wildcard in the JSON
|
|
66
|
-
* keys as those are also used to produce links throught the `useTo` hook and
|
|
67
|
-
* having asterisks there is a bit cumbersome.
|
|
68
|
-
*
|
|
69
|
-
* @see https://nextjs.org/docs/messages/invalid-multi-match
|
|
70
|
-
*/ function transformRoute(route) {
|
|
71
|
-
const { pathname: rawPathname, template: rawTemplate } = route;
|
|
72
|
-
const pathnameParts = rawPathname.split("/").filter((part)=>!!part);
|
|
73
|
-
const templateParts = rawTemplate.split("/").filter((part)=>!!part);
|
|
74
|
-
const mapPartsByIdx = {};
|
|
75
|
-
const pathname = pathnameParts.map((part)=>{
|
|
76
|
-
const hasWildcard = part.endsWith("*");
|
|
77
|
-
part = part.replace("*", "");
|
|
78
|
-
const isDynamic = part.startsWith("{{") && part.endsWith("}}");
|
|
79
|
-
const asValue = isDynamic ? part.match(/{{(.+)}}/)?.[1].trim() ?? "" : part.trim();
|
|
80
|
-
const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
|
|
81
|
-
mapPartsByIdx[asValue] = {
|
|
82
|
-
isDynamic,
|
|
83
|
-
hasWildcard
|
|
84
|
-
};
|
|
85
|
-
return isDynamic ? `:${asPath}` : asPath;
|
|
86
|
-
}).join("/");
|
|
87
|
-
const template = templateParts.map((part)=>{
|
|
88
|
-
const isDynamic = part.startsWith("[") && part.endsWith("]");
|
|
89
|
-
const asValue = isDynamic ? part.match(/\[(.+)\]/)?.[1].trim() ?? "" : part.trim();
|
|
90
|
-
const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
|
|
91
|
-
const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
|
|
92
|
-
return isDynamic ? `:${asPath}` : asPath;
|
|
93
|
-
}).join("/");
|
|
94
|
-
return {
|
|
95
|
-
pathname,
|
|
96
|
-
template
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get routes map dictionary
|
|
101
|
-
*/ function getRoutesMap(map = {}, routes, pathnameBuffer = "", templateBuffer = "") {
|
|
102
|
-
for(const key in routes){
|
|
103
|
-
const pathOrNestedRoutes = routes[key];
|
|
104
|
-
const template = `${templateBuffer}/${key}`;
|
|
105
|
-
if (typeof pathOrNestedRoutes === "string") {
|
|
106
|
-
map[template] = {
|
|
107
|
-
template,
|
|
108
|
-
pathname: pathOrNestedRoutes,
|
|
109
|
-
wildcard: pathOrNestedRoutes.includes("*")
|
|
110
|
-
};
|
|
111
|
-
} else {
|
|
112
|
-
getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return map;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Removes `/index` from a template/url path
|
|
119
|
-
*/ function getWithoutIndex(template) {
|
|
120
|
-
return template.replace(/\/index$/, "");
|
|
121
|
-
}
|
|
122
|
-
function getPathRewrite(route) {
|
|
123
|
-
const { pathname, template } = transformRoute(route);
|
|
124
|
-
const source = `/${normaliseUrlPathname(pathname)}`;
|
|
125
|
-
const destination = `/${normaliseUrlPathname(template)}`;
|
|
126
|
-
// console.log(`rewrite pathname "${source}" to template "${destination}"`);
|
|
127
|
-
return {
|
|
128
|
-
source,
|
|
129
|
-
destination: getWithoutIndex(destination)
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function getPathRedirect(locale = "", route, permanent) {
|
|
133
|
-
const { template, pathname } = transformRoute(route);
|
|
134
|
-
const source = `/${normaliseUrlPathname((locale ? `/${locale}/` : "/") + template)}`;
|
|
135
|
-
const destination = `/${normaliseUrlPathname(pathname)}`;
|
|
136
|
-
// console.log(`redirect template "${source}" to pathname "${destination}"`);
|
|
137
|
-
return {
|
|
138
|
-
source: getWithoutIndex(source),
|
|
139
|
-
destination,
|
|
140
|
-
permanent: Boolean(permanent),
|
|
141
|
-
locale: false
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
async function getRedirects(defaultLocale, routes, permanent, debug) {
|
|
145
|
-
const redirects = [];
|
|
146
|
-
const routesMap = getRoutesMap({}, routes);
|
|
147
|
-
Object.keys(routesMap).forEach((template)=>{
|
|
148
|
-
const route = routesMap[template];
|
|
149
|
-
// TODO: add option hideDefaultLocaleInUrl?
|
|
150
|
-
// this is meant to redirect the URL with the default locale to the same
|
|
151
|
-
// url without locale prefix, e.g.: /en/about -> /about (assuming en is the
|
|
152
|
-
// defualt locale).
|
|
153
|
-
// Actually this redirect seem not to be necessary, probably the i18n routing
|
|
154
|
-
// mechanism of next 12 already does this, enabling causes infinite redirects
|
|
155
|
-
// if (hideDefaultLocaleInUrl) {
|
|
156
|
-
// redirects.push(getPathRedirect(defaultLocale, route, permanent));
|
|
157
|
-
// }
|
|
158
|
-
if (route.pathname !== getWithoutIndex(template)) {
|
|
159
|
-
redirects.push(getPathRedirect("", route, permanent));
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
if (debug) console.info("[@koine/next/config:getRedirects]", redirects);
|
|
163
|
-
return redirects;
|
|
164
|
-
}
|
|
165
|
-
async function getRewrites(routes, debug) {
|
|
166
|
-
const rewrites = [];
|
|
167
|
-
const routesMap = getRoutesMap({}, routes);
|
|
168
|
-
Object.keys(routesMap).forEach((template)=>{
|
|
169
|
-
const route = routesMap[template];
|
|
170
|
-
if (route.pathname !== getWithoutIndex(template)) {
|
|
171
|
-
rewrites.push(getPathRewrite(route));
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
if (debug) console.info("[@koine/next/config:getRewrites]", rewrites);
|
|
175
|
-
return rewrites;
|
|
176
|
-
}
|
|
177
|
-
function withKoine({ nx = true, svg = true, sc = true, page, routes, permanent, debug, ...custom } = {
|
|
178
|
-
i18n: {
|
|
179
|
-
locales: [
|
|
180
|
-
"en"
|
|
181
|
-
],
|
|
182
|
-
defaultLocale: "en"
|
|
183
|
-
}
|
|
184
|
-
}) {
|
|
185
|
-
const nextConfig = {
|
|
186
|
-
// @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
|
|
187
|
-
pageExtensions: page ? [
|
|
188
|
-
"page.tsx",
|
|
189
|
-
"page.ts"
|
|
190
|
-
] : undefined,
|
|
191
|
-
eslint: {
|
|
192
|
-
ignoreDuringBuilds: true
|
|
193
|
-
},
|
|
194
|
-
typescript: {
|
|
195
|
-
ignoreBuildErrors: true
|
|
196
|
-
},
|
|
197
|
-
poweredByHeader: false,
|
|
198
|
-
swcMinify: true,
|
|
199
|
-
modularizeImports: {
|
|
200
|
-
"@koine/api": {
|
|
201
|
-
transform: "@koine/api/{{member}}"
|
|
202
|
-
},
|
|
203
|
-
"@koine/browser": {
|
|
204
|
-
transform: "@koine/browser/{{member}}"
|
|
205
|
-
},
|
|
206
|
-
"@koine/dom": {
|
|
207
|
-
transform: "@koine/dom/{{member}}"
|
|
208
|
-
},
|
|
209
|
-
"@koine/next/?(((\\w*)?/?)*)": {
|
|
210
|
-
transform: "@koine/next/{{ matches.[1] }}/{{member}}"
|
|
211
|
-
},
|
|
212
|
-
"@koine/react/?(((\\w*)?/?)*)": {
|
|
213
|
-
transform: "@koine/react/{{ matches.[1] }}/{{member}}"
|
|
214
|
-
},
|
|
215
|
-
"@koine/utils": {
|
|
216
|
-
transform: "@koine/utils/{{member}}"
|
|
217
|
-
},
|
|
218
|
-
...custom["modularizeImports"] || {}
|
|
219
|
-
},
|
|
220
|
-
experimental: {
|
|
221
|
-
// @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
|
|
222
|
-
// @see critters error https://github.com/vercel/next.js/issues/20742
|
|
223
|
-
// optimizeCss: true,
|
|
224
|
-
// @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
|
|
225
|
-
scrollRestoration: true,
|
|
226
|
-
// concurrentFeatures: true,
|
|
227
|
-
// serverComponents: true,
|
|
228
|
-
// reactRoot: true,
|
|
229
|
-
...custom["experimental"] || {}
|
|
230
|
-
},
|
|
231
|
-
// @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
|
|
232
|
-
// reactStrictMode: true,
|
|
233
|
-
...custom
|
|
234
|
-
};
|
|
235
|
-
if (svg) {
|
|
236
|
-
if (nx) {
|
|
237
|
-
// @see https://github.com/gregberge/svgr
|
|
238
|
-
nextConfig["nx"] = {
|
|
239
|
-
svgr: true
|
|
240
|
-
};
|
|
241
|
-
} else {
|
|
242
|
-
nextConfig.webpack = (_config, options)=>{
|
|
243
|
-
const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config;
|
|
244
|
-
// @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
|
|
245
|
-
webpackConfig.module.rules.push({
|
|
246
|
-
test: /\.svg$/,
|
|
247
|
-
use: [
|
|
248
|
-
{
|
|
249
|
-
loader: "@svgr/webpack",
|
|
250
|
-
options: {
|
|
251
|
-
svgoConfig: {
|
|
252
|
-
plugins: [
|
|
253
|
-
{
|
|
254
|
-
name: "removeViewBox",
|
|
255
|
-
active: false
|
|
256
|
-
}
|
|
257
|
-
]
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
]
|
|
262
|
-
});
|
|
263
|
-
return webpackConfig;
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (sc) {
|
|
268
|
-
nextConfig.compiler = {
|
|
269
|
-
styledComponents: true
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
if (routes) {
|
|
273
|
-
// we pass the default values, so we can assert I guess
|
|
274
|
-
const defaultLocale = nextConfig?.i18n?.defaultLocale;
|
|
275
|
-
return {
|
|
276
|
-
...nextConfig,
|
|
277
|
-
async redirects () {
|
|
278
|
-
const defaults = await getRedirects(defaultLocale, routes, permanent, debug);
|
|
279
|
-
if (nextConfig.redirects) {
|
|
280
|
-
const customs = await nextConfig.redirects();
|
|
281
|
-
return [
|
|
282
|
-
...defaults,
|
|
283
|
-
...customs
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
return defaults;
|
|
287
|
-
},
|
|
288
|
-
async rewrites () {
|
|
289
|
-
const defaults = await getRewrites(routes, debug);
|
|
290
|
-
if (nextConfig.rewrites) {
|
|
291
|
-
const customs = await nextConfig.rewrites();
|
|
292
|
-
if (Array.isArray(customs)) {
|
|
293
|
-
return {
|
|
294
|
-
beforeFiles: defaults,
|
|
295
|
-
afterFiles: customs,
|
|
296
|
-
fallback: []
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
return {
|
|
300
|
-
...customs,
|
|
301
|
-
beforeFiles: [
|
|
302
|
-
...defaults,
|
|
303
|
-
...customs.beforeFiles || []
|
|
304
|
-
]
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
return {
|
|
308
|
-
afterFiles: [],
|
|
309
|
-
beforeFiles: defaults,
|
|
310
|
-
fallback: []
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
return nextConfig;
|
|
316
|
-
}
|
|
317
|
-
const _default = withKoine;
|