Skip to content

Commit ada4dd1

Browse files
authored
update post template (#48)
1 parent 383361e commit ada4dd1

7 files changed

Lines changed: 75 additions & 22 deletions

File tree

app/content/posts/personal-website/dagger-io.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
nanoId: qs05qpu3c0p78ww123zv1
3-
title: How I added dagger.io
3+
title: How I added dagger.io to my personal website
44
date: 2024-04-18
55
wip: true
66
---
@@ -17,6 +17,6 @@ I'm hosting my website on [Github Pages](https://pages.github.com/), using 3 env
1717
- `Staging`: [https://stg-n8v.github.io/](https://stg-n8v.github.io/)
1818
- `Production`: [https://ndthanhdev.github.io/](https://ndthanhdev.github.io/)
1919

20-
I want to apply "Trunk Based Development", so whenever I push a commit to `main` branch, the site should be published to `development`. Whenever a merge request is merged to `release-<version>` branch, the site should be published to `staging`. And when I create a release(a tag), the site should be published to `production`.
20+
I want to apply "Trunk Based Development", so whenever I push a commit to `main` branch, the site should be published to `development`. Whenever a merge request is merged to `release-<version>` branch, the site should be published to `staging`. And when I create a release (a tag), the site should be published to `production`.
2121

2222
{/* Add a pic */}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Stack, { StackProps } from "@mui/material/Stack";
2+
import Typography from "@mui/material/Typography";
3+
import { DateTime } from "luxon";
4+
import * as React from "react";
5+
6+
export type PostHeaderProps = Omit<
7+
StackProps<
8+
"div",
9+
{
10+
title?: string | null;
11+
date?: string | null;
12+
}
13+
>,
14+
"sx"
15+
>;
16+
17+
export const PostHeader = ({ title, date, ...stackProps }: PostHeaderProps) => {
18+
const formatterDate = date
19+
? DateTime.fromISO(date).toLocaleString(DateTime.DATE_FULL)
20+
: "";
21+
22+
return (
23+
<Stack {...stackProps}>
24+
<Typography variant="h2">{title}</Typography>
25+
<Typography variant="subtitle1">{formatterDate}</Typography>
26+
</Stack>
27+
);
28+
};

app/src/components/templates/post/index.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@ import { Container } from "@mui/material";
22
import React from "react";
33

44
import { AppDrawer, AppDrawerProps } from "@/components/organisms/app-drawer";
5+
import { AppFooter, AppFooterProps } from "@/components/organisms/app-footer";
56
import { AppHeader, AppHeaderProps } from "@/components/organisms/app-header";
7+
import {
8+
PostHeader,
9+
PostHeaderProps,
10+
} from "@/components/organisms/post-header";
11+
12+
import { styles } from "./styles";
613

714
export type PostTemplateProps = React.PropsWithChildren<{
815
appDrawerProps: AppDrawerProps;
916
appHeaderProps: AppHeaderProps;
17+
appFooterProps: AppFooterProps;
18+
postHeaderProps: PostHeaderProps;
1019
}>;
1120

1221
export const PostTemplate = ({
1322
appDrawerProps,
1423
appHeaderProps,
24+
appFooterProps,
25+
postHeaderProps,
1526
children,
1627
}: PostTemplateProps) => (
1728
<>
1829
<AppHeader {...appHeaderProps} />
1930
<AppDrawer {...appDrawerProps} />
20-
<Container maxWidth="md">{children}</Container>
31+
<Container maxWidth="md" css={styles.main}>
32+
<PostHeader {...postHeaderProps} css={styles.header} />
33+
{children}
34+
</Container>
35+
<AppFooter {...appFooterProps} />
2136
</>
2237
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { css } from "@emotion/react";
2+
3+
import { AppTheme } from "@/theme";
4+
5+
export const styles = {
6+
main: (theme: AppTheme) =>
7+
css({
8+
minHeight: "95vh",
9+
marginBlockStart: theme.spacing(6),
10+
marginBlockEnd: theme.spacing(4),
11+
}),
12+
13+
header: (theme: AppTheme) =>
14+
css({
15+
marginBlockEnd: theme.spacing(4),
16+
}),
17+
};

app/src/gatsby-types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@ type PostTemplateQueryVariables = Exact<{
26012601
}>;
26022602

26032603

2604-
type PostTemplateQuery = { readonly mdx: { readonly frontmatter: { readonly title: string | null } | null } | null };
2604+
type PostTemplateQuery = { readonly mdx: { readonly frontmatter: { readonly title: string | null, readonly date: string | null } | null } | null };
26052605

26062606
type SiteMetadataQueryVariables = Exact<{ [key: string]: never; }>;
26072607

app/src/layouts/post/index.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ import * as React from "react";
33

44
import { MyHelmet } from "@/components/atoms/my-helmet";
55
import { PostTemplate } from "@/components/templates/post";
6+
import { useMainTemplateProps } from "@/hooks/use-main-template-props";
67
import { AppMDXProvider } from "@/providers/mdx-provider";
78
import { useSiteMetadata } from "@/shell/default-headers";
8-
import { useAppDrawerStore } from "@/stores/use-app-drawer-store";
9-
import { useThemeModeStore } from "@/stores/use-theme-mode-store";
109

1110
export type PostLayoutProps = PageProps<Queries.PostTemplateQuery>;
1211

1312
const PostLayout = ({ children, data }: PostLayoutProps) => {
14-
const siteMetadata = useSiteMetadata(),
15-
drawer = useAppDrawerStore(),
16-
theme = useThemeModeStore();
13+
const siteMetadata = useSiteMetadata();
14+
15+
const mainTemplateProps = useMainTemplateProps();
1716

1817
return (
1918
<AppMDXProvider>
@@ -23,18 +22,10 @@ const PostLayout = ({ children, data }: PostLayoutProps) => {
2322
</title>
2423
</MyHelmet>
2524
<PostTemplate
26-
appDrawerProps={{
27-
onClose: drawer.closeDrawer,
28-
open: drawer.open,
29-
themeMode: theme.themeMode,
30-
onThemeModeChange: (_, mode) => {
31-
theme.setThemeMode(mode);
32-
},
33-
}}
34-
appHeaderProps={{
35-
onOpenSettings: drawer.openDrawer,
36-
themeMode: theme.themeMode,
37-
onToggleThemeMode: theme.toggleThemeMode,
25+
{...mainTemplateProps}
26+
postHeaderProps={{
27+
title: data.mdx?.frontmatter?.title,
28+
date: data.mdx?.frontmatter?.date,
3829
}}
3930
>
4031
{children}
@@ -50,6 +41,7 @@ export const pageQuery = graphql`
5041
mdx(id: { eq: $id }) {
5142
frontmatter {
5243
title
44+
date
5345
}
5446
}
5547
}

eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export default tseslint.config(
4747
"@typescript-eslint/no-unused-vars": [
4848
"error",
4949
{
50-
varsIgnorePattern: "(^_|^React$)",
50+
argsIgnorePattern: "^_",
51+
varsIgnorePattern: "^React$",
5152
},
5253
],
5354
"react/no-unknown-property": ["error", { ignore: ["css"] }],

0 commit comments

Comments
 (0)