HS
Signed-off-by: Max Schmidt <max.schmidt@outlook.de>
This commit is contained in:
parent
acda6ea8c0
commit
d8c1f15c91
@ -9,7 +9,7 @@ const contentArray = getContentArray(content);
|
|||||||
{
|
{
|
||||||
contentArray.map((value) => {
|
contentArray.map((value) => {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
return <div set:html={value} />;
|
return <article set:html={value} />;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
---
|
---
|
||||||
import Layout from "../layouts/Layout.astro";
|
import Layout from "../layouts/Layout.astro";
|
||||||
import type { Post } from "../types";
|
import { getPosts } from "../utils/payload";
|
||||||
|
|
||||||
const posts: Post[] = (
|
const posts = await getPosts();
|
||||||
await (await fetch("http://payload:3001/api/posts")).json()
|
|
||||||
).docs;
|
|
||||||
posts.forEach((post) => console.log(post.title));
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Welcome to Astroad">
|
<Layout title="Welcome to Astroad">
|
||||||
|
@ -1,26 +1,31 @@
|
|||||||
---
|
---
|
||||||
import Layout from "../../layouts/Layout.astro";
|
import Layout from "../../layouts/Layout.astro";
|
||||||
import type { Post } from "../../types";
|
|
||||||
|
|
||||||
import RichText from "../../components/RichText.astro";
|
import RichText from "../../components/RichText.astro";
|
||||||
|
import type { Post } from "../../types";
|
||||||
|
import { getPost, getPosts } from "../../utils/payload";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const paths = (
|
const posts = await getPosts();
|
||||||
await (await fetch("http://payload:3001/api/posts")).json()
|
const paths = posts.map((post: Post) => ({
|
||||||
).docs.map((post: Post) => ({
|
|
||||||
params: { id: post.id },
|
params: { id: post.id },
|
||||||
}));
|
}));
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id } = Astro.params;
|
const { id } = Astro.params;
|
||||||
const post = (await (
|
const post = id && (await getPost(id));
|
||||||
await fetch(`http://payload:3001/api/posts/${id}`)
|
|
||||||
).json()) as Post;
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title={post.title!}>
|
{
|
||||||
<div class="max-w-3xl mx-auto space-y-3 my-3">
|
post ? (
|
||||||
<a href="/">BACK</a>
|
<Layout title={post.title!}>
|
||||||
<h1>{post.title}</h1>
|
<div class="max-w-3xl mx-auto space-y-3 my-3">
|
||||||
{post.content && <RichText content={post.content} />}
|
<a href="/">BACK</a>
|
||||||
</div>
|
<h1>{post.title}</h1>
|
||||||
</Layout>
|
{post.content && <RichText content={post.content} />}
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
) : (
|
||||||
|
<div>404</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { payloadSlateToDomConfig, slateToHtml } from "slate-serializers";
|
||||||
payloadSlateToDomConfig,
|
|
||||||
SlateToDomConfig,
|
|
||||||
slateToHtml,
|
|
||||||
} from "slate-serializers";
|
|
||||||
import { Element } from "domhandler";
|
import { Element } from "domhandler";
|
||||||
|
|
||||||
export const getContentArray = (content: any) => {
|
export const getContentArray = (content: any) => {
|
||||||
|
7
astro/src/utils/payload.ts
Normal file
7
astro/src/utils/payload.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import type { Post } from "../types";
|
||||||
|
|
||||||
|
export const getPosts = async () =>
|
||||||
|
(await (await fetch("http://payload:3001/api/posts")).json()).docs as Post[];
|
||||||
|
|
||||||
|
export const getPost = async (id: string) =>
|
||||||
|
(await (await fetch(`http://payload:3001/api/posts/${id}`)).json()) as Post;
|
@ -23,6 +23,8 @@ const Posts: CollectionConfig = {
|
|||||||
name: "content",
|
name: "content",
|
||||||
type: "richText",
|
type: "richText",
|
||||||
admin: {
|
admin: {
|
||||||
|
elements: ["h2", "h3", "h4", "link", "ol", "ul", "upload"],
|
||||||
|
leaves: ["bold", "italic", "underline"],
|
||||||
upload: {
|
upload: {
|
||||||
collections: {
|
collections: {
|
||||||
media: {
|
media: {
|
||||||
|
Loading…
Reference in New Issue
Block a user