Skip to content

Commit

Permalink
refactor: format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
valcosmos committed Sep 30, 2024
1 parent c10c056 commit 3f0b761
Show file tree
Hide file tree
Showing 54 changed files with 2,885 additions and 1,626 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
id-token: write

concurrency:
group: 'pages'
group: pages
cancel-in-progress: false

jobs:
Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install PNPM
- name: Install PNPM
run: npm i -g pnpm
- id: configurepages
uses: actions/configure-pages@v5
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
## Blogi

4 changes: 2 additions & 2 deletions app/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Link from '@/components/Link'
import Tag from '@/components/Tag'
import siteMetadata from '@/data/siteMetadata'
import { formatDate } from 'pliny/utils/formatDate'
import NewsletterForm from 'pliny/ui/NewsletterForm'
import { formatDate } from 'pliny/utils/formatDate'

const MAX_DISPLAY = 5

Expand Down Expand Up @@ -44,7 +44,7 @@ export default function Home({ posts }) {
</Link>
</h2>
<div className="flex flex-wrap">
{tags.map((tag) => (
{tags.map(tag => (
<Tag key={tag} text={tag} />
))}
</div>
Expand Down
18 changes: 9 additions & 9 deletions app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Authors, allAuthors } from 'contentlayer/generated'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import type { Authors } from 'contentlayer/generated'
import AuthorLayout from '@/layouts/AuthorLayout'
import { coreContent } from 'pliny/utils/contentlayer'
import { genPageMetadata } from 'app/seo'
import { allAuthors } from 'contentlayer/generated'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { coreContent } from 'pliny/utils/contentlayer'

export const metadata = genPageMetadata({ title: 'About' })

export default function Page() {
const author = allAuthors.find((p) => p.slug === 'default') as Authors
const author = allAuthors.find(p => p.slug === 'default') as Authors
const mainContent = coreContent(author)

return (
<>
<AuthorLayout content={mainContent}>
<MDXLayoutRenderer code={author.body.code} />
</AuthorLayout>
</>

<AuthorLayout content={mainContent}>
<MDXLayoutRenderer code={author.body.code} />
</AuthorLayout>
)
}
5 changes: 2 additions & 3 deletions app/api/newsletter/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NewsletterAPI } from 'pliny/newsletter'
import siteMetadata from '@/data/siteMetadata'
import { NewsletterAPI } from 'pliny/newsletter'

const handler = NewsletterAPI({
// @ts-ignore
provider: siteMetadata.newsletter.provider,
provider: siteMetadata.newsletter!.provider,
})

export { handler as GET, handler as POST }
41 changes: 20 additions & 21 deletions app/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import 'css/prism.css'
import 'katex/dist/katex.css'
import type { Authors, Blog } from 'contentlayer/generated'
import type { Metadata } from 'next'

import PageTitle from '@/components/PageTitle'
import { components } from '@/components/MDXComponents'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { sortPosts, coreContent, allCoreContent } from 'pliny/utils/contentlayer'
import { allBlogs, allAuthors } from 'contentlayer/generated'
import type { Authors, Blog } from 'contentlayer/generated'
import PostSimple from '@/layouts/PostSimple'
import PostLayout from '@/layouts/PostLayout'
import PostBanner from '@/layouts/PostBanner'
import { Metadata } from 'next'
import siteMetadata from '@/data/siteMetadata'
import PostBanner from '@/layouts/PostBanner'
import PostLayout from '@/layouts/PostLayout'
import PostSimple from '@/layouts/PostSimple'
import { allAuthors, allBlogs } from 'contentlayer/generated'
import { notFound } from 'next/navigation'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { allCoreContent, coreContent, sortPosts } from 'pliny/utils/contentlayer'
import 'css/prism.css'
import 'katex/dist/katex.css'

const defaultLayout = 'PostLayout'
const layouts = {
Expand All @@ -27,10 +26,10 @@ export async function generateMetadata({
params: { slug: string[] }
}): Promise<Metadata | undefined> {
const slug = decodeURI(params.slug.join('/'))
const post = allBlogs.find((p) => p.slug === slug)
const post = allBlogs.find(p => p.slug === slug)
const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author)
const authorResults = allAuthors.find(p => p.slug === author)
return coreContent(authorResults as Authors)
})
if (!post) {
Expand All @@ -39,7 +38,7 @@ export async function generateMetadata({

const publishedAt = new Date(post.date).toISOString()
const modifiedAt = new Date(post.lastmod || post.date).toISOString()
const authors = authorDetails.map((author) => author.name)
const authors = authorDetails.map(author => author.name)
let imageList = [siteMetadata.socialBanner]
if (post.images) {
imageList = typeof post.images === 'string' ? [post.images] : post.images
Expand Down Expand Up @@ -74,33 +73,33 @@ export async function generateMetadata({
}
}

export const generateStaticParams = async () => {
return allBlogs.map((p) => ({ slug: p.slug.split('/').map((name) => decodeURI(name)) }))
export async function generateStaticParams() {
return allBlogs.map(p => ({ slug: p.slug.split('/').map(name => decodeURI(name)) }))
}

export default async function Page({ params }: { params: { slug: string[] } }) {
const slug = decodeURI(params.slug.join('/'))
// Filter out drafts in production
const sortedCoreContents = allCoreContent(sortPosts(allBlogs))
const postIndex = sortedCoreContents.findIndex((p) => p.slug === slug)
const postIndex = sortedCoreContents.findIndex(p => p.slug === slug)
if (postIndex === -1) {
return notFound()
}

const prev = sortedCoreContents[postIndex + 1]
const next = sortedCoreContents[postIndex - 1]
const post = allBlogs.find((p) => p.slug === slug) as Blog
const post = allBlogs.find(p => p.slug === slug) as Blog
const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author)
const authorResults = allAuthors.find(p => p.slug === author)
return coreContent(authorResults as Authors)
})
const mainContent = coreContent(post)
const jsonLd = post.structuredData
jsonLd['author'] = authorDetails.map((author) => {
jsonLd.author = authorDetails.map((author) => {
return {
'@type': 'Person',
name: author.name,
'name': author.name,
}
})

Expand Down
6 changes: 3 additions & 3 deletions app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { genPageMetadata } from 'app/seo'
import { allBlogs } from 'contentlayer/generated'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'

const POSTS_PER_PAGE = 5

Expand All @@ -12,7 +12,7 @@ export default function BlogPage() {
const pageNumber = 1
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
POSTS_PER_PAGE * pageNumber
POSTS_PER_PAGE * pageNumber,
)
const pagination = {
currentPage: pageNumber,
Expand Down
8 changes: 4 additions & 4 deletions app/blog/page/[page]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'

const POSTS_PER_PAGE = 5

export const generateStaticParams = async () => {
export async function generateStaticParams() {
const totalPages = Math.ceil(allBlogs.length / POSTS_PER_PAGE)
const paths = Array.from({ length: totalPages }, (_, i) => ({ page: (i + 1).toString() }))

Expand All @@ -13,10 +13,10 @@ export const generateStaticParams = async () => {

export default function Page({ params }: { params: { page: string } }) {
const posts = allCoreContent(sortPosts(allBlogs))
const pageNumber = parseInt(params.page as string)
const pageNumber = Number.parseInt(params.page as string)
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
POSTS_PER_PAGE * pageNumber
POSTS_PER_PAGE * pageNumber,
)
const pagination = {
currentPage: pageNumber,
Expand Down
24 changes: 14 additions & 10 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import 'css/tailwind.css'
import 'pliny/search/algolia.css'
import 'remark-github-blockquote-alert/alert.css'
import type { Metadata } from 'next'
import type { AnalyticsConfig } from 'pliny/analytics'
import type { SearchConfig } from 'pliny/search'

import { Space_Grotesk } from 'next/font/google'
import { Analytics, AnalyticsConfig } from 'pliny/analytics'
import { SearchProvider, SearchConfig } from 'pliny/search'
// import process from 'node:process'
import Footer from '@/components/Footer'
import Header from '@/components/Header'
import SectionContainer from '@/components/SectionContainer'
import Footer from '@/components/Footer'
import siteMetadata from '@/data/siteMetadata'
import { Space_Grotesk } from 'next/font/google'
import { Analytics } from 'pliny/analytics'
import { SearchProvider } from 'pliny/search'
import { ThemeProviders } from './theme-providers'
import { Metadata } from 'next'
import 'css/tailwind.css'
import 'pliny/search/algolia.css'

import 'remark-github-blockquote-alert/alert.css'

const space_grotesk = Space_Grotesk({
subsets: ['latin'],
Expand Down Expand Up @@ -44,8 +48,8 @@ export const metadata: Metadata = {
index: true,
follow: true,
googleBot: {
index: true,
follow: true,
'index': true,
'follow': true,
'max-video-preview': -1,
'max-image-preview': 'large',
'max-snippet': -1,
Expand Down
2 changes: 1 addition & 1 deletion app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function NotFound() {
<p className="mb-8">But dont worry, you can find plenty of other things on our homepage.</p>
<Link
href="/"
className="focus:shadow-outline-blue inline rounded-lg border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium leading-5 text-white shadow transition-colors duration-150 hover:bg-blue-700 focus:outline-none dark:hover:bg-blue-500"
className="inline rounded-lg border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium leading-5 text-white shadow transition-colors duration-150 hover:bg-blue-700 focus:shadow-blue-500 focus:outline-none dark:hover:bg-blue-500"
>
Back to homepage
</Link>
Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sortPosts, allCoreContent } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import Main from './Main'

export default async function Page() {
Expand Down
48 changes: 24 additions & 24 deletions app/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import projectsData from '@/data/projectsData'
import Card from '@/components/Card'
import projectsData from '@/data/projectsData'
import { genPageMetadata } from 'app/seo'

export const metadata = genPageMetadata({ title: 'Projects' })

export default function Projects() {
return (
<>
<div className="divide-y divide-gray-200 dark:divide-gray-700">
<div className="space-y-2 pb-8 pt-6 md:space-y-5">
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
Projects
</h1>
<p className="text-lg leading-7 text-gray-500 dark:text-gray-400">
Showcase your projects with a hero image (16 x 9)
</p>
</div>
<div className="container py-12">
<div className="-m-4 flex flex-wrap">
{projectsData.map((d) => (
<Card
key={d.title}
title={d.title}
description={d.description}
imgSrc={d.imgSrc}
href={d.href}
/>
))}
</div>

<div className="divide-y divide-gray-200 dark:divide-gray-700">
<div className="space-y-2 pb-8 pt-6 md:space-y-5">
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
Projects
</h1>
<p className="text-lg leading-7 text-gray-500 dark:text-gray-400">
Showcase your projects with a hero image (16 x 9)
</p>
</div>
<div className="container py-12">
<div className="-m-4 flex flex-wrap">
{projectsData.map(d => (
<Card
key={d.title}
title={d.title}
description={d.description}
imgSrc={d.imgSrc}
href={d.href}
/>
))}
</div>
</div>
</>
</div>

)
}
2 changes: 1 addition & 1 deletion app/robots.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataRoute } from 'next'
import type { MetadataRoute } from 'next'
import siteMetadata from '@/data/siteMetadata'

export default function robots(): MetadataRoute.Robots {
Expand Down
3 changes: 1 addition & 2 deletions app/seo.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Metadata } from 'next'
import type { Metadata } from 'next'
import siteMetadata from '@/data/siteMetadata'

interface PageSEOProps {
title: string
description?: string
image?: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any
}

Expand Down
10 changes: 5 additions & 5 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { MetadataRoute } from 'next'
import { allBlogs } from 'contentlayer/generated'
import type { MetadataRoute } from 'next'
import siteMetadata from '@/data/siteMetadata'
import { allBlogs } from 'contentlayer/generated'

export default function sitemap(): MetadataRoute.Sitemap {
const siteUrl = siteMetadata.siteUrl

const blogRoutes = allBlogs
.filter((post) => !post.draft)
.map((post) => ({
.filter(post => !post.draft)
.map(post => ({
url: `${siteUrl}/${post.path}`,
lastModified: post.lastmod || post.date,
}))

const routes = ['', 'blog', 'projects', 'tags'].map((route) => ({
const routes = ['', 'blog', 'projects', 'tags'].map(route => ({
url: `${siteUrl}/${route}`,
lastModified: new Date().toISOString().split('T')[0],
}))
Expand Down
Loading

0 comments on commit 3f0b761

Please sign in to comment.