Fetch different number of blogposts according to route
This commit is contained in:
parent
e4c141867d
commit
cb4682f8cf
|
@ -30,7 +30,8 @@ const CMS = {
|
||||||
CTA_WHO_USES_OXEN: /^\{\{[\s]*who_uses_oxen[\s]*\}\}$/,
|
CTA_WHO_USES_OXEN: /^\{\{[\s]*who_uses_oxen[\s]*\}\}$/,
|
||||||
CTA_SESSION_LOKINET: /^\{\{[\s]*session_lokinet[\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;
|
export default CMS;
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
|
||||||
// Pagination only occurs when tag isnt defined.
|
// Pagination only occurs when tag isnt defined.
|
||||||
// If tag is defined, pagination is for tag results
|
// If tag is defined, pagination is for tag results
|
||||||
const { posts, total: totalPosts } = await cms.fetchBlogEntries(
|
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,
|
tag ? 1 : page,
|
||||||
);
|
);
|
||||||
console.log(posts);
|
console.log(posts);
|
||||||
|
@ -40,7 +40,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
|
||||||
total: _tagTotalPosts,
|
total: _tagTotalPosts,
|
||||||
} = await cms.fetchBlogEntriesByTag(
|
} = await cms.fetchBlogEntriesByTag(
|
||||||
tag ?? '',
|
tag ?? '',
|
||||||
CMS.BLOG_RESULTS_PER_PAGE,
|
CMS.BLOG_RESULTS_PER_PAGE_TAG,
|
||||||
page,
|
page,
|
||||||
);
|
);
|
||||||
tagPosts = _tagPosts;
|
tagPosts = _tagPosts;
|
||||||
|
@ -49,7 +49,7 @@ export const getServerSideProps: GetServerSideProps = async context => {
|
||||||
|
|
||||||
const total = tagTotalPosts ?? totalPosts;
|
const total = tagTotalPosts ?? totalPosts;
|
||||||
console.log(total);
|
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 {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class CmsApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchBlogEntries(
|
public async fetchBlogEntries(
|
||||||
quantity = CMS.BLOG_RESULTS_PER_PAGE,
|
quantity = CMS.BLOG_RESULTS_PER_PAGE_MAIN,
|
||||||
page = 1,
|
page = 1,
|
||||||
): Promise<IFetchBlogEntriesReturn> {
|
): Promise<IFetchBlogEntriesReturn> {
|
||||||
const entries = await this.client.getEntries({
|
const entries = await this.client.getEntries({
|
||||||
|
@ -75,7 +75,7 @@ export class CmsApi {
|
||||||
|
|
||||||
public async fetchBlogEntriesByTag(
|
public async fetchBlogEntriesByTag(
|
||||||
tag: string,
|
tag: string,
|
||||||
quantity = CMS.BLOG_RESULTS_PER_PAGE,
|
quantity = CMS.BLOG_RESULTS_PER_PAGE_TAG,
|
||||||
page = 1,
|
page = 1,
|
||||||
): Promise<IFetchBlogEntriesReturn> {
|
): Promise<IFetchBlogEntriesReturn> {
|
||||||
const entries = await this.client.getEntries({
|
const entries = await this.client.getEntries({
|
||||||
|
|
Loading…
Reference in New Issue