Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ BETTER_AUTH_URL=http://localhost:3000
# Local email previews do not need these values.
RESEND_API_KEY=
RESEND_FROM_EMAIL=

# reccomended as 5000 reqs can be sent per hour
GITHUB_TOKEN=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pnpm install
pnpm dev
```

Open http://localhost:3000. No environment variables or separate service are required for the existing site.
Open http://localhost:3000. No environment variables or separate service are required for the existing site; an optional `GITHUB_TOKEN` raises the GitHub API limit for the home page statistics.

Development and production builds use Turbopack.

Expand Down
6 changes: 6 additions & 0 deletions WEBSITE_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All source, public assets, and configuration are at the repository root. Run `pnpm dev` from this directory. No environment variables are needed for the existing site. Future server features can read private values from `.env.local`; never prefix secrets with `NEXT_PUBLIC_`.

## Home page

The home page is a bento grid (`app/page.tsx`, laid out by the `.bento` rules in `styles/globals.css`). Its statistics, language breakdown, and commit calendar come from the public GitHub API for the [Manipal-OSF](https://github.com/Manipal-OSF) organization (`lib/github.ts`). Responses are cached for a day and the page re-renders hourly; if GitHub is unreachable, those cells say so instead of failing the page. Unauthenticated requests are limited to 60 an hour, so set `GITHUB_TOKEN` in `.env.local` or the hosting environment if builds or previews run often. A fine-grained token without any permissions is enough.

The map uses [MapLibre](https://maplibre.org/) with [OpenFreeMap](https://openfreemap.org/) tiles; edit `regions` in `components/home/KarnatakaMap.tsx` to change the places in its menu.

## Write a blog post

Create `content/posts/your-post.md`:
Expand Down
11 changes: 4 additions & 7 deletions app/blog/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import CoverImage from '@/components/blog/CoverImage';
import MarkdownRenderer from '@/components/blog/MarkdownRenderer';
import PostHeader from '@/components/blog/PostHeader';
import PostNavigation from '@/components/blog/PostNavigation';
import {
TableOfContentsDropdown,
TableOfContentsSidebar,
} from '@/components/blog/TableOfContents';
import MobileTableOfContents from '@/components/blog/MobileTableOfContents';
import { TableOfContentsSidebar } from '@/components/blog/TableOfContents';
import Breadcrumbs from '@/components/common/Breadcrumbs';
import Container from '@/components/common/Container';
import { resolveAuthors } from '@/lib/content/authors';
Expand Down Expand Up @@ -79,16 +77,15 @@ export default async function PostPage({ params }: PostPageProps) {
preload
className='mx-auto aspect-[1200/630] w-full max-w-5xl rounded-xl'
/>
<Container className='flex flex-col gap-6'>
<Container>
<PostHeader post={post} authors={authors} />
<PostNavigation newer={newer} older={older} />
</Container>
<div className='grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_48rem_minmax(0,1fr)]'>
<aside className='hidden xl:block'>
<TableOfContentsSidebar headings={post.headings} className='pr-8' />
</aside>
<Container className='flex flex-col gap-6'>
<TableOfContentsDropdown
<MobileTableOfContents
headings={post.headings}
className='xl:hidden'
/>
Expand Down
12 changes: 1 addition & 11 deletions app/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Metadata } from 'next';
import PostList from '@/components/blog/PostList';
import Breadcrumbs from '@/components/common/Breadcrumbs';
import Container from '@/components/common/Container';
import Link from '@/components/common/TransitionLink';
import { getPublishedPosts } from '@/lib/content/posts';

export const metadata: Metadata = { title: 'Blog' };
Expand All @@ -16,16 +15,7 @@ export default async function BlogPage() {

return (
<Container className='flex flex-col gap-8'>
<div className='flex flex-wrap items-center justify-between gap-4'>
<Breadcrumbs items={[{ label: 'Blog' }]} />
<Link
href='/authors'
scroll={false}
className='text-muted-foreground hover:text-foreground text-sm'
>
Authors
</Link>
</div>
<Breadcrumbs items={[{ label: 'Blog' }]} />
{posts.length === 0 ? (
<p className='text-muted-foreground text-sm'>No posts yet.</p>
) : (
Expand Down
198 changes: 191 additions & 7 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,196 @@
import { siteName } from '@/lib/site';
import { BookMarked, GitFork, Star, Users, UsersRound } from 'lucide-react';
import type { ReactNode } from 'react';
import BrandIcon from '@/components/common/BrandIcon';
import Link from '@/components/common/TransitionLink';
import CoverImage from '@/components/blog/CoverImage';
import ActivityCard from '@/components/home/ActivityCard';
import BentoCell from '@/components/home/BentoCell';
import KarnatakaMap from '@/components/home/KarnatakaMap';
import LanguagesCard from '@/components/home/LanguagesCard';
import LinkCell from '@/components/home/LinkCell';
import Logo from '@/components/layout/Logo';
import { getPublishedPosts } from '@/lib/content/posts';
import { formatDate } from '@/lib/format';
import { getOrgStats, githubOrg } from '@/lib/github';
import { siteName, socialLinks } from '@/lib/site';

// Re-render hourly; GitHub responses themselves are cached for a day.
export const revalidate = 3600;

const href = (label: (typeof socialLinks)[number]['label']) =>
socialLinks.find((link) => link.label === label)!.href;

const Stat = ({
icon,
value,
label,
}: {
icon: ReactNode;
value: number;
label: string;
}) => (
<div className='flex flex-col'>
<dt className='text-muted-foreground order-last flex items-center gap-1 text-xs [&>svg]:hidden [&>svg]:size-3 [&>svg]:shrink-0 @[9rem]:[&>svg]:block'>
{icon}
{label}
</dt>
<dd className='text-2xl font-semibold tabular-nums sm:text-3xl'>{value}</dd>
</div>
);

const Unavailable = ({ children }: { children: ReactNode }) => (
<p className='text-muted-foreground grid h-full place-items-center p-4 text-center text-sm'>
{children}
</p>
);

export default async function HomePage() {
const [stats, posts] = await Promise.all([
getOrgStats(),
getPublishedPosts(),
]);
const latest = posts[0];

export default function HomePage() {
return (
<div className='text-foreground m-auto grid gap-5 place-self-center text-center'>
<h2 className='text-left italic duration-300 hover:-translate-y-1'>
Experience
</h2>
<h1 className='text-5xl sm:text-7xl'>{siteName}</h1>
<div className='bento py-2'>
<BentoCell
area='about'
className='flex flex-col justify-center gap-3 p-5'
>
<h1 className='text-2xl font-semibold sm:text-3xl'>
Hello, We are <span className='text-primary'>{siteName}</span>
</h1>
<p className='text-muted-foreground text-sm text-pretty sm:text-base'>
An open-source initiative led by the students of MIT for democratizing
free software &amp; material
</p>
</BentoCell>

<BentoCell
area='logo'
className='text-primary grid place-items-center'
note={
stats ? `Established & Active since ${stats.since}` : 'Hello there!'
}
noteClassName='bottom-3 left-3'
>
<Logo className='size-2/3 max-w-40 transition-transform duration-500 group-hover:-rotate-6 motion-reduce:transition-none' />
</BentoCell>

<BentoCell area='stats' className='p-3 sm:p-4'>
{stats ? (
<div className='@container flex h-full flex-col justify-between gap-2'>
<h2 className='text-muted-foreground text-sm sm:text-base'>
All time stats
</h2>
<dl className='grid grid-cols-2 gap-x-2 gap-y-2 sm:gap-x-3'>
<Stat icon={<BookMarked />} value={stats.repos} label='repos' />
<Stat icon={<Star />} value={stats.stars} label='stars' />
<Stat icon={<GitFork />} value={stats.forks} label='forks' />
<Stat
icon={<Users />}
value={stats.followers}
label='followers'
/>
</dl>
</div>
) : (
<Unavailable>
GitHub statistics are unavailable right now.
</Unavailable>
)}
</BentoCell>

<BentoCell area='post'>
<Link
href={latest ? `/blog/${latest.id}` : '/blog'}
className='flex h-full flex-col'
>
<CoverImage
src={latest?.coverImage ?? null}
alt=''
sizes='(min-width: 64rem) 32rem, 100vw'
className='absolute inset-0 aspect-auto transition-transform duration-500 group-hover:scale-105 motion-reduce:transition-none'
/>
<div className='from-card via-card/90 relative mt-auto flex flex-col gap-1 bg-gradient-to-t to-transparent p-4 pt-12'>
<span className='text-primary text-xs font-medium'>
Latest post
</span>
<h2 className='line-clamp-2 text-lg font-medium'>
{latest?.title ?? 'Read our blog'}
</h2>
{latest && (
<p className='text-muted-foreground text-xs'>
{formatDate(latest.publishDate)} · {latest.readingTime}
</p>
)}
</div>
</Link>
</BentoCell>

<BentoCell
area='map'
note='We accept members from both campuses!'
noteClassName='top-3 left-3'
>
<KarnatakaMap />
</BentoCell>

<BentoCell area='langs'>
{stats?.languages.length ? (
<LanguagesCard languages={stats.languages} />
) : (
<Unavailable>
Language statistics are unavailable right now.
</Unavailable>
)}
</BentoCell>

<BentoCell area='activity'>
{stats ? (
<ActivityCard
activity={stats.activity}
totalCommits={stats.totalCommits}
/>
) : (
<Unavailable>Commit activity is unavailable right now.</Unavailable>
)}
</BentoCell>

<LinkCell
area='github'
href={href('GitHub')}
image='/github.webp'
icon={<BrandIcon brand='GitHub' />}
title='GitHub'
detail={`@${githubOrg}`}
note='Star a repo!'
/>
<LinkCell
area='discord'
href={href('Discord')}
image='/discord.png'
icon={<BrandIcon brand='Discord' />}
title='Discord'
detail='Join the server'
note='Come say hi!'
/>
<LinkCell
area='teams'
href={href('MS Teams')}
image='/team.png'
icon={<BrandIcon brand='MS Teams' />}
title='MS Teams'
detail='Join the channel'
/>
<LinkCell
area='team'
href='/team'
image='/team.jpg'
icon={<UsersRound />}
title='Our team'
detail='Meet the people behind OSF'
/>
</div>
);
}
2 changes: 1 addition & 1 deletion components/blog/MarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import rehypeSlug from 'rehype-slug';

export default function MarkdownRenderer({ content }: { content: string }) {
return (
<div className='prose w-full [&_:is(h2,h3,h4,h5,h6)]:scroll-mt-20'>
<div className='prose w-full [&_:is(h2,h3,h4,h5,h6)]:scroll-mt-28 xl:[&_:is(h2,h3,h4,h5,h6)]:scroll-mt-20'>
<ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeSlug]}>
{content}
</ReactMarkdown>
Expand Down
88 changes: 88 additions & 0 deletions components/blog/MobileTableOfContents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use client';

import { ChevronDown } from 'lucide-react';
import { useRef } from 'react';
import { useScrollProgress } from '@/hooks/use-scroll-progress';
import { useVisibleSections } from '@/hooks/use-visible-sections';
import { cn } from '@/lib/utils';
import type { PostHeading } from '@/types/blog';
import HeadingList from './HeadingList';

const RADIUS = 10;
const CIRCUMFERENCE = 2 * Math.PI * RADIUS;

interface MobileTableOfContentsProps {
headings: PostHeading[];
className?: string;
}

// Sticky bar under the header for narrow screens: shows the section being read
// and a ring that fills as the reader works through the post.
const MobileTableOfContents = ({
headings,
className,
}: MobileTableOfContentsProps) => {
const details = useRef<HTMLDetailsElement>(null);
const visible = useVisibleSections(headings.map((heading) => heading.slug));
const progress = useScrollProgress();

if (headings.length === 0) return null;

const current =
headings
.filter((heading) => visible.includes(heading.slug))
.map((heading) => heading.text)
.join(', ') || 'Overview';

return (
<details
ref={details}
// Collapse once the reader picks a section so the text is not covered.
onClick={(event) => {
if ((event.target as HTMLElement).closest('a') && details.current)
details.current.open = false;
}}
className={cn(
'group bg-background/80 sticky top-14 z-40 -mx-4 border-b px-4 py-3 backdrop-blur-sm sm:mx-0 sm:rounded-xl sm:border',
className
)}
>
<summary className='flex cursor-pointer list-none items-center gap-2 text-sm [&::-webkit-details-marker]:hidden'>
<svg
viewBox='0 0 24 24'
className='size-4 shrink-0 -rotate-90'
role='img'
aria-label={`${Math.round(progress * 100)}% read`}
>
<circle
cx='12'
cy='12'
r={RADIUS}
fill='none'
stroke='currentColor'
strokeWidth='2'
className='text-primary/20'
/>
<circle
cx='12'
cy='12'
r={RADIUS}
fill='none'
stroke='currentColor'
strokeWidth='2'
strokeDasharray={CIRCUMFERENCE}
strokeDashoffset={CIRCUMFERENCE * (1 - progress)}
className='text-primary'
/>
</svg>
<span className='text-muted-foreground grow truncate'>{current}</span>
<ChevronDown className='text-muted-foreground size-4 shrink-0 transition-transform group-open:rotate-180' />
</summary>
<div className='mt-3 max-h-[50vh] overflow-y-auto'>
<HeadingList headings={headings} />
</div>
</details>
);
};

export default MobileTableOfContents;
Loading
Loading