Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support custom domain deployment #25

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/lib/auth";
import BlogList from "@/components/BlogList";
import { getBlogPosts } from "@/lib/githubApi";
import GitHubSignInButton from "@/components/GitHubSignInButton";
import { getBlogPosts, getBlogPostsPublic } from "@/lib/githubApi";
import { Octokit } from "@octokit/rest";
import PublicBlogList from "@/components/PublicBlogList";

export const revalidate = 60;

export default async function BlogPage() {
const session = await getServerSession(authOptions);

if (!session || !session.accessToken) {
return <GitHubSignInButton />;
const username = process.env.GITHUB_USERNAME ?? '';

if (username) {
const octokit = new Octokit();
const blogPosts = await getBlogPostsPublic(
octokit,
username,
"tinymind-blog"
);

return (
<div className="max-w-4xl mx-auto px-4 py-8">
<div className="max-w-2xl mx-auto">
<PublicBlogList posts={blogPosts} username={username} />
</div>
</div>
);
} else {
return (
<GitHubSignInButton />
);
}
}

try {
Expand Down
6 changes: 5 additions & 1 deletion app/editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default async function EditorPage({
const defaultType = searchParams.type === "blog" ? "blog" : "thought";

if (!session) {
return <GitHubSignInButton />;

const username = process.env.GITHUB_USERNAME;
if (!username) {
return <GitHubSignInButton />;
}
}

return (
Expand Down
4 changes: 3 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ThoughtsList from "@/components/ThoughtsList";

export default function Home() {
const username = process.env.GITHUB_USERNAME ?? ''

return (
<div className="flex flex-col min-h-screen">
<main className="flex-grow container mx-auto px-4 sm:px-6">
<ThoughtsList />
<ThoughtsList username={username} />
</main>
</div>
);
Expand Down
28 changes: 25 additions & 3 deletions app/thoughts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/lib/auth";
import ThoughtsList from "@/components/ThoughtsList";
import GitHubSignInButton from "@/components/GitHubSignInButton";
import ThoughtsList from "@/components/ThoughtsList";
import { getThoughtsPublic } from "@/lib/githubApi";
import { Octokit } from "@octokit/rest";
import PublicThoughtsList from "@/components/PublicThoughtsList";

export const revalidate = 60;

export default async function ThoughtsPage() {
const session = await getServerSession(authOptions);
const username = process.env.GITHUB_USERNAME ?? '';

if (!session || !session.accessToken) {
return <GitHubSignInButton />;
if (username) {
const octokit = new Octokit();
const blogPosts = await getThoughtsPublic(
octokit,
process.env.GITHUB_USERNAME ?? '',
"tinymind-blog"
);
return (
<div className="max-w-4xl mx-auto px-4 py-8">
<div className="max-w-2xl mx-auto">
<PublicThoughtsList thoughts={blogPosts} />
</div>
</div>
);
} else {
return (
<GitHubSignInButton />
);
}
}

return <ThoughtsList />;
return <ThoughtsList username={username} />;
}
27 changes: 14 additions & 13 deletions components/ThoughtsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useState, useEffect } from "react";
import { useSession } from "next-auth/react";
import { getThoughts, Thought } from "@/lib/githubApi";
import { getThoughts, getThoughtsPublic, Thought } from "@/lib/githubApi";
import { Octokit } from "@octokit/rest";
import GitHubSignInButton from "./GitHubSignInButton";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
Expand All @@ -16,7 +17,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
} from "@/components/ui/dropdown-menu"
import { AiOutlineEllipsis } from "react-icons/ai";
import { useToast } from "@/components/ui/use-toast";
import {
Expand All @@ -33,7 +34,7 @@ import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import { formatTimestamp } from "@/utils/dateFormatting";

export default function ThoughtsList() {
export default function ThoughtsList({ username }: { username: string }) {
const [thoughts, setThoughts] = useState<Thought[]>([]);
const [error, setError] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
Expand All @@ -48,18 +49,16 @@ export default function ThoughtsList() {
async function fetchThoughts() {
if (status === "loading") return;
if (status === "unauthenticated") {
setError("Please log in to view thoughts");
setIsLoading(false);
return;
}
if (!session?.accessToken) {
setError("Access token not available");
setIsLoading(false);
return;
}

try {
const fetchedThoughts = await getThoughts(session.accessToken);
const octokit = new Octokit();
const fetchedThoughts = session?.accessToken
? await getThoughts(session.accessToken)
: username
? await getThoughtsPublic(octokit, username, "tinymind-blog")
: [];
setThoughts(fetchedThoughts);
setError(null);
} catch (error) {
Expand All @@ -79,7 +78,7 @@ export default function ThoughtsList() {
}

fetchThoughts();
}, [session, status]);
}, [session, status, username]);

const handleDeleteThought = async (id: string) => {
if (!session?.accessToken) {
Expand Down Expand Up @@ -125,7 +124,9 @@ export default function ThoughtsList() {
};

if (status === "unauthenticated" || error === "authentication_failed") {
return <GitHubSignInButton />;
if (!username) {
return <GitHubSignInButton />;
}
}

if (error && error !== "authentication_failed") {
Expand Down