Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add locale configuration #59

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/Datetime.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LOCALE } from "@config";

export interface Props {
datetime: string | Date;
size?: "sm" | "lg";
Expand Down Expand Up @@ -28,13 +30,13 @@ export default function Datetime({ datetime, size = "sm", className }: Props) {
const FormattedDatetime = ({ datetime }: { datetime: string | Date }) => {
const myDatetime = new Date(datetime);

const date = myDatetime.toLocaleDateString([], {
const date = myDatetime.toLocaleDateString(LOCALE, {
year: "numeric",
month: "long",
day: "numeric",
});

const time = myDatetime.toLocaleTimeString([], {
const time = myDatetime.toLocaleTimeString(LOCALE, {
hour: "2-digit",
minute: "2-digit",
});
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const SITE: Site = {
postPerPage: 3,
};

export const LOCALE = ["en-EN"]; // set to [] to use the environment default

export const LOGO_IMAGE = {
enable: false,
svg: true,
Expand Down
11 changes: 11 additions & 0 deletions src/content/blog/how-to-configure-astropaper-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Here are SITE configuration options
| `lightAndDarkMode` | Enable or disable `light & dark mode` for the website. If disabled, primary color scheme will be used. This option is enabled by default. |
| `postPerPage` | You can specify how many posts will be displayed in each posts page. (eg: if you set SITE.postPerPage to 3, each page will only show 3 posts per page) |

## Configuring locale

You can configure the default locale used for the build (e.g., date format in the post page), and for the rendering in browsers (e.g., date format in the search page)

```js
// file: src/config.ts
export const LOCALE = ["en-EN"]; // set to [] to use the environment default
```

You can even specify an array of locales for fallback languages. Leave it empty `[]` to use the environment default at _build-_ and _run-time_.

## Configuring logo or title

You can specify site's title or logo image in `src/config.ts` file.
Expand Down