-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(site): latest news in home page
- Loading branch information
Showing
13 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
import { defineCollection } from 'astro:content'; | ||
import { defineCollection, z } from 'astro:content'; | ||
import { docsSchema } from '@astrojs/starlight/schema'; | ||
|
||
const docs = defineCollection({ schema: docsSchema() }); | ||
|
||
const postSchema = z.object({ | ||
title: z.string(), | ||
description: z.string().optional(), | ||
url: z.string(), | ||
}).optional(); | ||
|
||
const posts = defineCollection({ | ||
type: 'data', | ||
schema: z.object({ | ||
date: z.coerce.date(), | ||
en: postSchema, | ||
zh: postSchema, | ||
}), | ||
}); | ||
|
||
export const collections = { | ||
docs: defineCollection({ schema: docsSchema() }), | ||
docs, | ||
posts, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
date: 2024-12-17 21:11:12 +0800 | ||
zh: | ||
title: 期待已久的开源 OpenBuild 官网前端代码库来啦! | ||
description: 加入 OpenBuild,共创 Web3 开源! | ||
url: https://openbuildxyz.github.io/eco/zh/posts/the-openbuild-official-website-frontend-codebase-is-open-now/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as LatestListView } from './views/latest-list'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { SupportedLocale, LocaleValue } from '@/types'; | ||
import { getCollection, unwrapLocalValue } from '@/utils'; | ||
|
||
import type { InternalPost, Post } from './typing'; | ||
|
||
const posts: InternalPost[] = await getCollection('posts'); | ||
|
||
function getList(locale: SupportedLocale): Post[] { | ||
return posts | ||
.map(({ date, ...others }) => { | ||
const unwrapped = unwrapLocalValue<Post>(others as LocaleValue<Post>, locale); | ||
|
||
return unwrapped ? { ...unwrapped, date } : undefined; | ||
}) | ||
.filter(post => !!post) | ||
.slice() | ||
.sort((a, b) => b.date.valueOf() - a.date.valueOf()); | ||
} | ||
|
||
export { getList }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { SupportedLocale, PickCollectionData } from '@/types'; | ||
|
||
type PostLocale = { | ||
browseMore: string; | ||
}; | ||
|
||
type InternalPost = PickCollectionData<'posts'>; | ||
|
||
type Post = Omit<InternalPost, SupportedLocale> & { | ||
title: string; | ||
description: string; | ||
url: string; | ||
}; | ||
|
||
export type { PostLocale, InternalPost, Post }; |
23 changes: 23 additions & 0 deletions
23
.knosys/sites/default/src/domain/post/views/latest-list/LatestList.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
import type { SupportedLocale } from '@/types'; | ||
import { getList } from '../../repository'; | ||
import PostCardWidget from '../../widgets/post-card'; | ||
const locale = Astro.currentLocale as SupportedLocale; | ||
const posts = getList(locale).slice(0, 3); | ||
--- | ||
|
||
{posts.length > 0 && ( | ||
<div class="grid gap-4 lg:gap-9 grid-cols-1 sm:grid-cols-3"> | ||
{posts.map(post => ( | ||
<PostCardWidget | ||
dataSource={post} | ||
headerClassName="p-6 pb-1.5" | ||
bodyClassName="p-6 pt-1.5" | ||
footerClassName="px-6" | ||
client:visible | ||
/> | ||
))} | ||
</div> | ||
)} |
1 change: 1 addition & 0 deletions
1
.knosys/sites/default/src/domain/post/views/latest-list/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './LatestList.astro'; |
33 changes: 33 additions & 0 deletions
33
.knosys/sites/default/src/domain/post/widgets/post-card/PostCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import clsx from 'clsx'; | ||
|
||
import { Card, CardHeader, CardBody, CardFooter } from '@/controls'; | ||
|
||
import type { Post } from '../../typing'; | ||
|
||
type PostCardWidgetProps = { | ||
dataSource: Post; | ||
className?: string; | ||
headerClassName?: string; | ||
bodyClassName?: string; | ||
footerClassName?: string; | ||
}; | ||
|
||
function PostCardWidget({ dataSource, className, headerClassName, bodyClassName, footerClassName }: PostCardWidgetProps) { | ||
return ( | ||
<Card className={className}> | ||
<CardHeader className={clsx('flex-col items-start leading-none', headerClassName)}> | ||
<span className="text-lg/tight font-semibold">{dataSource.title}</span> | ||
</CardHeader> | ||
<CardBody className={clsx('py-0 text-sm font-light break-all', bodyClassName)}>{dataSource.description || 'No description'}</CardBody> | ||
<CardFooter className={footerClassName}>{dataSource.date.toLocaleDateString()}</CardFooter> | ||
<a | ||
className="absolute inset-0 z-50" | ||
href={dataSource.url} | ||
target="_blank" | ||
rel="external nofollow" | ||
/> | ||
</Card> | ||
); | ||
} | ||
|
||
export default PostCardWidget; |
1 change: 1 addition & 0 deletions
1
.knosys/sites/default/src/domain/post/widgets/post-card/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './PostCard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { CollectionEntry } from 'astro:content'; | ||
|
||
type DataCollectionKey = 'posts'; | ||
|
||
type PickCollectionData<K extends DataCollectionKey> = CollectionEntry<K>['data']; | ||
|
||
export type { DataCollectionKey, PickCollectionData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './content'; | ||
export * from './locale'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters