Replace env variable with SITE config object

This commit is contained in:
Sat Naing
2022-09-22 21:32:02 +06:30
parent f8d3a3a960
commit 300fd568e9
11 changed files with 30 additions and 22 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
---
import { SITE } from "src/config";
import Posts from "@layouts/Posts.astro";
import PostDetails from "@layouts/PostDetails.astro";
import getSortedPosts from "@utils/getSortedPosts";
@@ -59,8 +60,8 @@ const currentPage =
slug && !isNaN(Number(slug)) && totalPages.includes(Number(slug))
? Number(slug)
: 0;
const lastPost = currentPage * import.meta.env.PUBLIC_POST_PER_PAGE;
const startPost = lastPost - import.meta.env.PUBLIC_POST_PER_PAGE;
const lastPost = currentPage * SITE.postPerPage;
const startPost = lastPost - SITE.postPerPage;
const paginatedPosts = sortedPosts.slice(startPost, lastPost);
---
+3 -5
View File
@@ -1,8 +1,9 @@
---
import { SITE } from "src/config";
import Posts from "@layouts/Posts.astro";
import getSortedPosts from "@utils/getSortedPosts";
import getPageNumbers from "@utils/getPageNumbers";
import type { Frontmatter } from "@utils/types";
import type { Frontmatter } from "src/types";
const posts = await Astro.glob<Frontmatter>("../../contents/*.md");
@@ -10,10 +11,7 @@ const sortedPosts = getSortedPosts(posts);
const totalPages = getPageNumbers(posts.length);
const paginatedPosts = sortedPosts.slice(
0,
import.meta.env.PUBLIC_POST_PER_PAGE
);
const paginatedPosts = sortedPosts.slice(0, SITE.postPerPage);
---
<Posts posts={paginatedPosts} pageNum={1} totalPages={totalPages.length} />