@djangocfg/nextjs 2.1.110 → 2.1.112

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.
Files changed (60) hide show
  1. package/README.md +208 -7
  2. package/dist/config/index.d.mts +16 -1
  3. package/dist/config/index.mjs +83 -14
  4. package/dist/config/index.mjs.map +1 -1
  5. package/dist/i18n/client.d.mts +123 -0
  6. package/dist/i18n/client.mjs +104 -0
  7. package/dist/i18n/client.mjs.map +1 -0
  8. package/dist/i18n/components.d.mts +11 -0
  9. package/dist/i18n/components.mjs +90 -0
  10. package/dist/i18n/components.mjs.map +1 -0
  11. package/dist/i18n/index.d.mts +18 -0
  12. package/dist/i18n/index.mjs +226 -0
  13. package/dist/i18n/index.mjs.map +1 -0
  14. package/dist/i18n/navigation.d.mts +1095 -0
  15. package/dist/i18n/navigation.mjs +45 -0
  16. package/dist/i18n/navigation.mjs.map +1 -0
  17. package/dist/i18n/plugin.d.mts +41 -0
  18. package/dist/i18n/plugin.mjs +17 -0
  19. package/dist/i18n/plugin.mjs.map +1 -0
  20. package/dist/i18n/provider.d.mts +18 -0
  21. package/dist/i18n/provider.mjs +54 -0
  22. package/dist/i18n/provider.mjs.map +1 -0
  23. package/dist/i18n/proxy.d.mts +40 -0
  24. package/dist/i18n/proxy.mjs +42 -0
  25. package/dist/i18n/proxy.mjs.map +1 -0
  26. package/dist/i18n/request.d.mts +42 -0
  27. package/dist/i18n/request.mjs +63 -0
  28. package/dist/i18n/request.mjs.map +1 -0
  29. package/dist/i18n/routing.d.mts +79 -0
  30. package/dist/i18n/routing.mjs +33 -0
  31. package/dist/i18n/routing.mjs.map +1 -0
  32. package/dist/i18n/server.d.mts +90 -0
  33. package/dist/i18n/server.mjs +79 -0
  34. package/dist/i18n/server.mjs.map +1 -0
  35. package/dist/index.d.mts +3 -1
  36. package/dist/index.mjs +176 -30
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/sitemap/index.d.mts +22 -3
  39. package/dist/sitemap/index.mjs +92 -15
  40. package/dist/sitemap/index.mjs.map +1 -1
  41. package/dist/types-Cy349X20.d.mts +60 -0
  42. package/package.json +54 -4
  43. package/src/config/constants.ts +1 -0
  44. package/src/config/createNextConfig.ts +39 -17
  45. package/src/i18n/client.ts +221 -0
  46. package/src/i18n/components/LocaleSwitcher.tsx +60 -0
  47. package/src/i18n/components/index.ts +7 -0
  48. package/src/i18n/index.ts +149 -0
  49. package/src/i18n/navigation.ts +90 -0
  50. package/src/i18n/plugin.ts +66 -0
  51. package/src/i18n/provider.tsx +91 -0
  52. package/src/i18n/proxy.ts +81 -0
  53. package/src/i18n/request.ts +141 -0
  54. package/src/i18n/routing.ts +84 -0
  55. package/src/i18n/server.ts +175 -0
  56. package/src/i18n/types.ts +88 -0
  57. package/src/sitemap/generator.ts +84 -9
  58. package/src/sitemap/index.ts +1 -1
  59. package/src/sitemap/route.ts +71 -8
  60. package/src/sitemap/types.ts +9 -0
@@ -4,5 +4,5 @@
4
4
 
5
5
  export { createSitemapHandler } from './route';
6
6
  export { generateSitemapXml, normalizeUrl } from './generator';
7
- export type { SitemapGeneratorOptions, SitemapRoute } from './types';
7
+ export type { SitemapGeneratorOptions, SitemapRoute, SitemapI18nOptions } from './types';
8
8
 
@@ -13,7 +13,6 @@
13
13
  * { loc: '/about', changefreq: 'monthly', priority: 0.8 },
14
14
  * ],
15
15
  * dynamicPages: async () => {
16
- * // Fetch dynamic pages from API
17
16
  * const posts = await fetchPosts();
18
17
  * return posts.map(post => ({
19
18
  * loc: `/posts/${post.slug}`,
@@ -22,6 +21,11 @@
22
21
  * priority: 0.7,
23
22
  * }));
24
23
  * },
24
+ * // i18n support with hreflang
25
+ * i18n: {
26
+ * locales: ['en', 'ru', 'ko'],
27
+ * defaultLocale: 'en',
28
+ * },
25
29
  * });
26
30
  * ```
27
31
  */
@@ -39,6 +43,7 @@ export function createSitemapHandler(options: SitemapGeneratorOptions) {
39
43
  staticPages = [],
40
44
  dynamicPages = [],
41
45
  cacheControl = 'public, s-maxage=86400, stale-while-revalidate',
46
+ i18n,
42
47
  } = options;
43
48
 
44
49
  return async function GET() {
@@ -54,14 +59,23 @@ export function createSitemapHandler(options: SitemapGeneratorOptions) {
54
59
  }
55
60
  }
56
61
 
57
- // Normalize all URLs
58
- const normalizedUrls = urls.map((url) => ({
59
- ...url,
60
- loc: normalizeUrl(url.loc, siteUrl),
61
- }));
62
+ // Expand URLs for each locale if i18n is enabled
63
+ let expandedUrls: SitemapUrl[];
64
+ if (i18n) {
65
+ expandedUrls = expandUrlsForLocales(urls, i18n.locales, siteUrl);
66
+ } else {
67
+ expandedUrls = urls.map((url) => ({
68
+ ...url,
69
+ loc: normalizeUrl(url.loc, siteUrl),
70
+ }));
71
+ }
62
72
 
63
- // Generate XML
64
- const sitemap = generateSitemapXml(normalizedUrls);
73
+ // Generate XML with i18n support
74
+ const sitemap = generateSitemapXml({
75
+ urls: expandedUrls,
76
+ i18n,
77
+ siteUrl,
78
+ });
65
79
 
66
80
  // Return response
67
81
  return new NextResponse(sitemap, {
@@ -74,3 +88,52 @@ export function createSitemapHandler(options: SitemapGeneratorOptions) {
74
88
  };
75
89
  }
76
90
 
91
+ /**
92
+ * Expand URLs to include all locale variants
93
+ * Input: [{ loc: '/page' }] with locales ['en', 'ru']
94
+ * Output: [{ loc: 'https://example.com/en/page' }, { loc: 'https://example.com/ru/page' }]
95
+ */
96
+ function expandUrlsForLocales(
97
+ urls: SitemapUrl[],
98
+ locales: string[],
99
+ siteUrl: string
100
+ ): SitemapUrl[] {
101
+ const baseSiteUrl = siteUrl.endsWith('/') ? siteUrl.slice(0, -1) : siteUrl;
102
+ const expandedUrls: SitemapUrl[] = [];
103
+
104
+ for (const url of urls) {
105
+ // Normalize the path (remove leading slash if present for consistency)
106
+ let path = url.loc;
107
+ if (path.startsWith(baseSiteUrl)) {
108
+ path = path.replace(baseSiteUrl, '');
109
+ }
110
+ if (!path.startsWith('/')) {
111
+ path = '/' + path;
112
+ }
113
+
114
+ // Check if the path already has a locale prefix
115
+ const hasLocalePrefix = locales.some(
116
+ (locale) => path === `/${locale}` || path.startsWith(`/${locale}/`)
117
+ );
118
+
119
+ if (hasLocalePrefix) {
120
+ // URL already has locale prefix, just normalize it
121
+ expandedUrls.push({
122
+ ...url,
123
+ loc: normalizeUrl(path, siteUrl),
124
+ });
125
+ } else {
126
+ // Create a URL for each locale
127
+ for (const locale of locales) {
128
+ const localePath = path === '/' ? `/${locale}` : `/${locale}${path}`;
129
+ expandedUrls.push({
130
+ ...url,
131
+ loc: `${baseSiteUrl}${localePath}`,
132
+ });
133
+ }
134
+ }
135
+ }
136
+
137
+ return expandedUrls;
138
+ }
139
+
@@ -4,11 +4,20 @@
4
4
 
5
5
  import type { ChangeFreq, SitemapUrl } from '../types';
6
6
 
7
+ export interface SitemapI18nOptions {
8
+ /** Supported locales (e.g., ['en', 'ru', 'ko']) */
9
+ locales: string[];
10
+ /** Default locale for x-default hreflang */
11
+ defaultLocale: string;
12
+ }
13
+
7
14
  export interface SitemapGeneratorOptions {
8
15
  siteUrl: string;
9
16
  staticPages?: SitemapUrl[];
10
17
  dynamicPages?: (() => Promise<SitemapUrl[]>) | SitemapUrl[];
11
18
  cacheControl?: string;
19
+ /** i18n configuration for hreflang support */
20
+ i18n?: SitemapI18nOptions;
12
21
  }
13
22
 
14
23
  export interface SitemapRoute {