Skip to content

Commit 1b8849b

Browse files
committed
refactor: migrate content
1 parent 296fcb6 commit 1b8849b

47 files changed

Lines changed: 196 additions & 183 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Thumbs.db
2525
build/
2626

2727
.env
28+
.astro/

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232
"[typescriptreact]": {
3333
"editor.defaultFormatter": "esbenp.prettier-vscode"
3434
},
35-
"terminal.integrated.defaultProfile.linux": "zsh"
35+
"terminal.integrated.defaultProfile.linux": "zsh",
36+
"[xml]": {
37+
"editor.defaultFormatter": "redhat.vscode-xml"
38+
}
3639
}

src/components/Content.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import type { MarkdownHeading } from 'astro';
2+
import type { CollectionEntry } from 'astro:content';
23
import path from 'path';
34
import type { ReactNode } from 'react';
45

56
import { EditGitHub } from '@/components/EditGitHub';
67
import { Toc } from '@/components/Toc';
7-
import type { IArticleFrontmatter } from '@/types/IArticleFrontmatter';
88
import { AppConfig } from '@/utils/AppConfig';
99

1010
type IContentProps = {
11-
content: IArticleFrontmatter;
11+
content: CollectionEntry<'posts'>;
1212
headings: MarkdownHeading[];
1313
children: ReactNode;
1414
};
1515

1616
const Content: React.FC<IContentProps> = (props: IContentProps) => {
1717
return (
1818
<div className="mx-auto mt-5 max-w-prose">
19-
{props.content.imgSrc && (
19+
{props.content.data.imgSrc && (
2020
<div className="aspect-w-3 aspect-h-2">
2121
<img
2222
className="h-full w-full rounded-lg object-cover object-center"
23-
src={path.join(AppConfig.base, props.content.imgSrc)}
24-
alt={props.content.imgAlt}
23+
src={path.join(AppConfig.base, props.content.data.imgSrc)}
24+
alt={props.content.data.imgAlt}
2525
loading="lazy"
2626
/>
2727
</div>

src/components/ContentHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import type { CollectionEntry } from 'astro:content';
12
import { format } from 'date-fns';
23

3-
import type { IArticleFrontmatter } from '@/types/IArticleFrontmatter';
44
import type { Tags } from '@/utils/Tag';
55

66
import { Tag } from './Tag';
77

88
type IContentHeaderProps = {
9-
content: IArticleFrontmatter;
9+
content: CollectionEntry<'posts'>;
1010
author: string;
1111
tags: Tags;
1212
contentCategory: string;
@@ -15,12 +15,12 @@ type IContentHeaderProps = {
1515
export const ContentHeader = (props: IContentHeaderProps) => (
1616
<>
1717
<h1 id="contents_header" className="text-center text-3xl font-bold">
18-
{props.content.title.replace('\\n', '')}
18+
{props.content.data.title.replace('\\n', '')}
1919
</h1>
2020

2121
<div className="mt-2 text-center text-sm text-gray-400">
2222
By {props.author} on{' '}
23-
{format(new Date(props.content.pubDate), 'LLL d, yyyy')}
23+
{format(new Date(props.content.data.pubDate), 'LLL d, yyyy')}
2424
</div>
2525

2626
<div className="mt-4 flex flex-wrap justify-center gap-2">

src/components/EditGitHub.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import type { CollectionEntry } from 'astro:content';
12
import path from 'path';
23
import { BsGithub } from 'react-icons/bs/index';
34

4-
import type { IArticleFrontmatter } from '@/types/IArticleFrontmatter';
55
import { AppConfig } from '@/utils/AppConfig';
66

77
type IEditGitHubProps = {
8-
content: IArticleFrontmatter;
8+
content: CollectionEntry<'posts'>;
99
};
1010

1111
export const EditGitHub = (props: IEditGitHubProps) => {
12-
if (props.content.url === undefined) {
12+
if (props.content.id === undefined) {
1313
return <></>;
1414
}
1515

@@ -19,14 +19,14 @@ export const EditGitHub = (props: IEditGitHubProps) => {
1919
'main',
2020
'src',
2121
'pages',
22-
props.content.url
22+
props.content.id
2323
);
2424

2525
return (
2626
<div className="flex justify-end">
2727
<a
2828
style={{ height: 'fit-content' }}
29-
href={`https://${url}.md`}
29+
href={`https://${url}`}
3030
target="_blank"
3131
rel="noopener noreferrer"
3232
>

src/components/PostCard.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
import { format } from 'date-fns';
22
import path from 'path';
33

4-
import type { IContent } from '@/types/IArticleFrontmatter';
4+
import type { IPost } from '@/types/IArticleFrontmatter';
55
import { AppConfig } from '@/utils/AppConfig';
66
import { transformTitleForContentCard } from '@/utils/StringWidth';
77
import type { Tags } from '@/utils/Tag';
88

99
import { Tag } from './Tag';
1010

1111
type IPostCardProps = {
12-
instance: IContent;
12+
instance: IPost;
1313
contentCategory: string;
1414
tags: Tags;
1515
};
1616

1717
export const PostCard = (props: IPostCardProps) => {
18-
const contentPath = props.instance.url;
18+
const contentPath = path.join(
19+
'/',
20+
props.instance.collection,
21+
props.instance.slug
22+
);
1923

2024
return (
2125
<div className="relative overflow-hidden rounded-md bg-slate-800">
2226
<div className="aspect-w-16 aspect-h-9">
23-
{props.instance.frontmatter.imgSrc && (
27+
{props.instance.data.imgSrc && (
2428
<img
2529
className="h-full w-full object-cover object-center"
26-
src={path.join(AppConfig.base, props.instance.frontmatter.imgSrc)}
27-
alt={props.instance.frontmatter.imgSrc}
30+
src={path.join(AppConfig.base, props.instance.data.imgSrc)}
31+
alt={props.instance.data.imgSrc}
2832
loading="lazy"
2933
/>
3034
)}
@@ -35,7 +39,7 @@ export const PostCard = (props: IPostCardProps) => {
3539
<div className="py-1.5 px-3">
3640
<a href={contentPath}>
3741
<div>
38-
{transformTitleForContentCard(props.instance.frontmatter.title)
42+
{transformTitleForContentCard(props.instance.data.title)
3943
.split('\\n')
4044
.map((t) => (
4145
<span key={t} className="text-lg font-bold">
@@ -44,16 +48,13 @@ export const PostCard = (props: IPostCardProps) => {
4448
</span>
4549
))}
4650
<span className="align-middle text-xs text-gray-300 ">
47-
{format(
48-
new Date(props.instance.frontmatter.pubDate),
49-
'LLL d, yyyy'
50-
)}
51+
{format(new Date(props.instance.data.pubDate), 'LLL d, yyyy')}
5152
</span>
5253
</div>
5354
</a>
5455
<div className="mt-1 flex flex-wrap gap-2">
55-
{props.instance.frontmatter.tags &&
56-
props.instance.frontmatter.tags.map((tagName) => (
56+
{props.instance.data.tags &&
57+
props.instance.data.tags.map((tagName) => (
5758
<Tag
5859
key={tagName}
5960
name={tagName}

src/components/PostGallery.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import type { IContent } from '@/types/IArticleFrontmatter';
1+
import type { IPost } from '@/types/IArticleFrontmatter';
22
import type { Tags } from '@/utils/Tag';
33

44
import { PostCard } from './PostCard';
55

66
type IRecentPostsProps = {
77
tags: Tags;
88
contentCategory: string;
9-
postList: IContent[];
9+
postList: IPost[];
1010
};
1111

1212
export const PostGallery = (props: IRecentPostsProps) => {
1313
return (
1414
<div className="grid grid-cols-1 gap-6 md:grid-cols-3">
1515
{props.postList.map((elt) => (
1616
<PostCard
17-
key={elt.url}
17+
key={elt.id}
1818
instance={elt}
1919
tags={props.tags}
2020
contentCategory={props.contentCategory}

src/content/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineCollection, z } from 'astro:content';
2+
3+
const postCollection = defineCollection({
4+
schema: z.object({
5+
title: z.string(),
6+
description: z.string().nullable().optional(),
7+
pubDate: z.date(),
8+
tags: z.array(z.string()),
9+
order: z.number().optional(),
10+
imgSrc: z.string().optional(),
11+
imgAlt: z.string().optional(),
12+
draft: z.boolean().optional(),
13+
}),
14+
});
15+
16+
export const collections = {
17+
posts: postCollection,
18+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: '@/templates/BasePost.astro'
2+
33
title: ETロボコン2017 に参加しました
44
description: ロボコンの話
55
pubDate: 2017-09-30T00:00:00Z
@@ -8,7 +8,7 @@ tags:
88
- 大学
99
---
1010

11-
片山徹郎研究室のメンバーで参加しました。九州南地区大会で敗北。
11+
片山徹郎研究室のメンバーで参加しました。九州南地区大会で敗北。aaa
1212

1313
- [ETロボコン2017大会 | ETロボコン](https://www.etrobo.jp/2017archive)
1414
- [korosuke613/etrobocon2017: ETロボコン2017](https://github.com/korosuke613/etrobocon2017)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: '@/templates/BasePost.astro'
2+
33
title: 専門教育入門セミナーT 2017\nin 片山(徹)研
44
description: 授業の話
55
pubDate: 2017-10-01T00:00:00Z

0 commit comments

Comments
 (0)