@jet-w/astro-blog 0.2.1 → 0.2.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.
- package/dist/chunk-DAH2XP4W.js +154 -0
- package/dist/{chunk-TJTPX2WP.js → chunk-PG43JO4O.js} +1 -153
- package/dist/chunk-PZICDGJG.js +69 -0
- package/dist/chunk-Z3O3JK56.js +186 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +8 -6
- package/dist/{i18n-PgMCFBw0.d.ts → i18n-DYYPTq4o.d.ts} +1 -1
- package/dist/index.d.ts +10 -202
- package/dist/index.js +33 -223
- package/dist/integration.d.ts +2 -2
- package/dist/{sidebar-Da-W_4Lr.d.ts → sidebar-DNdiCKBw.d.ts} +1 -1
- package/dist/utils/i18n.d.ts +133 -0
- package/dist/utils/i18n.js +49 -0
- package/dist/utils/sidebar.d.ts +1 -1
- package/dist/utils/useI18n.d.ts +74 -0
- package/dist/utils/useI18n.js +15 -0
- package/package.json +9 -1
- package/templates/default/package.dev.json +31 -0
- package/templates/default/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,207 +1,15 @@
|
|
|
1
1
|
export { defaultMenu, defaultSEO, defaultSiteConfig, defineMenu, defineSiteConfig, menu, siteConfig } from './config/index.js';
|
|
2
|
-
import {
|
|
3
|
-
export { D as DividerConfig, M as ManualConfig, f as MixedConfig, P as PathMatchConfig, e as ScanConfig,
|
|
4
|
-
import {
|
|
5
|
-
export { m as FooterLink, o as I18nRoutingConfig, n as LocaleConfig, j as builtInTranslations, c as defaultFooterConfig, g as defaultI18nConfig, d as defaultIcons, l as defaultLocales, a as defaultSocialLinks, e as defineFooterConfig, h as defineI18nConfig, b as defineSocialLinks, k as enTranslations, f as footerConfig, i as getUITranslations, s as socialLinks, z as zhCNTranslations } from './i18n-
|
|
6
|
-
import { SiteConfig
|
|
7
|
-
export { BlogPost, Category, PostFrontmatter, SEOProps, SearchResult, Tag } from './types/index.js';
|
|
2
|
+
import { S as SidebarConfig } from './sidebar-DNdiCKBw.js';
|
|
3
|
+
export { D as DividerConfig, M as ManualConfig, f as MixedConfig, P as PathMatchConfig, e as ScanConfig, b as SidebarGroup, c as SidebarItem, d as defaultSidebarConfig, a as defineSidebarConfig, s as sidebarConfig } from './sidebar-DNdiCKBw.js';
|
|
4
|
+
import { F as FooterConfig, S as SocialLink, I as I18nConfig } from './i18n-DYYPTq4o.js';
|
|
5
|
+
export { m as FooterLink, o as I18nRoutingConfig, L as Locale, n as LocaleConfig, U as UITranslations, j as builtInTranslations, c as defaultFooterConfig, g as defaultI18nConfig, d as defaultIcons, l as defaultLocales, a as defaultSocialLinks, e as defineFooterConfig, h as defineI18nConfig, b as defineSocialLinks, k as enTranslations, f as footerConfig, i as getUITranslations, s as socialLinks, z as zhCNTranslations } from './i18n-DYYPTq4o.js';
|
|
6
|
+
import { SiteConfig } from './types/index.js';
|
|
7
|
+
export { BlogPost, Category, NavigationItem, PostFrontmatter, SEOProps, SearchResult, Tag } from './types/index.js';
|
|
8
8
|
export { AstroBlogIntegrationOptions, default as astroBlog, default as astroBlogIntegration } from './integration.js';
|
|
9
|
-
|
|
9
|
+
export { AlternateLink, MergedLocaleConfig, filterPostsByLocale, formatDate, formatDateShort, getAlternateLinks, getContentPathPrefix, getLocaleByCode, getLocaleConfig, getLocaleFromPath, getLocalePrefix, getLocalizedPath, getTextDirection, isMultiLanguageEnabled, isRTL, removeLocalePrefix, t } from './utils/i18n.js';
|
|
10
|
+
export { I18N_CONFIG_KEY, I18N_LOCALE_KEY, I18N_TRANSLATIONS_KEY, I18nContext, UseI18nReturn, createI18nContext, useI18n } from './utils/useI18n.js';
|
|
10
11
|
import 'astro';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* i18n Utility Functions
|
|
14
|
-
*
|
|
15
|
-
* Provides helper functions for multi-language support.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Merged locale configuration with all defaults applied
|
|
20
|
-
*/
|
|
21
|
-
interface MergedLocaleConfig {
|
|
22
|
-
locale: Locale;
|
|
23
|
-
site: SiteConfig;
|
|
24
|
-
menu: NavigationItem[];
|
|
25
|
-
footer: FooterConfig;
|
|
26
|
-
sidebar: SidebarConfig;
|
|
27
|
-
ui: UITranslations;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Alternate link for SEO (hreflang)
|
|
31
|
-
*/
|
|
32
|
-
interface AlternateLink {
|
|
33
|
-
locale: string;
|
|
34
|
-
url: string;
|
|
35
|
-
hreflang: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get current locale from URL pathname
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* getLocaleFromPath('/en/posts', config) // 'en'
|
|
42
|
-
* getLocaleFromPath('/posts', config) // 'zh-CN' (default)
|
|
43
|
-
* getLocaleFromPath('/zh-CN/about', config) // 'zh-CN'
|
|
44
|
-
*/
|
|
45
|
-
declare function getLocaleFromPath(pathname: string, config?: I18nConfig): string;
|
|
46
|
-
/**
|
|
47
|
-
* Get locale data by code
|
|
48
|
-
*/
|
|
49
|
-
declare function getLocaleByCode(code: string, config?: I18nConfig): Locale | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Remove locale prefix from pathname
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* removeLocalePrefix('/en/posts', config) // '/posts'
|
|
55
|
-
* removeLocalePrefix('/posts', config) // '/posts'
|
|
56
|
-
*/
|
|
57
|
-
declare function removeLocalePrefix(pathname: string, config?: I18nConfig): string;
|
|
58
|
-
/**
|
|
59
|
-
* Get localized path for a given locale
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* getLocalizedPath('/posts', 'en', config) // '/en/posts'
|
|
63
|
-
* getLocalizedPath('/en/posts', 'zh-CN', config) // '/posts' (if zh-CN is default)
|
|
64
|
-
*/
|
|
65
|
-
declare function getLocalizedPath(pathname: string, targetLocale: string, config?: I18nConfig): string;
|
|
66
|
-
/**
|
|
67
|
-
* Get all alternate links for SEO (hreflang tags)
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* getAlternateLinks('/posts', 'https://example.com', config)
|
|
71
|
-
* // Returns links for all locales
|
|
72
|
-
*/
|
|
73
|
-
declare function getAlternateLinks(pathname: string, baseUrl: string, config?: I18nConfig): AlternateLink[];
|
|
74
|
-
/**
|
|
75
|
-
* Get merged configuration for a specific locale
|
|
76
|
-
* Combines default config with locale-specific overrides
|
|
77
|
-
*/
|
|
78
|
-
declare function getLocaleConfig(locale: string, config?: I18nConfig): MergedLocaleConfig;
|
|
79
|
-
/**
|
|
80
|
-
* Translation function - get a UI translation string
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* t('readMore', 'en') // 'Read more'
|
|
84
|
-
* t('readMore', 'zh-CN') // '阅读更多'
|
|
85
|
-
*/
|
|
86
|
-
declare function t(key: keyof UITranslations, locale: string, config?: I18nConfig): string;
|
|
87
|
-
/**
|
|
88
|
-
* Format date according to locale
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* formatDate(new Date(), 'en') // 'January 1, 2024'
|
|
92
|
-
* formatDate(new Date(), 'zh-CN') // '2024年1月1日'
|
|
93
|
-
*/
|
|
94
|
-
declare function formatDate(date: Date | string, locale: string, options?: Intl.DateTimeFormatOptions): string;
|
|
95
|
-
/**
|
|
96
|
-
* Format date in short format
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* formatDateShort(new Date(), 'en') // '1/1/2024'
|
|
100
|
-
* formatDateShort(new Date(), 'zh-CN') // '2024/1/1'
|
|
101
|
-
*/
|
|
102
|
-
declare function formatDateShort(date: Date | string, locale: string): string;
|
|
103
|
-
/**
|
|
104
|
-
* Check if a locale is RTL (right-to-left)
|
|
105
|
-
*/
|
|
106
|
-
declare function isRTL(locale: string, config?: I18nConfig): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Get the HTML dir attribute value
|
|
109
|
-
*/
|
|
110
|
-
declare function getTextDirection(locale: string, config?: I18nConfig): 'ltr' | 'rtl';
|
|
111
|
-
/**
|
|
112
|
-
* Check if multi-language is enabled (more than one locale)
|
|
113
|
-
*/
|
|
114
|
-
declare function isMultiLanguageEnabled(config?: I18nConfig): boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Get prefix for a locale in routes
|
|
117
|
-
* Returns empty string for default locale if prefixDefaultLocale is false
|
|
118
|
-
*/
|
|
119
|
-
declare function getLocalePrefix(locale: string, config?: I18nConfig): string;
|
|
120
|
-
/**
|
|
121
|
-
* Get content path prefix for a specific locale
|
|
122
|
-
* Returns the contentPathPrefix from locale config, or undefined if not set
|
|
123
|
-
*/
|
|
124
|
-
declare function getContentPathPrefix(locale: string, config?: I18nConfig): string | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* Filter posts by locale based on contentPathPrefix
|
|
127
|
-
* If contentPathPrefix is set, only return posts that start with that prefix
|
|
128
|
-
* If not set, return all posts (backward compatible)
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* // If en locale has contentPathPrefix: 'blog_docs_en'
|
|
132
|
-
* filterPostsByLocale(posts, 'en', config)
|
|
133
|
-
* // Returns only posts with id starting with 'blog_docs_en/'
|
|
134
|
-
*/
|
|
135
|
-
declare function filterPostsByLocale<T extends {
|
|
136
|
-
id: string;
|
|
137
|
-
}>(posts: T[], locale: string, config?: I18nConfig): T[];
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Vue Composable for i18n
|
|
141
|
-
*
|
|
142
|
-
* Provides i18n support for Vue components in the blog.
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* i18n injection keys
|
|
147
|
-
*/
|
|
148
|
-
declare const I18N_LOCALE_KEY: unique symbol;
|
|
149
|
-
declare const I18N_CONFIG_KEY: unique symbol;
|
|
150
|
-
declare const I18N_TRANSLATIONS_KEY: unique symbol;
|
|
151
|
-
/**
|
|
152
|
-
* i18n context provided to Vue components
|
|
153
|
-
*/
|
|
154
|
-
interface I18nContext {
|
|
155
|
-
locale: string;
|
|
156
|
-
translations: UITranslations;
|
|
157
|
-
config?: I18nConfig;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Return type of useI18n composable
|
|
161
|
-
*/
|
|
162
|
-
interface UseI18nReturn {
|
|
163
|
-
/** Current locale code */
|
|
164
|
-
locale: ComputedRef<string>;
|
|
165
|
-
/** Translation function */
|
|
166
|
-
t: (key: keyof UITranslations) => string;
|
|
167
|
-
/** Format date according to locale */
|
|
168
|
-
formatDate: (date: Date | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
169
|
-
/** Format date in short format */
|
|
170
|
-
formatDateShort: (date: Date | string) => string;
|
|
171
|
-
/** All translations for current locale */
|
|
172
|
-
translations: ComputedRef<UITranslations>;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Vue composable for i18n support
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```vue
|
|
179
|
-
* <script setup>
|
|
180
|
-
* import { useI18n } from '@jet-w/astro-blog/utils/useI18n';
|
|
181
|
-
*
|
|
182
|
-
* const { t, formatDate, locale } = useI18n();
|
|
183
|
-
* </script>
|
|
184
|
-
*
|
|
185
|
-
* <template>
|
|
186
|
-
* <h1>{{ t('postList') }}</h1>
|
|
187
|
-
* <span>{{ formatDate(post.pubDate) }}</span>
|
|
188
|
-
* </template>
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
declare function useI18n(): UseI18nReturn;
|
|
192
|
-
/**
|
|
193
|
-
* Create i18n context for providing to Vue components
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* ```astro
|
|
197
|
-
* ---
|
|
198
|
-
* import { createI18nContext } from '@jet-w/astro-blog/utils/useI18n';
|
|
199
|
-
* const i18nContext = createI18nContext('en', i18nConfig);
|
|
200
|
-
* ---
|
|
201
|
-
* <Component client:load {...i18nContext} />
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
declare function createI18nContext(locale: string, config?: I18nConfig): I18nContext;
|
|
12
|
+
import 'vue';
|
|
205
13
|
|
|
206
14
|
/**
|
|
207
15
|
* Define blog configuration helper
|
|
@@ -232,4 +40,4 @@ declare function getAstroConfig(options?: {
|
|
|
232
40
|
};
|
|
233
41
|
};
|
|
234
42
|
|
|
235
|
-
export { type
|
|
43
|
+
export { type BlogConfig, FooterConfig, I18nConfig, SidebarConfig, SiteConfig, SocialLink, defineBlogConfig, getAstroConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
|
-
defaultFooterConfig,
|
|
3
2
|
defaultIcons,
|
|
3
|
+
defaultSocialLinks,
|
|
4
|
+
defineSocialLinks,
|
|
5
|
+
socialLinks
|
|
6
|
+
} from "./chunk-PG43JO4O.js";
|
|
7
|
+
import "./chunk-FXPGR372.js";
|
|
8
|
+
import {
|
|
9
|
+
filterPostsByLocale,
|
|
10
|
+
formatDate,
|
|
11
|
+
formatDateShort,
|
|
12
|
+
getAlternateLinks,
|
|
13
|
+
getContentPathPrefix,
|
|
14
|
+
getLocaleByCode,
|
|
15
|
+
getLocaleConfig,
|
|
16
|
+
getLocaleFromPath,
|
|
17
|
+
getLocalePrefix,
|
|
18
|
+
getLocalizedPath,
|
|
19
|
+
getTextDirection,
|
|
20
|
+
isMultiLanguageEnabled,
|
|
21
|
+
isRTL,
|
|
22
|
+
removeLocalePrefix,
|
|
23
|
+
t
|
|
24
|
+
} from "./chunk-Z3O3JK56.js";
|
|
25
|
+
import {
|
|
26
|
+
defaultFooterConfig,
|
|
4
27
|
defaultMenu,
|
|
5
28
|
defaultSEO,
|
|
6
29
|
defaultSidebarConfig,
|
|
7
30
|
defaultSiteConfig,
|
|
8
|
-
defaultSocialLinks,
|
|
9
31
|
defineFooterConfig,
|
|
10
32
|
defineMenu,
|
|
11
33
|
defineSidebarConfig,
|
|
12
34
|
defineSiteConfig,
|
|
13
|
-
defineSocialLinks,
|
|
14
35
|
footerConfig,
|
|
15
36
|
menu,
|
|
16
37
|
sidebarConfig,
|
|
17
|
-
siteConfig
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
siteConfig
|
|
39
|
+
} from "./chunk-DAH2XP4W.js";
|
|
40
|
+
import {
|
|
41
|
+
I18N_CONFIG_KEY,
|
|
42
|
+
I18N_LOCALE_KEY,
|
|
43
|
+
I18N_TRANSLATIONS_KEY,
|
|
44
|
+
createI18nContext,
|
|
45
|
+
useI18n
|
|
46
|
+
} from "./chunk-PZICDGJG.js";
|
|
21
47
|
import {
|
|
22
48
|
astroBlogIntegration,
|
|
23
49
|
integration_default
|
|
@@ -32,222 +58,6 @@ import {
|
|
|
32
58
|
zhCNTranslations
|
|
33
59
|
} from "./chunk-A2E2VSAQ.js";
|
|
34
60
|
|
|
35
|
-
// src/utils/i18n.ts
|
|
36
|
-
function getLocaleFromPath(pathname, config = defaultI18nConfig) {
|
|
37
|
-
const segments = pathname.replace(/^\//, "").split("/");
|
|
38
|
-
const firstSegment = segments[0];
|
|
39
|
-
const matchedLocale = config.locales.find(
|
|
40
|
-
(locale) => locale.code === firstSegment
|
|
41
|
-
);
|
|
42
|
-
if (matchedLocale) {
|
|
43
|
-
return matchedLocale.code;
|
|
44
|
-
}
|
|
45
|
-
return config.defaultLocale;
|
|
46
|
-
}
|
|
47
|
-
function getLocaleByCode(code, config = defaultI18nConfig) {
|
|
48
|
-
return config.locales.find((locale) => locale.code === code);
|
|
49
|
-
}
|
|
50
|
-
function removeLocalePrefix(pathname, config = defaultI18nConfig) {
|
|
51
|
-
const locale = getLocaleFromPath(pathname, config);
|
|
52
|
-
if (locale === config.defaultLocale && !config.routing.prefixDefaultLocale) {
|
|
53
|
-
return pathname;
|
|
54
|
-
}
|
|
55
|
-
const prefix = `/${locale}`;
|
|
56
|
-
if (pathname.startsWith(prefix)) {
|
|
57
|
-
const rest = pathname.slice(prefix.length);
|
|
58
|
-
return rest || "/";
|
|
59
|
-
}
|
|
60
|
-
return pathname;
|
|
61
|
-
}
|
|
62
|
-
function getLocalizedPath(pathname, targetLocale, config = defaultI18nConfig) {
|
|
63
|
-
const basePath = removeLocalePrefix(pathname, config);
|
|
64
|
-
if (targetLocale === config.defaultLocale && !config.routing.prefixDefaultLocale) {
|
|
65
|
-
return basePath;
|
|
66
|
-
}
|
|
67
|
-
if (basePath === "/") {
|
|
68
|
-
return `/${targetLocale}`;
|
|
69
|
-
}
|
|
70
|
-
return `/${targetLocale}${basePath}`;
|
|
71
|
-
}
|
|
72
|
-
function getAlternateLinks(pathname, baseUrl, config = defaultI18nConfig) {
|
|
73
|
-
const links = [];
|
|
74
|
-
for (const locale of config.locales) {
|
|
75
|
-
const localizedPath = getLocalizedPath(pathname, locale.code, config);
|
|
76
|
-
links.push({
|
|
77
|
-
locale: locale.code,
|
|
78
|
-
url: `${baseUrl.replace(/\/$/, "")}${localizedPath}`,
|
|
79
|
-
hreflang: locale.htmlLang
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const defaultPath = getLocalizedPath(
|
|
83
|
-
pathname,
|
|
84
|
-
config.defaultLocale,
|
|
85
|
-
config
|
|
86
|
-
);
|
|
87
|
-
links.push({
|
|
88
|
-
locale: "x-default",
|
|
89
|
-
url: `${baseUrl.replace(/\/$/, "")}${defaultPath}`,
|
|
90
|
-
hreflang: "x-default"
|
|
91
|
-
});
|
|
92
|
-
return links;
|
|
93
|
-
}
|
|
94
|
-
function deepMerge(base, override) {
|
|
95
|
-
const result = { ...base };
|
|
96
|
-
for (const key in override) {
|
|
97
|
-
if (Object.prototype.hasOwnProperty.call(override, key)) {
|
|
98
|
-
const overrideValue = override[key];
|
|
99
|
-
const baseValue = base[key];
|
|
100
|
-
if (typeof overrideValue === "object" && overrideValue !== null && !Array.isArray(overrideValue) && typeof baseValue === "object" && baseValue !== null && !Array.isArray(baseValue)) {
|
|
101
|
-
result[key] = deepMerge(baseValue, overrideValue);
|
|
102
|
-
} else if (overrideValue !== void 0) {
|
|
103
|
-
result[key] = overrideValue;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
function getLocaleConfig(locale, config = defaultI18nConfig) {
|
|
110
|
-
const localeData = getLocaleByCode(locale, config);
|
|
111
|
-
const localeOverrides = config.localeConfigs[locale] || {};
|
|
112
|
-
const localeInfo = localeData || {
|
|
113
|
-
code: locale,
|
|
114
|
-
name: locale,
|
|
115
|
-
htmlLang: locale,
|
|
116
|
-
dateLocale: locale,
|
|
117
|
-
direction: "ltr"
|
|
118
|
-
};
|
|
119
|
-
const site = deepMerge(defaultSiteConfig, localeOverrides.site || {});
|
|
120
|
-
const menu2 = localeOverrides.menu || defaultMenu;
|
|
121
|
-
const footer = deepMerge(defaultFooterConfig, localeOverrides.footer || {});
|
|
122
|
-
const sidebar = localeOverrides.sidebar ? {
|
|
123
|
-
...sidebarConfig,
|
|
124
|
-
...localeOverrides.sidebar,
|
|
125
|
-
// Use locale-specific groups if provided, otherwise keep default
|
|
126
|
-
groups: localeOverrides.sidebar.groups || sidebarConfig.groups
|
|
127
|
-
} : sidebarConfig;
|
|
128
|
-
const ui = getUITranslations(locale, config);
|
|
129
|
-
return {
|
|
130
|
-
locale: localeInfo,
|
|
131
|
-
site,
|
|
132
|
-
menu: menu2,
|
|
133
|
-
footer,
|
|
134
|
-
sidebar,
|
|
135
|
-
ui
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function t(key, locale, config) {
|
|
139
|
-
const translations = getUITranslations(locale, config);
|
|
140
|
-
return translations[key] || key;
|
|
141
|
-
}
|
|
142
|
-
function formatDate(date, locale, options) {
|
|
143
|
-
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
144
|
-
const defaultOptions = {
|
|
145
|
-
year: "numeric",
|
|
146
|
-
month: "long",
|
|
147
|
-
day: "numeric"
|
|
148
|
-
};
|
|
149
|
-
return new Intl.DateTimeFormat(locale, options || defaultOptions).format(
|
|
150
|
-
dateObj
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
function formatDateShort(date, locale) {
|
|
154
|
-
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
155
|
-
return new Intl.DateTimeFormat(locale, {
|
|
156
|
-
year: "numeric",
|
|
157
|
-
month: "numeric",
|
|
158
|
-
day: "numeric"
|
|
159
|
-
}).format(dateObj);
|
|
160
|
-
}
|
|
161
|
-
function isRTL(locale, config = defaultI18nConfig) {
|
|
162
|
-
const localeData = getLocaleByCode(locale, config);
|
|
163
|
-
return localeData?.direction === "rtl";
|
|
164
|
-
}
|
|
165
|
-
function getTextDirection(locale, config = defaultI18nConfig) {
|
|
166
|
-
return isRTL(locale, config) ? "rtl" : "ltr";
|
|
167
|
-
}
|
|
168
|
-
function isMultiLanguageEnabled(config = defaultI18nConfig) {
|
|
169
|
-
return config.locales.length > 1;
|
|
170
|
-
}
|
|
171
|
-
function getLocalePrefix(locale, config = defaultI18nConfig) {
|
|
172
|
-
if (locale === config.defaultLocale && !config.routing.prefixDefaultLocale) {
|
|
173
|
-
return "";
|
|
174
|
-
}
|
|
175
|
-
return `/${locale}`;
|
|
176
|
-
}
|
|
177
|
-
function getContentPathPrefix(locale, config = defaultI18nConfig) {
|
|
178
|
-
const localeConfig = config.localeConfigs[locale];
|
|
179
|
-
return localeConfig?.contentPathPrefix;
|
|
180
|
-
}
|
|
181
|
-
function filterPostsByLocale(posts, locale, config = defaultI18nConfig) {
|
|
182
|
-
const contentPathPrefix = getContentPathPrefix(locale, config);
|
|
183
|
-
if (!contentPathPrefix) {
|
|
184
|
-
return posts;
|
|
185
|
-
}
|
|
186
|
-
return posts.filter((post) => {
|
|
187
|
-
const postPath = post.id.toLowerCase();
|
|
188
|
-
const prefix = contentPathPrefix.toLowerCase();
|
|
189
|
-
return postPath.startsWith(prefix + "/") || postPath === prefix;
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/utils/useI18n.ts
|
|
194
|
-
import { inject, computed } from "vue";
|
|
195
|
-
var I18N_LOCALE_KEY = /* @__PURE__ */ Symbol("i18n-locale");
|
|
196
|
-
var I18N_CONFIG_KEY = /* @__PURE__ */ Symbol("i18n-config");
|
|
197
|
-
var I18N_TRANSLATIONS_KEY = /* @__PURE__ */ Symbol("i18n-translations");
|
|
198
|
-
function useI18n() {
|
|
199
|
-
const injectedLocale = inject(I18N_LOCALE_KEY, "zh-CN");
|
|
200
|
-
const injectedTranslations = inject(
|
|
201
|
-
I18N_TRANSLATIONS_KEY,
|
|
202
|
-
void 0
|
|
203
|
-
);
|
|
204
|
-
const injectedConfig = inject(I18N_CONFIG_KEY, void 0);
|
|
205
|
-
const locale = computed(() => injectedLocale);
|
|
206
|
-
const translations = computed(() => {
|
|
207
|
-
if (injectedTranslations) {
|
|
208
|
-
return injectedTranslations;
|
|
209
|
-
}
|
|
210
|
-
return getUITranslations(injectedLocale, injectedConfig);
|
|
211
|
-
});
|
|
212
|
-
function t2(key) {
|
|
213
|
-
return translations.value[key] || key;
|
|
214
|
-
}
|
|
215
|
-
function formatDate2(date, options) {
|
|
216
|
-
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
217
|
-
const defaultOptions = {
|
|
218
|
-
year: "numeric",
|
|
219
|
-
month: "long",
|
|
220
|
-
day: "numeric"
|
|
221
|
-
};
|
|
222
|
-
return new Intl.DateTimeFormat(
|
|
223
|
-
locale.value,
|
|
224
|
-
options || defaultOptions
|
|
225
|
-
).format(dateObj);
|
|
226
|
-
}
|
|
227
|
-
function formatDateShort2(date) {
|
|
228
|
-
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
229
|
-
return new Intl.DateTimeFormat(locale.value, {
|
|
230
|
-
year: "numeric",
|
|
231
|
-
month: "numeric",
|
|
232
|
-
day: "numeric"
|
|
233
|
-
}).format(dateObj);
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
locale,
|
|
237
|
-
t: t2,
|
|
238
|
-
formatDate: formatDate2,
|
|
239
|
-
formatDateShort: formatDateShort2,
|
|
240
|
-
translations
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
function createI18nContext(locale, config) {
|
|
244
|
-
return {
|
|
245
|
-
locale,
|
|
246
|
-
translations: getUITranslations(locale, config),
|
|
247
|
-
config
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
61
|
// src/index.ts
|
|
252
62
|
function defineBlogConfig(config) {
|
|
253
63
|
return config;
|
package/dist/integration.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AstroIntegration } from 'astro';
|
|
2
|
-
import { I as I18nConfig } from './i18n-
|
|
2
|
+
import { I as I18nConfig } from './i18n-DYYPTq4o.js';
|
|
3
3
|
import './types/index.js';
|
|
4
|
-
import './sidebar-
|
|
4
|
+
import './sidebar-DNdiCKBw.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @jet-w/astro-blog Integration
|
|
@@ -89,4 +89,4 @@ declare const sidebarConfig: SidebarConfig;
|
|
|
89
89
|
declare function defineSidebarConfig(config: Partial<SidebarConfig>): SidebarConfig;
|
|
90
90
|
declare const defaultSidebarConfig: SidebarConfig;
|
|
91
91
|
|
|
92
|
-
export { type DividerConfig as D, type ManualConfig as M, type PathMatchConfig as P, type
|
|
92
|
+
export { type DividerConfig as D, type ManualConfig as M, type PathMatchConfig as P, type SidebarConfig as S, defineSidebarConfig as a, type SidebarGroup as b, type SidebarItem as c, defaultSidebarConfig as d, type ScanConfig as e, type MixedConfig as f, sidebarConfig as s };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { I as I18nConfig, L as Locale, F as FooterConfig, U as UITranslations } from '../i18n-DYYPTq4o.js';
|
|
2
|
+
export { n as LocaleConfig, j as builtInTranslations, g as defaultI18nConfig, h as defineI18nConfig, k as enTranslations, i as getUITranslations, z as zhCNTranslations } from '../i18n-DYYPTq4o.js';
|
|
3
|
+
import { SiteConfig, NavigationItem } from '../types/index.js';
|
|
4
|
+
import { S as SidebarConfig } from '../sidebar-DNdiCKBw.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* i18n Utility Functions
|
|
8
|
+
*
|
|
9
|
+
* Provides helper functions for multi-language support.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Merged locale configuration with all defaults applied
|
|
14
|
+
*/
|
|
15
|
+
interface MergedLocaleConfig {
|
|
16
|
+
locale: Locale;
|
|
17
|
+
site: SiteConfig;
|
|
18
|
+
menu: NavigationItem[];
|
|
19
|
+
footer: FooterConfig;
|
|
20
|
+
sidebar: SidebarConfig;
|
|
21
|
+
ui: UITranslations;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Alternate link for SEO (hreflang)
|
|
25
|
+
*/
|
|
26
|
+
interface AlternateLink {
|
|
27
|
+
locale: string;
|
|
28
|
+
url: string;
|
|
29
|
+
hreflang: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get current locale from URL pathname
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* getLocaleFromPath('/en/posts', config) // 'en'
|
|
36
|
+
* getLocaleFromPath('/posts', config) // 'zh-CN' (default)
|
|
37
|
+
* getLocaleFromPath('/zh-CN/about', config) // 'zh-CN'
|
|
38
|
+
*/
|
|
39
|
+
declare function getLocaleFromPath(pathname: string, config?: I18nConfig): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get locale data by code
|
|
42
|
+
*/
|
|
43
|
+
declare function getLocaleByCode(code: string, config?: I18nConfig): Locale | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Remove locale prefix from pathname
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* removeLocalePrefix('/en/posts', config) // '/posts'
|
|
49
|
+
* removeLocalePrefix('/posts', config) // '/posts'
|
|
50
|
+
*/
|
|
51
|
+
declare function removeLocalePrefix(pathname: string, config?: I18nConfig): string;
|
|
52
|
+
/**
|
|
53
|
+
* Get localized path for a given locale
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* getLocalizedPath('/posts', 'en', config) // '/en/posts'
|
|
57
|
+
* getLocalizedPath('/en/posts', 'zh-CN', config) // '/posts' (if zh-CN is default)
|
|
58
|
+
*/
|
|
59
|
+
declare function getLocalizedPath(pathname: string, targetLocale: string, config?: I18nConfig): string;
|
|
60
|
+
/**
|
|
61
|
+
* Get all alternate links for SEO (hreflang tags)
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* getAlternateLinks('/posts', 'https://example.com', config)
|
|
65
|
+
* // Returns links for all locales
|
|
66
|
+
*/
|
|
67
|
+
declare function getAlternateLinks(pathname: string, baseUrl: string, config?: I18nConfig): AlternateLink[];
|
|
68
|
+
/**
|
|
69
|
+
* Get merged configuration for a specific locale
|
|
70
|
+
* Combines default config with locale-specific overrides
|
|
71
|
+
*/
|
|
72
|
+
declare function getLocaleConfig(locale: string, config?: I18nConfig): MergedLocaleConfig;
|
|
73
|
+
/**
|
|
74
|
+
* Translation function - get a UI translation string
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* t('readMore', 'en') // 'Read more'
|
|
78
|
+
* t('readMore', 'zh-CN') // '阅读更多'
|
|
79
|
+
*/
|
|
80
|
+
declare function t(key: keyof UITranslations, locale: string, config?: I18nConfig): string;
|
|
81
|
+
/**
|
|
82
|
+
* Format date according to locale
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* formatDate(new Date(), 'en') // 'January 1, 2024'
|
|
86
|
+
* formatDate(new Date(), 'zh-CN') // '2024年1月1日'
|
|
87
|
+
*/
|
|
88
|
+
declare function formatDate(date: Date | string, locale: string, options?: Intl.DateTimeFormatOptions): string;
|
|
89
|
+
/**
|
|
90
|
+
* Format date in short format
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* formatDateShort(new Date(), 'en') // '1/1/2024'
|
|
94
|
+
* formatDateShort(new Date(), 'zh-CN') // '2024/1/1'
|
|
95
|
+
*/
|
|
96
|
+
declare function formatDateShort(date: Date | string, locale: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a locale is RTL (right-to-left)
|
|
99
|
+
*/
|
|
100
|
+
declare function isRTL(locale: string, config?: I18nConfig): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Get the HTML dir attribute value
|
|
103
|
+
*/
|
|
104
|
+
declare function getTextDirection(locale: string, config?: I18nConfig): 'ltr' | 'rtl';
|
|
105
|
+
/**
|
|
106
|
+
* Check if multi-language is enabled (more than one locale)
|
|
107
|
+
*/
|
|
108
|
+
declare function isMultiLanguageEnabled(config?: I18nConfig): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get prefix for a locale in routes
|
|
111
|
+
* Returns empty string for default locale if prefixDefaultLocale is false
|
|
112
|
+
*/
|
|
113
|
+
declare function getLocalePrefix(locale: string, config?: I18nConfig): string;
|
|
114
|
+
/**
|
|
115
|
+
* Get content path prefix for a specific locale
|
|
116
|
+
* Returns the contentPathPrefix from locale config, or undefined if not set
|
|
117
|
+
*/
|
|
118
|
+
declare function getContentPathPrefix(locale: string, config?: I18nConfig): string | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Filter posts by locale based on contentPathPrefix
|
|
121
|
+
* If contentPathPrefix is set, only return posts that start with that prefix
|
|
122
|
+
* If not set, return all posts (backward compatible)
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* // If en locale has contentPathPrefix: 'blog_docs_en'
|
|
126
|
+
* filterPostsByLocale(posts, 'en', config)
|
|
127
|
+
* // Returns only posts with id starting with 'blog_docs_en/'
|
|
128
|
+
*/
|
|
129
|
+
declare function filterPostsByLocale<T extends {
|
|
130
|
+
id: string;
|
|
131
|
+
}>(posts: T[], locale: string, config?: I18nConfig): T[];
|
|
132
|
+
|
|
133
|
+
export { type AlternateLink, I18nConfig, Locale, type MergedLocaleConfig, UITranslations, filterPostsByLocale, formatDate, formatDateShort, getAlternateLinks, getContentPathPrefix, getLocaleByCode, getLocaleConfig, getLocaleFromPath, getLocalePrefix, getLocalizedPath, getTextDirection, isMultiLanguageEnabled, isRTL, removeLocalePrefix, t };
|