Skip to content

Commit

Permalink
feat: add number of posts config for home page (#281)
Browse files Browse the repository at this point in the history
* Add a SITE config parameter for posts in index page

* docs: update blog post for `postPerIndex` config

---------

Co-authored-by: satnaing <[email protected]>
  • Loading branch information
davlgd and satnaing committed Jul 14, 2024
1 parent 7b045a0 commit 0d5ea52
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const SITE: Site = {
title: "AstroPaper",
ogImage: "astropaper-og.jpg",
lightAndDarkMode: true,
postPerIndex: 4,
postPerPage: 3,
scheduledPostMargin: 15 * 60 * 1000, // 15 minutes
};
Expand Down
1 change: 1 addition & 0 deletions src/content/blog/how-to-configure-astropaper-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Here are SITE configuration options
| `title` | Your site name |
| `ogImage` | Your default OG image for the site. Useful for social media sharing. OG images can be an external image url or they can be placed under `/public` directory. |
| `lightAndDarkMode` | Enable or disable `light & dark mode` for the website. If disabled, primary color scheme will be used. This option is enabled by default. |
| `postPerIndex` | The number of posts to be displayed at the home page under `Recent` section. |
| `postPerPage` | You can specify how many posts will be displayed in each posts page. (eg: if you set SITE.postPerPage to 3, each page will only show 3 posts per page) |
| `scheduledPostMargin` | In Production mode, posts with a future `pubDatetime` will not be visible. However, if a post's `pubDatetime` is within the next 15 minutes, it will be visible. You can set `scheduledPostMargin` if you don't like the default 15 minutes margin. |

Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Hr from "@components/Hr.astro";
import Card from "@components/Card";
import Socials from "@components/Socials.astro";
import getSortedPosts from "@utils/getSortedPosts";
import { SOCIALS } from "@config";
import { SITE, SOCIALS } from "@config";
const posts = await getCollection("blog");
Expand Down Expand Up @@ -96,7 +96,7 @@ const socialCount = SOCIALS.filter(social => social.active).length;
<ul>
{recentPosts.map(
({ data, slug }, index) =>
index < 4 && (
index < SITE.postPerIndex && (
<Card
href={`/posts/${slug}/`}
frontmatter={data}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Site = {
title: string;
ogImage?: string;
lightAndDarkMode: boolean;
postPerIndex: number;
postPerPage: number;
scheduledPostMargin: number;
};
Expand Down

0 comments on commit 0d5ea52

Please sign in to comment.