mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 16:29:47 +02:00
refactor(theme): dates should be formatted on the client-side instead of in nodejs code (#9868)
Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
6bf21d215c
commit
0279c329ad
15 changed files with 83 additions and 162 deletions
|
@ -114,6 +114,7 @@ export {
|
|||
} from './hooks/useTOCHighlight';
|
||||
|
||||
export {useVisibleBlogSidebarItems} from './utils/blogUtils';
|
||||
export {useDateTimeFormat} from './utils/IntlUtils';
|
||||
|
||||
export {useHideableNavbar} from './hooks/useHideableNavbar';
|
||||
export {
|
||||
|
|
27
packages/docusaurus-theme-common/src/utils/IntlUtils.ts
Normal file
27
packages/docusaurus-theme-common/src/utils/IntlUtils.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
export function useCalendar(): string {
|
||||
const {
|
||||
i18n: {currentLocale, localeConfigs},
|
||||
} = useDocusaurusContext();
|
||||
return localeConfigs[currentLocale]!.calendar;
|
||||
}
|
||||
|
||||
export function useDateTimeFormat(
|
||||
options: Intl.DateTimeFormatOptions = {},
|
||||
): Intl.DateTimeFormat {
|
||||
const {
|
||||
i18n: {currentLocale},
|
||||
} = useDocusaurusContext();
|
||||
const calendar = useCalendar();
|
||||
return new Intl.DateTimeFormat(currentLocale, {
|
||||
calendar,
|
||||
...options,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue