Skip to content

Commit

Permalink
Authors
Browse files Browse the repository at this point in the history
  • Loading branch information
UnsignedArduino committed Mar 16, 2024
1 parent f0498cc commit 9abd337
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 20 deletions.
5 changes: 4 additions & 1 deletion content/authors/UnsignedArduino.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
name: UnsignedArduino
link: "https://github.com/UnsignedArduino"
bio: "Hi there \U0001F44B\n\nI'm the creator of Awesome Arcade - thanks for visiting my site!\n"
avatarURL: "https://avatars.githubusercontent.com/u/38868705?s=400&v=4"
---

Hi there 👋

I'm the creator of Awesome Arcade - thanks for visiting my site!
33 changes: 33 additions & 0 deletions src/components/Blog/Author/Author.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";
import { AuthorsQuery } from "../../../../tina/__generated__/types";
import {
AvatarImageRenderer,
RichTextSectionRenderer,
} from "@/components/Blog/Elements";

export default function BlogAuthor({
data,
}: {
data: AuthorsQuery;
}): React.ReactNode {
return (
<>
<h1>
<AvatarImageRenderer
url={data.authors.avatarURL as string}
name={data.authors.name}
/>{" "}
{data.authors.name}
</h1>
{data.authors.link ? (
<p>
Visit on{" "}
<a href={data.authors.link} target="_blank" rel="noopener noreferrer">
{new URL(data.authors.link).hostname}
</a>
</p>
) : null}
<RichTextSectionRenderer content={data.authors.bio} />
</>
);
}
42 changes: 42 additions & 0 deletions src/components/Blog/Author/Preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import Link from "next/link";
import { AvatarImageRenderer } from "@/components/Blog/Elements";

export type BlogAuthorPreview = {
name: string;
link: string;
avatarURL: string | null | undefined;
};

export default function BlogAuthorPreviewRenderer({
preview,
}: {
preview: BlogAuthorPreview;
}): React.ReactNode {
return (
<>
<div className="card mb-2">
<div className="card-body">
<h5 className="card-title">
<AvatarImageRenderer
url={preview.avatarURL as string}
name={preview.name}
/>{" "}
{preview.name}
</h5>
{preview.link ? (
<h6 className="card-subtitle mb-2 text-body-secondary">
Visit on{" "}
<a href={preview.link} target="_blank" rel="noopener noreferrer">
{new URL(preview.link).hostname}
</a>
</h6>
) : null}
<Link href={`/blog/authors/${preview.name}`} className="card-link">
View profile
</Link>
</div>
</div>
</>
);
}
40 changes: 31 additions & 9 deletions src/components/Blog/Elements.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TinaMarkdown } from "tinacms/dist/rich-text";
import React from "react";
import { Authors } from "../../../tina/__generated__/types";
import Link from "next/link";

const PageSection = (props: any) => {
return (
Expand All @@ -19,25 +20,46 @@ export function RichTextSectionRenderer({ content }: { content: any }) {
return <TinaMarkdown components={components} content={content} />;
}

export function AuthorRenderer({
author,
export function AvatarImageRenderer({
url,
name,
}: {
author: Authors;
url: string;
name: string;
}): React.ReactNode {
return (
<>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={author.avatarURL as string | undefined}
alt={`Profile picture of ${author.name}`}
src={url}
alt={`Profile picture of ${name}`}
style={{
width: "1em",
height: "1em",
width: "0.9em",
height: "0.9em",
objectFit: "contain",
borderRadius: "50%",
verticalAlign: "middle",
marginBottom: "0.15em",
}}
/>{" "}
{author.name}
/>
</>
);
}

export function ShortAuthorRenderer({
author,
}: {
author: Authors;
}): React.ReactNode {
return (
<>
<Link href={`/blog/authors/${author.name}`}>
<AvatarImageRenderer
url={author.avatarURL as string}
name={author.name}
/>{" "}
{author.name}
</Link>
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { formatDateAndTime } from "@/scripts/Utils/DateAndTime/Format";
import { Authors, PostQuery } from "../../../tina/__generated__/types";
import { Authors, PostQuery } from "../../../../tina/__generated__/types";
import {
AuthorRenderer,
RichTextSectionRenderer,
ShortAuthorRenderer,
} from "@/components/Blog/Elements";

export default function BlogPost({
Expand All @@ -15,7 +15,7 @@ export default function BlogPost({
<>
<h1>{data.post.title}</h1>
<p>
<AuthorRenderer author={data.post.author as Authors} />
Written by <ShortAuthorRenderer author={data.post.author as Authors} />
<br />
{data.post.datePosted != null ? (
<>Posted on {formatDateAndTime(new Date(data.post.datePosted))}.</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Authors } from "../../../tina/__generated__/types";
import { Authors } from "../../../../tina/__generated__/types";
import React from "react";
import {
AuthorRenderer,
RichTextSectionRenderer,
ShortAuthorRenderer,
} from "@/components/Blog/Elements";
import { formatDateAndTime } from "@/scripts/Utils/DateAndTime/Format";
import Link from "next/link";
Expand All @@ -28,11 +28,11 @@ export default function BlogPostPreviewRenderer({
<h6 className="card-subtitle mb-2 text-body-secondary">
{preview.postedDate !== null ? (
<>
Posted by <AuthorRenderer author={preview.author} /> on{" "}
Posted by <ShortAuthorRenderer author={preview.author} /> on{" "}
{formatDateAndTime(new Date(preview.postedDate))}.
</>
) : (
<AuthorRenderer author={preview.author} />
<ShortAuthorRenderer author={preview.author} />
)}
</h6>
<div className="card-text">
Expand Down
4 changes: 4 additions & 0 deletions src/components/Footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function Footer({ appProps }: { appProps: AppProps }): JSX.Element {
title: "Tools",
link: "/tools",
},
{
title: "Blog",
link: "/blog",
},
{
title: "Help",
link: "/help",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Layout from "@/components/Layout";
import { PostQuery } from "../../../tina/__generated__/types";
import React from "react";
import { createBreadCrumbSegment } from "@/components/Layout/layout";
import BlogPost from "@/components/Blog/Post";
import BlogPost from "@/components/Blog/Post/Post";

type BlogProps = {
variables: { relativePath: string };
Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Authors } from "../../../tina/__generated__/types";
import React from "react";
import BlogPostPreviewRenderer, {
BlogPostPreview,
} from "@/components/Blog/Preview";
} from "@/components/Blog/Post/Preview";
import { createBreadCrumbSegment } from "@/components/Layout/layout";

type BlogProps = {
Expand Down
88 changes: 88 additions & 0 deletions src/pages/blog/authors/[author].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { useTina } from "tinacms/dist/react";
import client from "../../../../tina/__generated__/client";
import getAppProps, { AppProps } from "@/components/WithAppProps";
import { GetStaticPathsResult } from "next";
import Layout from "@/components/Layout";
import { AuthorsQuery } from "../../../../tina/__generated__/types";
import React from "react";
import { createBreadCrumbSegment } from "@/components/Layout/layout";
import BlogAuthor from "@/components/Blog/Author/Author";

type BlogAuthorProps = {
variables: { relativePath: string };
filename: string;
data: AuthorsQuery;
query: string;
appProps: AppProps;
};

type BlogAuthorParams = { author: string };

export default function BlogAuthorPage(props: BlogAuthorProps) {
const { data } = useTina({
query: props.query,
variables: props.variables,
data: props.data,
});

const pageName = `${data.authors.name} | Blog`;

return (
<Layout
title={pageName}
currentPage={pageName}
appProps={props.appProps}
description={`${data.authors.name} on Awesome Arcade's blog!`}
keywords={`Game development, Awesome, Modules, Libraries, Extensions, Tools, Curated, Arcade, Useful, Curated list, MakeCode, Awesome extensions, Useful extensions, MakeCode Arcade, MakeCode Arcade Extensions, Arcade Extensions, Awesome tools, Useful tools, MakeCode Arcade, MakeCode Arcade tools, Arcade tools, Blog, Awesome Arcade blog, Blog post, Awesome Arcade blog post, ${data.authors.name}, ${data.authors.name} blog posts`}
breadCrumbs={[
createBreadCrumbSegment("Blog", "/blog"),
createBreadCrumbSegment("Authors", "/blog/authors"),
createBreadCrumbSegment(
data.authors.name,
`/blog/authors/${props.filename}`,
),
]}
>
{/*<code>{JSON.stringify(data, null, 2)}</code>*/}
<BlogAuthor data={data} />
</Layout>
);
}

export async function getStaticProps({
params,
}: {
params: BlogAuthorParams;
}): Promise<{
props: BlogAuthorProps;
}> {
let variables = { relativePath: `${params.author}.md` };

const res = await client.queries.authors(variables);
const query = res.query;
const data = res.data;
variables = res.variables;

return {
props: {
variables,
filename: params.author,
data,
query,
appProps: await getAppProps(),
},
};
}

export async function getStaticPaths(): Promise<
GetStaticPathsResult<BlogAuthorParams>
> {
const postsListData = await client.queries.authorsConnection();

return {
paths: postsListData.data.authorsConnection.edges!.map((author) => ({
params: { author: author!.node!._sys.filename },
})),
fallback: false,
};
}
71 changes: 71 additions & 0 deletions src/pages/blog/authors/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import client from "../../../../tina/__generated__/client";
import getAppProps, { AppProps } from "@/components/WithAppProps";
import Layout from "@/components/Layout";
import { Authors } from "../../../../tina/__generated__/types";
import React from "react";
import { createBreadCrumbSegment } from "@/components/Layout/layout";
import BlogAuthorPreviewRenderer, {
BlogAuthorPreview,
} from "@/components/Blog/Author/Preview";

type BlogAuthorProps = {
blogAuthorPreviews: BlogAuthorPreview[];
appProps: AppProps;
};

const pageName = `All authors | Blog`;

export default function AllBlogAuthors(props: BlogAuthorProps) {
return (
<Layout
title={pageName}
currentPage={pageName}
appProps={props.appProps}
description="All of Awesome Arcade's blog authors!"
keywords="Game development, Awesome, Modules, Libraries, Extensions, Tools, Curated, Arcade, Useful, Curated list, MakeCode, Awesome extensions, Useful extensions, MakeCode Arcade, MakeCode Arcade Extensions, Arcade Extensions, Awesome tools, Useful tools, MakeCode Arcade, MakeCode Arcade tools, Arcade tools, Blog, Awesome Arcade blog, Blog authors, Awesome Arcade blog authors, All blog authors, All Awesome Arcade blog authors"
breadCrumbs={[
createBreadCrumbSegment("Blog", "/blog"),
createBreadCrumbSegment("Authors", "/blog/authors"),
]}
>
<h1>All blog authors</h1>
<p>Here is a list of all blog authors on Awesome Arcade.</p>
{
<>
{props.blogAuthorPreviews.map((preview) => {
return (
<BlogAuthorPreviewRenderer preview={preview} key={preview.name} />
);
})}
</>
}
</Layout>
);
}

export async function getStaticProps(): Promise<{
props: BlogAuthorProps;
}> {
const authorsListData = await client.queries.authorsConnection();

const previews: BlogAuthorPreview[] = [];

for (const edge of authorsListData.data.authorsConnection.edges ?? []) {
if (!edge || !edge.node) {
continue;
}
const author = edge.node;
previews.push({
name: author.name,
link: author.link,
avatarURL: author.avatarURL,
});
}

return {
props: {
blogAuthorPreviews: previews,
appProps: await getAppProps(),
},
};
}
2 changes: 1 addition & 1 deletion src/pages/blog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Authors } from "../../../tina/__generated__/types";
import React from "react";
import BlogPostPreviewRenderer, {
BlogPostPreview,
} from "@/components/Blog/Preview";
} from "@/components/Blog/Post/Preview";
import Link from "next/link";

type BlogProps = {
Expand Down
Loading

0 comments on commit 9abd337

Please sign in to comment.