Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from paveg/additional-info
Browse files Browse the repository at this point in the history
⚙️ Added additional information to the posts, except for footnotes
  • Loading branch information
paveg authored Mar 17, 2024
2 parents de26f63 + 644e31d commit da14329
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function generateStaticParams(): Promise<PageProps['params'][]> {
}

export default async function PagePage({ params }: PageProps) {
const pagePublishedDate = '2024-03-17'
const pagePublishedDate = '2024-03-17';
const page = await getPageFromParams(params);

if (!page) {
Expand Down
27 changes: 21 additions & 6 deletions app/posts/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import '@/styles/codes/prism-dracula.css';
import { notFound } from 'next/navigation';
import { Metadata } from 'next';
import { ArticleJsonLd } from 'next-seo';
import { ReaderIcon } from '@radix-ui/react-icons';
import { allPosts } from 'contentlayer/generated';
import { Mdx } from '@/components/mdx-components';
import { TableOfContents } from '@/components/table-of-contents';
import { cfg } from '@/utils/constants';
import { CategoryBadge } from '@/components/category-badge';

interface PostProps {
params: {
Expand Down Expand Up @@ -79,12 +81,25 @@ export default async function PostPage({ params }: PostProps) {
authorName={cfg.author}
description={post?.description ?? ''}
/>
<h1 className="mb-4">{post.title}</h1>
{post.date && (
<p className="text-sm text-slate-700 dark:text-slate-200">
{formatDate(post.date)}
</p>
)}
<h1>{post.title}</h1>
<div className="flex gap-4 align-middle text-sm">
{post.date && (
<span className="text-slate-700 dark:text-slate-200">
{formatDate(post.date)}
</span>
)}
<span className="text-slate-700 dark:text-slate-200">
<CategoryBadge badgeString={post.category} />
</span>
{post.readingTime && (
<div className="flex gap-2">
<ReaderIcon className="h-4 w-4">{post.readingTime.text}</ReaderIcon>
<span className="text-slate-700 dark:text-slate-200">
{post.readingTime.text}
</span>
</div>
)}
</div>
<hr className="my-4" />
<div
className="lg:grid lg:grid-cols-4 lg:gap-x-6"
Expand Down
24 changes: 24 additions & 0 deletions components/category-badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Badge } from './ui/badge';

type Props = {
badgeString?: string;
};

type BadgeTypes =
| 'Technology'
| 'Programming'
| 'Productivity'
| 'Lifestyle'
| 'Gadgets'
| 'Other';

const toPascalCase = (str: string) => {
return [str]
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join('');
};

export const CategoryBadge = ({ badgeString }: Props) => {
const bs = badgeString ? toPascalCase(badgeString) : 'Other';
return <Badge variant="secondary">{bs}</Badge>;
};
36 changes: 36 additions & 0 deletions components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '@/lib/utils';

const badgeVariants = cva(
'inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
{
variants: {
variant: {
default:
'border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80',
secondary:
'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
destructive:
'border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80',
outline: 'text-foreground',
},
},
defaultVariants: {
variant: 'default',
},
}
);

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
);
}

export { Badge, badgeVariants };
1 change: 1 addition & 0 deletions content/posts/sample.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Sample
description: Sample post
category: lifestyle
date: 2020-01-01
---

Expand Down
9 changes: 9 additions & 0 deletions content/posts/without-category-post.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Without category post
description: This post doesn't have a category.
date: 2024-03-17
---

## As a premise

This post doesn't have a category, so, please check it.
6 changes: 6 additions & 0 deletions contentlayer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { defineDocumentType, makeSource } from 'contentlayer/source-files';
import rehypeSlug from 'rehype-slug';
import rehypePrism from 'rehype-prism-plus';
import rehypeCodeTitles from 'rehype-code-titles';
import readingTime from 'reading-time';

/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
slug: {
type: 'string',
resolve: (doc) => `/${doc._raw.flattenedPath}`,
Expand Down Expand Up @@ -47,6 +49,10 @@ export const Post = defineDocumentType(() => ({
type: 'date',
required: true,
},
category: {
type: 'string',
required: false,
},
},
computedFields,
}));
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"reading-time": "^1.5.0",
"rehype-code-titles": "^1.2.0",
"rehype-prism-plus": "^2.0.0",
"rehype-slug": "^6.0.0",
"remark-footnotes": "^4.0.1",
"tailwind-merge": "^2.2.1",
"tailwindcss": "3.3.2",
"tailwindcss-animate": "^1.0.7",
Expand Down
52 changes: 52 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da14329

Please sign in to comment.