Fetch different number of blogposts according to route

This commit is contained in:
Lucas Phang 2021-04-23 10:33:35 +10:00
parent e4c141867d
commit cb4682f8cf
3 changed files with 7 additions and 6 deletions

View File

@ -30,7 +30,8 @@ const CMS = {
CTA_WHO_USES_OXEN: /^\{\{[\s]*who_uses_oxen[\s]*\}\}$/,
CTA_SESSION_LOKINET: /^\{\{[\s]*session_lokinet[\s]*\}\}$/,
},
BLOG_RESULTS_PER_PAGE: 21,
BLOG_RESULTS_PER_PAGE_MAIN: 21,
BLOG_RESULTS_PER_PAGE_TAG: 20,
};
export default CMS;

View File

@ -26,7 +26,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
// Pagination only occurs when tag isnt defined.
// If tag is defined, pagination is for tag results
const { posts, total: totalPosts } = await cms.fetchBlogEntries(
tag ? 8 : CMS.BLOG_RESULTS_PER_PAGE,
tag ? 8 : CMS.BLOG_RESULTS_PER_PAGE_MAIN,
tag ? 1 : page,
);
console.log(posts);
@ -40,7 +40,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
total: _tagTotalPosts,
} = await cms.fetchBlogEntriesByTag(
tag ?? '',
CMS.BLOG_RESULTS_PER_PAGE,
CMS.BLOG_RESULTS_PER_PAGE_TAG,
page,
);
tagPosts = _tagPosts;
@ -49,7 +49,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
const total = tagTotalPosts ?? totalPosts;
console.log(total);
const pageCount = Math.ceil(total / CMS.BLOG_RESULTS_PER_PAGE);
const pageCount = Math.ceil(total / CMS.BLOG_RESULTS_PER_PAGE_MAIN);
return {
props: {

View File

@ -32,7 +32,7 @@ export class CmsApi {
}
public async fetchBlogEntries(
quantity = CMS.BLOG_RESULTS_PER_PAGE,
quantity = CMS.BLOG_RESULTS_PER_PAGE_MAIN,
page = 1,
): Promise<IFetchBlogEntriesReturn> {
const entries = await this.client.getEntries({
@ -75,7 +75,7 @@ export class CmsApi {
public async fetchBlogEntriesByTag(
tag: string,
quantity = CMS.BLOG_RESULTS_PER_PAGE,
quantity = CMS.BLOG_RESULTS_PER_PAGE_TAG,
page = 1,
): Promise<IFetchBlogEntriesReturn> {
const entries = await this.client.getEntries({