Skip to content

Commit

Permalink
Support pinning posts
Browse files Browse the repository at this point in the history
  • Loading branch information
half0wl committed Feb 25, 2023
1 parent 9c51cb7 commit 559567f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import HomepageComponent, { Head } from "@lekoarts/gatsby-theme-minimal-blog-cor
/**
* Shadowed component with the following tweaks:
* - Remove limit on allPost
* - Support pinning posts
*/

export default HomepageComponent
Expand All @@ -24,6 +25,15 @@ export const query = graphql`
name
slug
}
... on MdxPost {
parent {
... on Mdx {
frontmatter {
featured
}
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** @jsx jsx */
import * as React from "react"
import { Text } from "theme-ui"
import { jsx, Box } from "theme-ui"
import { Link } from "gatsby"
import ItemTags from "./item-tags"
import { Highlight } from "../utils"

/**
* Shadowed component with the following tweaks:
* - Support pinning posts
*/

type BlogListItemProps = {
post: {
slug: string
title: string
date: string
excerpt: string
description: string
timeToRead?: number
tags?: {
name: string
slug: string
}[]
}
featured?: boolean
showTags?: boolean
}

const BlogListItem = ({ featured, post, showTags = true }: BlogListItemProps) => (
<Box mb={4}>
<Link to={post.slug} sx={(t) => ({ ...t.styles?.a, fontSize: [1, 2, 3], color: `text` })}>
{ featured ? <Highlight>📌 {post.title}</Highlight> : post.title }
</Link>
<p sx={{ color: `secondary`, mt: 1, a: { color: `secondary` }, fontSize: [1, 1, 2] }}>
<time>{post.date}</time>
{post.tags && showTags && (
<React.Fragment>
{` — `}
<ItemTags tags={post.tags} />
</React.Fragment>
)}
</p>
</Box>
)

export default BlogListItem
14 changes: 8 additions & 6 deletions src/@lekoarts/gatsby-theme-minimal-blog/components/homepage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/** @jsx jsx */
import { jsx, Text } from "theme-ui";
import { ReactNode } from "react";
import { HeadFC, Link } from "gatsby";
import Layout from "@lekoarts/gatsby-theme-minimal-blog/src/components/layout";
import Title from "@lekoarts/gatsby-theme-minimal-blog/src/components/title";
import Listing from "@lekoarts/gatsby-theme-minimal-blog/src/components/listing";
import Listing from "./listing";
import useMinimalBlogConfig from "@lekoarts/gatsby-theme-minimal-blog/src/hooks/use-minimal-blog-config";
import useSiteMetadata from "@lekoarts/gatsby-theme-minimal-blog/src/hooks/use-site-metadata";
import replaceSlashes from "@lekoarts/gatsby-theme-minimal-blog/src/utils/replaceSlashes";
import { visuallyHidden } from "@lekoarts/gatsby-theme-minimal-blog/src/styles/utils";
import Seo from "@lekoarts/gatsby-theme-minimal-blog/src/components/seo";
import { Highlight } from "../utils"
import Hero from "../texts/hero.mdx";

/**
Expand All @@ -20,6 +20,7 @@ import Hero from "../texts/hero.mdx";
* - Remove <Bottom /> component (originally for "Projects" section in theme)
* - Turn "Read all posts" into "View all tags"
* - Hardcode hero section instead of using content from hero.mdx
* - Support pinning posts
*/

export type MBHomepageProps = {
Expand All @@ -34,13 +35,14 @@ export type MBHomepageProps = {
name: string
slug: string
}[]
parent: {
frontmatter: {
[key: string]: any
}
}
}[]
}

const Highlight = ({ children }: { children: ReactNode }) => {
return <strong style={{ color: "rgb(255, 146, 112)" }}>{children}</strong>;
};

const Homepage = ({ posts }: MBHomepageProps) => {
const { basePath, tagsPath } = useMinimalBlogConfig()
const { siteTitle } = useSiteMetadata()
Expand Down
15 changes: 13 additions & 2 deletions src/@lekoarts/gatsby-theme-minimal-blog/components/listing.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/** @jsx jsx */
import { jsx } from "theme-ui"
import BlogListItem from "@lekoarts/gatsby-theme-minimal-blog/src/components/blog-list-item";
import BlogListItem from "./blog-list-item";

/**
* Shadowed component with the following tweaks:
* - Lower margin-bottom
* - Support pinning posts
*/

type ListingProps = {
Expand All @@ -19,6 +20,11 @@ type ListingProps = {
name: string
slug: string
}[]
parent: {
frontmatter: {
[key: string]: any
}
}
}[]
className?: string
showTags?: boolean
Expand All @@ -27,7 +33,12 @@ type ListingProps = {
const Listing = ({ posts, className = ``, showTags = true }: ListingProps) => (
<section sx={{ mb: [3, 3, 3] }} className={className}>
{posts.map((post) => (
<BlogListItem key={post.slug} post={post} showTags={showTags} />
<BlogListItem
key={post.slug}
featured={post.parent.frontmatter.featured}
post={post}
showTags={showTags}
/>
))}
</section>
)
Expand Down
7 changes: 7 additions & 0 deletions src/@lekoarts/gatsby-theme-minimal-blog/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @jsx jsx */
import { jsx } from 'theme-ui'
import { ReactNode } from 'react'

export const Highlight = ({ children }: { children: ReactNode }) => {
return <strong style={{ color: 'rgb(255, 146, 112)' }}>{children}</strong>
}

0 comments on commit 559567f

Please sign in to comment.