-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: ニュース一覧・詳細ページを追加
- Loading branch information
Showing
18 changed files
with
218 additions
and
14 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
BACKEND_URL=https://graphql-engine.asis-be.orb.local/v1/graphql |
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
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
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,9 +1,11 @@ | ||
import { defineConfig } from 'astro/config' | ||
|
||
import cloudflare from '@astrojs/cloudflare' | ||
import sitemap from '@astrojs/sitemap' | ||
import { defineConfig } from 'astro/config' | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
site: 'https://asis.quest', | ||
integrations: [sitemap()] | ||
integrations: [sitemap()], | ||
output: 'server', | ||
adapter: cloudflare() | ||
}) |
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
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 Show from './Show.astro'; | ||
interface Props<T> { | ||
each: Iterable<T>; | ||
} | ||
const { each } = Astro.props; | ||
--- | ||
|
||
{ | ||
(async function* () { | ||
for await (const value of each) { | ||
let html = await Astro.slots.render('default', [value]); | ||
yield <Fragment set:html={html} />; | ||
yield '\n'; | ||
} | ||
})() | ||
} | ||
|
||
<Show when={!each.length}> | ||
<slot name="fallback" /> | ||
</Show> |
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,9 @@ | ||
--- | ||
interface Props<T> { | ||
when: T | number | boolean | undefined | null; | ||
} | ||
const { when } = Astro.props; | ||
--- | ||
|
||
{!!when ? <slot /> : <slot name="fallback" />} |
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,88 @@ | ||
import type { News } from '@/types.ts' | ||
|
||
/** | ||
* Fetches the GraphQL API | ||
* @param operationsDoc | ||
* @param operationName | ||
* @param variables | ||
*/ | ||
async function fetchGraphQL( | ||
operationsDoc: string, | ||
operationName: string, | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
variables: Record<string, any> | ||
) { | ||
const result = await fetch(`${import.meta.env.BACKEND_URL}`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query: operationsDoc, | ||
variables, | ||
operationName | ||
}) | ||
}) | ||
return await result.json() | ||
} | ||
|
||
/** | ||
* Fetches the list of news | ||
*/ | ||
export async function fetchNewsList(): Promise<News[]> { | ||
const { errors, data } = await fetchGraphQL( | ||
` | ||
query GetNewsList { | ||
news { | ||
title | ||
slug | ||
publishedAt | ||
excerpt | ||
coverImageUrl | ||
content | ||
} | ||
} | ||
`, | ||
'GetNewsList', | ||
{} | ||
) | ||
|
||
if (errors) { | ||
// handle those errors like a pro | ||
console.error(errors) | ||
} | ||
|
||
console.log(data) | ||
return data.news as News[] | ||
} | ||
|
||
/** | ||
* Fetches the list of news | ||
*/ | ||
export async function fetchNewsBySlug(slug: string): Promise<News> { | ||
const { errors, data } = await fetchGraphQL( | ||
` | ||
query GetNewsBySlug($slug: String) { | ||
news(where: {slug: {_eq: $slug}}) { | ||
title | ||
slug | ||
publishedAt | ||
excerpt | ||
coverImageUrl | ||
content | ||
} | ||
} | ||
`, | ||
'GetNewsBySlug', | ||
{ | ||
slug | ||
} | ||
) | ||
|
||
if (errors) { | ||
// handle those errors like a pro | ||
console.error(errors) | ||
} | ||
|
||
console.log(data) | ||
// biome-ignore lint/style/noNonNullAssertion: <explanation> | ||
return (data.news as News[])[0]! | ||
} |
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
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,16 @@ | ||
--- | ||
import BaseLayout from '@/layouts/BaseLayout.astro' | ||
import { fetchNewsBySlug } from '../../lib/api' | ||
const { slug } = Astro.params as { slug: string } | ||
const news = await fetchNewsBySlug(slug) | ||
--- | ||
|
||
<BaseLayout> | ||
<div class="stack gap-20 lg:gap-48"> | ||
<h2>{news.title}</h2> | ||
<p>{news.publishedAt}</p> | ||
<div set:html={news.content} /> | ||
</div> | ||
</BaseLayout> |
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,22 @@ | ||
--- | ||
import For from '@/components/For.astro' | ||
import BaseLayout from '@/layouts/BaseLayout.astro' | ||
import { fetchNewsList } from '@/lib/api' | ||
import type { News } from '@/types' | ||
const newsList = await fetchNewsList() | ||
--- | ||
|
||
<BaseLayout> | ||
<ul class="stack gap-20 lg:gap-48"> | ||
<For each={newsList}>{(news: News) => ( | ||
<li> | ||
<a href=`news/${news.slug}`> | ||
<h2>{news.title}</h2> | ||
<p>{news.publishedAt}</p> | ||
<p>{news.excerpt}</p> | ||
</a> | ||
</li> | ||
)}</For> | ||
</ul> | ||
</BaseLayout> |
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,8 @@ | ||
export interface News { | ||
title: string | ||
slug: string | ||
publishedAt: number | ||
excerpt: string | ||
coverImageUrl: string | ||
content: string | ||
} |
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 @@ | ||
BACKEND_URL={{backendUrl}} |