@jet-w/astro-blog 0.1.6 → 0.2.0
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-ATRISB7B.js +206 -0
- package/dist/chunk-HVQKQN6B.js +145 -0
- package/dist/config/index.d.ts +3 -47
- package/dist/config/index.js +18 -2
- package/dist/i18n-5H4W145i.d.ts +202 -0
- package/dist/index.d.ts +186 -7
- package/dist/index.js +238 -3
- package/dist/integration.d.ts +9 -1
- package/dist/integration.js +2 -1
- package/dist/{sidebar-DNdiCKBw.d.ts → sidebar-Da-W_4Lr.d.ts} +1 -1
- package/dist/utils/sidebar.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/layout/Footer.astro +36 -20
- package/src/components/layout/Header.astro +69 -15
- package/src/components/layout/Sidebar.astro +27 -15
- package/src/components/ui/LanguageSwitcher.vue +183 -0
- package/src/layouts/BaseLayout.astro +77 -52
- package/src/layouts/PageLayout.astro +22 -27
- package/src/layouts/SlidesLayout.astro +14 -2
- package/src/pages/rss.xml.ts +18 -6
- package/templates/default/astro.config.mjs +22 -2
- package/templates/default/content/posts/blog_docs/12-i18n.md +355 -0
- package/templates/default/content/posts/blog_docs/README.md +1 -0
- package/templates/default/content/posts/blog_docs_en/README.md +78 -0
- package/templates/default/content/posts/blog_docs_en/config/01-site.md +208 -0
- package/templates/default/content/posts/blog_docs_en/config/02-sidebar.md +240 -0
- package/templates/default/content/posts/blog_docs_en/config/03-i18n.md +285 -0
- package/templates/default/content/posts/blog_docs_en/config/README.md +85 -0
- package/templates/default/content/posts/blog_docs_en/get-started/01-intro.md +81 -0
- package/templates/default/content/posts/blog_docs_en/get-started/02-install.md +137 -0
- package/templates/default/content/posts/blog_docs_en/get-started/03-create-post.md +176 -0
- package/templates/default/content/posts/blog_docs_en/get-started/04-structure.md +173 -0
- package/templates/default/content/posts/blog_docs_en/get-started/05-deploy.md +197 -0
- package/templates/default/content/posts/blog_docs_en/get-started/README.md +52 -0
- package/templates/default/content/posts/blog_docs_en/guide/README.md +59 -0
- package/templates/default/content/posts/blog_docs_en/guide/features/01-mermaid.md +194 -0
- package/templates/default/content/posts/blog_docs_en/guide/features/02-latex.md +233 -0
- package/templates/default/content/posts/blog_docs_en/guide/features/03-video.md +184 -0
- package/templates/default/content/posts/blog_docs_en/guide/features/04-icons.md +227 -0
- package/templates/default/content/posts/blog_docs_en/guide/features/README.md +51 -0
- package/templates/default/content/posts/blog_docs_en/guide/markdown/02-containers.md +226 -0
- package/templates/default/content/posts/blog_docs_en/guide/markdown/03-code-blocks.md +206 -0
- package/templates/default/content/posts/blog_docs_en/guide/markdown/README.md +194 -0
- package/templates/default/package-lock.json +9667 -0
- package/templates/default/package.json +1 -1
- package/templates/default/src/config/footer.ts +14 -11
- package/templates/default/src/config/locales/en/footer.ts +17 -0
- package/templates/default/src/config/locales/en/index.ts +16 -0
- package/templates/default/src/config/locales/en/menu.ts +12 -0
- package/templates/default/src/config/locales/en/sidebar.ts +18 -0
- package/templates/default/src/config/locales/en/site.ts +7 -0
- package/templates/default/src/config/locales/index.ts +7 -0
- package/templates/default/src/config/locales/zh-CN/footer.ts +17 -0
- package/templates/default/src/config/locales/zh-CN/index.ts +16 -0
- package/templates/default/src/config/locales/zh-CN/menu.ts +12 -0
- package/templates/default/src/config/locales/zh-CN/sidebar.ts +18 -0
- package/templates/default/src/config/locales/zh-CN/site.ts +7 -0
- package/templates/default/src/config/sidebar.ts +10 -12
- package/templates/default/src/env.d.ts +7 -0
- package/dist/chunk-MQXPSOYB.js +0 -124
- /package/dist/{chunk-GYLSY3OJ.js → chunk-AZHCNNAC.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export { defaultMenu, defaultSEO, defaultSiteConfig, defineMenu, defineSiteConfig, menu, siteConfig } from './config/index.js';
|
|
2
|
+
import { b as SidebarConfig } from './sidebar-Da-W_4Lr.js';
|
|
3
|
+
export { D as DividerConfig, M as ManualConfig, f as MixedConfig, P as PathMatchConfig, e as ScanConfig, a as SidebarGroup, S as SidebarItem, d as defaultSidebarConfig, c as defineSidebarConfig, s as sidebarConfig } from './sidebar-Da-W_4Lr.js';
|
|
4
|
+
import { I as I18nConfig, L as Locale, F as FooterConfig, U as UITranslations, S as SocialLink } from './i18n-5H4W145i.js';
|
|
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-5H4W145i.js';
|
|
6
|
+
import { SiteConfig, NavigationItem } from './types/index.js';
|
|
7
|
+
export { BlogPost, Category, PostFrontmatter, SEOProps, SearchResult, Tag } from './types/index.js';
|
|
7
8
|
export { AstroBlogIntegrationOptions, default as astroBlog, default as astroBlogIntegration } from './integration.js';
|
|
9
|
+
import { ComputedRef } from 'vue';
|
|
8
10
|
import 'astro';
|
|
9
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
|
+
/**
|
|
122
|
+
* Vue Composable for i18n
|
|
123
|
+
*
|
|
124
|
+
* Provides i18n support for Vue components in the blog.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* i18n injection keys
|
|
129
|
+
*/
|
|
130
|
+
declare const I18N_LOCALE_KEY: unique symbol;
|
|
131
|
+
declare const I18N_CONFIG_KEY: unique symbol;
|
|
132
|
+
declare const I18N_TRANSLATIONS_KEY: unique symbol;
|
|
133
|
+
/**
|
|
134
|
+
* i18n context provided to Vue components
|
|
135
|
+
*/
|
|
136
|
+
interface I18nContext {
|
|
137
|
+
locale: string;
|
|
138
|
+
translations: UITranslations;
|
|
139
|
+
config?: I18nConfig;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Return type of useI18n composable
|
|
143
|
+
*/
|
|
144
|
+
interface UseI18nReturn {
|
|
145
|
+
/** Current locale code */
|
|
146
|
+
locale: ComputedRef<string>;
|
|
147
|
+
/** Translation function */
|
|
148
|
+
t: (key: keyof UITranslations) => string;
|
|
149
|
+
/** Format date according to locale */
|
|
150
|
+
formatDate: (date: Date | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
151
|
+
/** Format date in short format */
|
|
152
|
+
formatDateShort: (date: Date | string) => string;
|
|
153
|
+
/** All translations for current locale */
|
|
154
|
+
translations: ComputedRef<UITranslations>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Vue composable for i18n support
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```vue
|
|
161
|
+
* <script setup>
|
|
162
|
+
* import { useI18n } from '@jet-w/astro-blog/utils/useI18n';
|
|
163
|
+
*
|
|
164
|
+
* const { t, formatDate, locale } = useI18n();
|
|
165
|
+
* </script>
|
|
166
|
+
*
|
|
167
|
+
* <template>
|
|
168
|
+
* <h1>{{ t('postList') }}</h1>
|
|
169
|
+
* <span>{{ formatDate(post.pubDate) }}</span>
|
|
170
|
+
* </template>
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function useI18n(): UseI18nReturn;
|
|
174
|
+
/**
|
|
175
|
+
* Create i18n context for providing to Vue components
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```astro
|
|
179
|
+
* ---
|
|
180
|
+
* import { createI18nContext } from '@jet-w/astro-blog/utils/useI18n';
|
|
181
|
+
* const i18nContext = createI18nContext('en', i18nConfig);
|
|
182
|
+
* ---
|
|
183
|
+
* <Component client:load {...i18nContext} />
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function createI18nContext(locale: string, config?: I18nConfig): I18nContext;
|
|
187
|
+
|
|
10
188
|
/**
|
|
11
189
|
* Define blog configuration helper
|
|
12
190
|
*/
|
|
@@ -15,6 +193,7 @@ interface BlogConfig {
|
|
|
15
193
|
sidebar?: SidebarConfig;
|
|
16
194
|
footer?: FooterConfig;
|
|
17
195
|
social?: SocialLink[];
|
|
196
|
+
i18n?: I18nConfig;
|
|
18
197
|
}
|
|
19
198
|
declare function defineBlogConfig(config: BlogConfig): BlogConfig;
|
|
20
199
|
/**
|
|
@@ -35,4 +214,4 @@ declare function getAstroConfig(options?: {
|
|
|
35
214
|
};
|
|
36
215
|
};
|
|
37
216
|
|
|
38
|
-
export { type BlogConfig, FooterConfig, SidebarConfig, SiteConfig, SocialLink, defineBlogConfig, getAstroConfig };
|
|
217
|
+
export { type AlternateLink, type BlogConfig, FooterConfig, I18N_CONFIG_KEY, I18N_LOCALE_KEY, I18N_TRANSLATIONS_KEY, I18nConfig, type I18nContext, Locale, type MergedLocaleConfig, NavigationItem, SidebarConfig, SiteConfig, SocialLink, UITranslations, type UseI18nReturn, createI18nContext, defineBlogConfig, formatDate, formatDateShort, getAlternateLinks, getAstroConfig, getLocaleByCode, getLocaleConfig, getLocaleFromPath, getLocalePrefix, getLocalizedPath, getTextDirection, isMultiLanguageEnabled, isRTL, removeLocalePrefix, t, useI18n };
|
package/dist/index.js
CHANGED
|
@@ -16,12 +16,222 @@ import {
|
|
|
16
16
|
sidebarConfig,
|
|
17
17
|
siteConfig,
|
|
18
18
|
socialLinks
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-AZHCNNAC.js";
|
|
20
20
|
import "./chunk-FXPGR372.js";
|
|
21
21
|
import {
|
|
22
22
|
astroBlogIntegration,
|
|
23
23
|
integration_default
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-HVQKQN6B.js";
|
|
25
|
+
import {
|
|
26
|
+
builtInTranslations,
|
|
27
|
+
defaultI18nConfig,
|
|
28
|
+
defaultLocales,
|
|
29
|
+
defineI18nConfig,
|
|
30
|
+
enTranslations,
|
|
31
|
+
getUITranslations,
|
|
32
|
+
zhCNTranslations
|
|
33
|
+
} from "./chunk-ATRISB7B.js";
|
|
34
|
+
|
|
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
|
+
|
|
178
|
+
// src/utils/useI18n.ts
|
|
179
|
+
import { inject, computed } from "vue";
|
|
180
|
+
var I18N_LOCALE_KEY = /* @__PURE__ */ Symbol("i18n-locale");
|
|
181
|
+
var I18N_CONFIG_KEY = /* @__PURE__ */ Symbol("i18n-config");
|
|
182
|
+
var I18N_TRANSLATIONS_KEY = /* @__PURE__ */ Symbol("i18n-translations");
|
|
183
|
+
function useI18n() {
|
|
184
|
+
const injectedLocale = inject(I18N_LOCALE_KEY, "zh-CN");
|
|
185
|
+
const injectedTranslations = inject(
|
|
186
|
+
I18N_TRANSLATIONS_KEY,
|
|
187
|
+
void 0
|
|
188
|
+
);
|
|
189
|
+
const injectedConfig = inject(I18N_CONFIG_KEY, void 0);
|
|
190
|
+
const locale = computed(() => injectedLocale);
|
|
191
|
+
const translations = computed(() => {
|
|
192
|
+
if (injectedTranslations) {
|
|
193
|
+
return injectedTranslations;
|
|
194
|
+
}
|
|
195
|
+
return getUITranslations(injectedLocale, injectedConfig);
|
|
196
|
+
});
|
|
197
|
+
function t2(key) {
|
|
198
|
+
return translations.value[key] || key;
|
|
199
|
+
}
|
|
200
|
+
function formatDate2(date, options) {
|
|
201
|
+
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
202
|
+
const defaultOptions = {
|
|
203
|
+
year: "numeric",
|
|
204
|
+
month: "long",
|
|
205
|
+
day: "numeric"
|
|
206
|
+
};
|
|
207
|
+
return new Intl.DateTimeFormat(
|
|
208
|
+
locale.value,
|
|
209
|
+
options || defaultOptions
|
|
210
|
+
).format(dateObj);
|
|
211
|
+
}
|
|
212
|
+
function formatDateShort2(date) {
|
|
213
|
+
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
214
|
+
return new Intl.DateTimeFormat(locale.value, {
|
|
215
|
+
year: "numeric",
|
|
216
|
+
month: "numeric",
|
|
217
|
+
day: "numeric"
|
|
218
|
+
}).format(dateObj);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
locale,
|
|
222
|
+
t: t2,
|
|
223
|
+
formatDate: formatDate2,
|
|
224
|
+
formatDateShort: formatDateShort2,
|
|
225
|
+
translations
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function createI18nContext(locale, config) {
|
|
229
|
+
return {
|
|
230
|
+
locale,
|
|
231
|
+
translations: getUITranslations(locale, config),
|
|
232
|
+
config
|
|
233
|
+
};
|
|
234
|
+
}
|
|
25
235
|
|
|
26
236
|
// src/index.ts
|
|
27
237
|
function defineBlogConfig(config) {
|
|
@@ -41,10 +251,17 @@ function getAstroConfig(options) {
|
|
|
41
251
|
};
|
|
42
252
|
}
|
|
43
253
|
export {
|
|
254
|
+
I18N_CONFIG_KEY,
|
|
255
|
+
I18N_LOCALE_KEY,
|
|
256
|
+
I18N_TRANSLATIONS_KEY,
|
|
44
257
|
integration_default as astroBlog,
|
|
45
258
|
astroBlogIntegration,
|
|
259
|
+
builtInTranslations,
|
|
260
|
+
createI18nContext,
|
|
46
261
|
defaultFooterConfig,
|
|
262
|
+
defaultI18nConfig,
|
|
47
263
|
defaultIcons,
|
|
264
|
+
defaultLocales,
|
|
48
265
|
defaultMenu,
|
|
49
266
|
defaultSEO,
|
|
50
267
|
defaultSidebarConfig,
|
|
@@ -52,14 +269,32 @@ export {
|
|
|
52
269
|
defaultSocialLinks,
|
|
53
270
|
defineBlogConfig,
|
|
54
271
|
defineFooterConfig,
|
|
272
|
+
defineI18nConfig,
|
|
55
273
|
defineMenu,
|
|
56
274
|
defineSidebarConfig,
|
|
57
275
|
defineSiteConfig,
|
|
58
276
|
defineSocialLinks,
|
|
277
|
+
enTranslations,
|
|
59
278
|
footerConfig,
|
|
279
|
+
formatDate,
|
|
280
|
+
formatDateShort,
|
|
281
|
+
getAlternateLinks,
|
|
60
282
|
getAstroConfig,
|
|
283
|
+
getLocaleByCode,
|
|
284
|
+
getLocaleConfig,
|
|
285
|
+
getLocaleFromPath,
|
|
286
|
+
getLocalePrefix,
|
|
287
|
+
getLocalizedPath,
|
|
288
|
+
getTextDirection,
|
|
289
|
+
getUITranslations,
|
|
290
|
+
isMultiLanguageEnabled,
|
|
291
|
+
isRTL,
|
|
61
292
|
menu,
|
|
293
|
+
removeLocalePrefix,
|
|
62
294
|
sidebarConfig,
|
|
63
295
|
siteConfig,
|
|
64
|
-
socialLinks
|
|
296
|
+
socialLinks,
|
|
297
|
+
t,
|
|
298
|
+
useI18n,
|
|
299
|
+
zhCNTranslations
|
|
65
300
|
};
|
package/dist/integration.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { I as I18nConfig } from './i18n-5H4W145i.js';
|
|
3
|
+
import './types/index.js';
|
|
4
|
+
import './sidebar-Da-W_4Lr.js';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* @jet-w/astro-blog Integration
|
|
5
8
|
*
|
|
6
9
|
* This integration injects the blog pages into your Astro project
|
|
10
|
+
* with multi-language support.
|
|
7
11
|
*/
|
|
8
12
|
|
|
9
13
|
interface AstroBlogIntegrationOptions {
|
|
@@ -19,7 +23,11 @@ interface AstroBlogIntegrationOptions {
|
|
|
19
23
|
search?: boolean;
|
|
20
24
|
rss?: boolean;
|
|
21
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* i18n configuration for multi-language support
|
|
28
|
+
*/
|
|
29
|
+
i18n?: I18nConfig;
|
|
22
30
|
}
|
|
23
31
|
declare function astroBlogIntegration(options?: AstroBlogIntegrationOptions): AstroIntegration;
|
|
24
32
|
|
|
25
|
-
export { type AstroBlogIntegrationOptions, astroBlogIntegration, astroBlogIntegration as default };
|
|
33
|
+
export { type AstroBlogIntegrationOptions, I18nConfig, astroBlogIntegration, astroBlogIntegration as default };
|
package/dist/integration.js
CHANGED
|
@@ -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 SidebarItem as S, type SidebarGroup as a, type SidebarConfig as b, defineSidebarConfig as c, defaultSidebarConfig as d, type ScanConfig as e, type MixedConfig as f, sidebarConfig as s };
|
package/dist/utils/sidebar.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { siteConfig, footerConfig, defaultIcons } from '@jet-w/astro-blog/config';
|
|
3
|
+
import type { I18nConfig } from '../../config/i18n';
|
|
4
|
+
import { defaultI18nConfig } from '../../config/i18n';
|
|
5
|
+
import { getLocaleFromPath, getLocaleConfig, getLocalePrefix } from '../../utils/i18n';
|
|
6
|
+
|
|
7
|
+
export interface Props {
|
|
8
|
+
i18nConfig?: I18nConfig;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { i18nConfig = defaultI18nConfig } = Astro.props;
|
|
12
|
+
|
|
13
|
+
const currentLocale = getLocaleFromPath(Astro.url.pathname, i18nConfig);
|
|
14
|
+
const localeConfig = getLocaleConfig(currentLocale, i18nConfig);
|
|
15
|
+
const ui = localeConfig.ui;
|
|
16
|
+
|
|
17
|
+
// Use locale-specific configs
|
|
18
|
+
const localeSiteConfig = localeConfig.site;
|
|
19
|
+
const localeFooterConfig = localeConfig.footer;
|
|
3
20
|
|
|
4
21
|
const currentYear = new Date().getFullYear();
|
|
5
22
|
|
|
@@ -7,43 +24,44 @@ function getIcon(link: { type: string; icon?: string }): string {
|
|
|
7
24
|
return link.icon || defaultIcons[link.type] || '';
|
|
8
25
|
}
|
|
9
26
|
|
|
10
|
-
//
|
|
11
|
-
const
|
|
27
|
+
// Get locale prefix for RSS link
|
|
28
|
+
const localePrefix = getLocalePrefix(currentLocale, i18nConfig);
|
|
29
|
+
const rssUrl = localeFooterConfig.rssUrl || footerConfig.rssUrl || `${localePrefix}/rss.xml`;
|
|
30
|
+
|
|
31
|
+
const copyright = (localeFooterConfig.copyright || footerConfig.copyright)
|
|
12
32
|
.replace('{year}', String(currentYear))
|
|
13
|
-
.replace('{author}', siteConfig.author);
|
|
33
|
+
.replace('{author}', localeSiteConfig.author || siteConfig.author);
|
|
14
34
|
---
|
|
15
35
|
|
|
16
36
|
<footer class="bg-slate-50 dark:bg-slate-800 border-t border-slate-200 dark:border-slate-700 mt-auto w-full min-w-0">
|
|
17
37
|
<div class="container mx-auto px-4 py-6">
|
|
18
38
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
|
19
|
-
<!-- 站点信息 -->
|
|
20
39
|
<div>
|
|
21
40
|
<div class="flex items-center space-x-3 mb-3">
|
|
22
|
-
{siteConfig.avatar && (
|
|
41
|
+
{(localeSiteConfig.avatar || siteConfig.avatar) && (
|
|
23
42
|
<img
|
|
24
|
-
src={siteConfig.avatar}
|
|
25
|
-
alt={siteConfig.title}
|
|
43
|
+
src={localeSiteConfig.avatar || siteConfig.avatar}
|
|
44
|
+
alt={localeSiteConfig.title || siteConfig.title}
|
|
26
45
|
class="w-8 h-8 rounded-full"
|
|
27
46
|
/>
|
|
28
47
|
)}
|
|
29
48
|
<div>
|
|
30
49
|
<h3 class="text-base font-semibold text-slate-900 dark:text-slate-100">
|
|
31
|
-
{siteConfig.title}
|
|
50
|
+
{localeSiteConfig.title || siteConfig.title}
|
|
32
51
|
</h3>
|
|
33
52
|
<p class="text-xs text-slate-600 dark:text-slate-400">
|
|
34
|
-
{siteConfig.description}
|
|
53
|
+
{localeSiteConfig.description || siteConfig.description}
|
|
35
54
|
</p>
|
|
36
55
|
</div>
|
|
37
56
|
</div>
|
|
38
57
|
</div>
|
|
39
58
|
|
|
40
|
-
<!-- 快速链接 -->
|
|
41
59
|
<div>
|
|
42
60
|
<h4 class="text-sm font-semibold text-slate-900 dark:text-slate-100 mb-3">
|
|
43
|
-
{footerConfig.quickLinksTitle}
|
|
61
|
+
{localeFooterConfig.quickLinksTitle || footerConfig.quickLinksTitle || ui.quickLinks}
|
|
44
62
|
</h4>
|
|
45
63
|
<div class="flex flex-wrap gap-x-4 gap-y-1">
|
|
46
|
-
{footerConfig.quickLinks.map((item) => (
|
|
64
|
+
{(localeFooterConfig.quickLinks || footerConfig.quickLinks).map((item) => (
|
|
47
65
|
<a
|
|
48
66
|
href={item.href}
|
|
49
67
|
class="text-sm text-slate-600 dark:text-slate-400 hover:text-primary-500 transition-colors"
|
|
@@ -54,13 +72,12 @@ const copyright = footerConfig.copyright
|
|
|
54
72
|
</div>
|
|
55
73
|
</div>
|
|
56
74
|
|
|
57
|
-
<!-- 社交链接 -->
|
|
58
75
|
<div>
|
|
59
76
|
<h4 class="text-sm font-semibold text-slate-900 dark:text-slate-100 mb-3">
|
|
60
|
-
{footerConfig.contactTitle}
|
|
77
|
+
{localeFooterConfig.contactTitle || footerConfig.contactTitle || ui.contact}
|
|
61
78
|
</h4>
|
|
62
79
|
<div class="flex space-x-4">
|
|
63
|
-
{footerConfig.socialLinks.map((link) => (
|
|
80
|
+
{(localeFooterConfig.socialLinks || footerConfig.socialLinks).map((link) => (
|
|
64
81
|
<a
|
|
65
82
|
href={link.url}
|
|
66
83
|
target={link.type === 'email' ? undefined : '_blank'}
|
|
@@ -74,11 +91,11 @@ const copyright = footerConfig.copyright
|
|
|
74
91
|
</a>
|
|
75
92
|
))}
|
|
76
93
|
|
|
77
|
-
{footerConfig.showRss && (
|
|
94
|
+
{(localeFooterConfig.showRss ?? footerConfig.showRss) && (
|
|
78
95
|
<a
|
|
79
|
-
href={
|
|
96
|
+
href={rssUrl}
|
|
80
97
|
class="text-slate-600 dark:text-slate-400 hover:text-primary-500 transition-colors"
|
|
81
|
-
aria-label=
|
|
98
|
+
aria-label={ui.rssFeed}
|
|
82
99
|
>
|
|
83
100
|
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
|
|
84
101
|
<path d="M3.429 2.486c9.36 0 16.943 7.583 16.943 16.943h-3.257c0-7.563-6.123-13.686-13.686-13.686V2.486zM3.429 9.114c5.647 0 10.229 4.581 10.229 10.229h-3.257c0-3.844-3.128-6.972-6.972-6.972V9.114zM6.686 16.486c0 1.8-1.457 3.257-3.257 3.257S0.172 18.286 0.172 16.486s1.457-3.257 3.257-3.257 3.257 1.457 3.257 3.257z"/>
|
|
@@ -89,12 +106,11 @@ const copyright = footerConfig.copyright
|
|
|
89
106
|
</div>
|
|
90
107
|
</div>
|
|
91
108
|
|
|
92
|
-
<!-- 版权信息 -->
|
|
93
109
|
<div class="border-t border-slate-200 dark:border-slate-700 pt-4 mt-6">
|
|
94
110
|
<div class="flex flex-col sm:flex-row justify-between items-center text-sm text-slate-600 dark:text-slate-400">
|
|
95
111
|
<p>{copyright}</p>
|
|
96
112
|
<p class="mt-2 sm:mt-0">
|
|
97
|
-
Powered by <a href={footerConfig.poweredBy.url} class="link" target="_blank" rel="noopener noreferrer">{footerConfig.poweredBy.text}</a>
|
|
113
|
+
Powered by <a href={(localeFooterConfig.poweredBy || footerConfig.poweredBy).url} class="link" target="_blank" rel="noopener noreferrer">{(localeFooterConfig.poweredBy || footerConfig.poweredBy).text}</a>
|
|
98
114
|
</p>
|
|
99
115
|
</div>
|
|
100
116
|
</div>
|