update pagination
This commit is contained in:
@@ -238,13 +238,19 @@ module.exports = {
|
||||
tags: {
|
||||
typeName: 'BlogTag',
|
||||
create: true
|
||||
},
|
||||
|
||||
category: {
|
||||
typeName: 'BlogCategory',
|
||||
create: true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
use: '@gridsome/source-filesystem',
|
||||
use: '@gridsome/source-filesystem',
|
||||
options: {
|
||||
typeName: 'News',
|
||||
path: './content/news/**/*.md',
|
||||
@@ -253,6 +259,11 @@ module.exports = {
|
||||
tags: {
|
||||
typeName: 'NewsTag',
|
||||
create: true
|
||||
},
|
||||
|
||||
category: {
|
||||
typeName: 'NewsCategory',
|
||||
create: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
v-for="(slide, index) in slides"
|
||||
:key="index"
|
||||
:href="`#${index}`"
|
||||
class="mt-1 capitalize group flex items-center px-3 py-2 text-sm leading-5 font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-50 focus:outline-none focus:text-gray-900 focus:bg-gray-50 transition ease-in-out duration-150"
|
||||
class="mt-1 capitalize group flex items-center px-3 py-2 text-sm leading-5 font-medium hover:text-gray-900 hover:bg-gray-400 focus:outline-none transition border-blue-500 hover:bg-gray-100 transition ease-in-out duration-150"
|
||||
:class="{
|
||||
'text-gray-900 border-r-3 border-blue-500 hover:bg-gray-100':
|
||||
activeIndex === index,
|
||||
'border-r-3 border-blue-500 hover:bg-gray-100': activeIndex === index,
|
||||
}"
|
||||
@click="setActive(index)"
|
||||
>
|
||||
@@ -20,12 +19,14 @@
|
||||
class="content inline-block h-full w-3/4 align-top p-5 transition ease-in-out duration-150"
|
||||
>
|
||||
<div :id="slides[activeIndex]" class="hidden" style="display: block">
|
||||
<img
|
||||
v-if="slides[activeIndex].img"
|
||||
:src="slides[activeIndex].img.src"
|
||||
<g-image
|
||||
v-if="slides[activeIndex].image"
|
||||
:src="
|
||||
require(`!!assets-loader!@images/sliders/${slides[activeIndex].image}`)
|
||||
"
|
||||
:alt="slides[activeIndex].title"
|
||||
/>
|
||||
<p v-html="slides[activeIndex].content"></p>
|
||||
<div v-html="slides[activeIndex].content"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -46,4 +47,3 @@ export default {
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
>filter:</span
|
||||
>
|
||||
</div>
|
||||
<div class="sm:block md:hidden">
|
||||
<ul class="list-none inline-flex justify-center md:justify-end">
|
||||
<li class="py-1 mx-5 cursor-pointer" @click="resetAll()">Reset</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav
|
||||
@@ -70,6 +75,11 @@
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="hidden md:ml-auto md:inline-block md:order-last">
|
||||
<ul class="list-none inline-flex justify-center md:justify-end">
|
||||
<li class="py-1 mx-5 cursor-pointer" @click="resetAll()">Reset</li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
</template>
|
||||
@@ -105,6 +115,9 @@ export default {
|
||||
this.open = false;
|
||||
}
|
||||
},
|
||||
resetAll() {
|
||||
this.$emit("resetAll", true);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
document.addEventListener("click", this.close);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<Layout>
|
||||
<NewsFilterHeader
|
||||
<NewsFilterHeader
|
||||
@selectedTopic="setTopic"
|
||||
@selectedYear="setYear"
|
||||
@selectedMonth="setMonth"
|
||||
@@ -9,7 +9,7 @@
|
||||
:years="years"
|
||||
:months="months"
|
||||
/>
|
||||
<div
|
||||
<div
|
||||
class="container sm:pxi-0 mx-auto mt-8"
|
||||
:style="{ 'min-height': contentHeight + 'px' }"
|
||||
>
|
||||
@@ -21,23 +21,22 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="pagination flex justify-center mb-8">
|
||||
<Pagination
|
||||
baseUrl=""
|
||||
:currentPage="blogs.pageInfo.currentPage"
|
||||
:totalPages="blogs.pageInfo.totalPages"
|
||||
:maxVisibleButtons="5"
|
||||
v-if="blogs.pageInfo.totalPages > 1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="pagination flex justify-center mb-8">
|
||||
<Pagination
|
||||
:baseUrl="baseurl"
|
||||
:currentPage="blogs.pageInfo.currentPage"
|
||||
:totalPages="blogs.pageInfo.totalPages"
|
||||
:maxVisibleButtons="5"
|
||||
v-if="blogs.pageInfo.totalPages > 1 && blogs.edges.length > 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
</template>
|
||||
<page-query>
|
||||
|
||||
query{
|
||||
entries: allBlog(sortBy: "created", order: DESC) {
|
||||
query($page: Int){
|
||||
entries: allBlog(perPage: 10, page: $page, sortBy: "created", order: DESC, filter: {category: { id: {in: ["farming"]}}}) @paginate{
|
||||
totalCount
|
||||
pageInfo {
|
||||
totalPages
|
||||
@@ -52,6 +51,10 @@ query{
|
||||
path
|
||||
}
|
||||
excerpt
|
||||
category{
|
||||
id
|
||||
title
|
||||
}
|
||||
image(width:800)
|
||||
path
|
||||
humanTime : created(format:"DD MMM YYYY")
|
||||
@@ -84,7 +87,7 @@ import NewsFilterHeader from "~/components/custom/NewsFilterHeader.vue";
|
||||
export default {
|
||||
data() {
|
||||
const allMonths = [
|
||||
"All",
|
||||
"All Months",
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
@@ -99,23 +102,23 @@ export default {
|
||||
"December",
|
||||
];
|
||||
const currYear = new Date().getFullYear();
|
||||
var years = ["All"]
|
||||
var r = this.range(2019, currYear)
|
||||
var years = ["All Years"];
|
||||
var r = this.range(2019, currYear);
|
||||
r.forEach((year) => years.push(String(year)));
|
||||
|
||||
return {
|
||||
selectedTopic: "All",
|
||||
selectedYear: "All",
|
||||
selectedMonth: "All",
|
||||
return {
|
||||
selectedTopic: "All Topics",
|
||||
selectedYear: "All Years",
|
||||
selectedMonth: "All Months",
|
||||
months: allMonths,
|
||||
years: years,
|
||||
listArchive: false,
|
||||
archiveButtonText : "Archive"
|
||||
archiveButtonText: "Archive",
|
||||
};
|
||||
},
|
||||
|
||||
metaInfo: {
|
||||
title: "Newsroom",
|
||||
title: "Blog",
|
||||
},
|
||||
components: {
|
||||
PostListItem,
|
||||
@@ -133,64 +136,58 @@ export default {
|
||||
this.selectedMonth = month;
|
||||
},
|
||||
resetAll() {
|
||||
this.selectedTopic = "All";
|
||||
this.selectedYear = "All";
|
||||
this.selectedMonth = "All";
|
||||
this.selectedTopic = "All Topics";
|
||||
this.selectedYear = "All Years";
|
||||
this.selectedMonth = "All Months";
|
||||
},
|
||||
range(start, end, step) {
|
||||
var range = [];
|
||||
var typeofStart = typeof start;
|
||||
var typeofEnd = typeof end;
|
||||
var range = [];
|
||||
var typeofStart = typeof start;
|
||||
var typeofEnd = typeof end;
|
||||
|
||||
if (step === 0) {
|
||||
throw TypeError("Step cannot be zero.");
|
||||
if (step === 0) {
|
||||
throw TypeError("Step cannot be zero.");
|
||||
}
|
||||
|
||||
if (typeofStart == "undefined" || typeofEnd == "undefined") {
|
||||
throw TypeError("Must pass start and end arguments.");
|
||||
} else if (typeofStart != typeofEnd) {
|
||||
throw TypeError("Start and end arguments must be of same type.");
|
||||
}
|
||||
|
||||
typeof step == "undefined" && (step = 1);
|
||||
|
||||
if (end < start) {
|
||||
step = -step;
|
||||
}
|
||||
|
||||
if (typeofStart == "number") {
|
||||
while (step > 0 ? end >= start : end <= start) {
|
||||
range.push(start);
|
||||
start += step;
|
||||
}
|
||||
} else if (typeofStart == "string") {
|
||||
if (start.length != 1 || end.length != 1) {
|
||||
throw TypeError("Only strings with one character are supported.");
|
||||
}
|
||||
|
||||
if (typeofStart == "undefined" || typeofEnd == "undefined") {
|
||||
throw TypeError("Must pass start and end arguments.");
|
||||
} else if (typeofStart != typeofEnd) {
|
||||
throw TypeError("Start and end arguments must be of same type.");
|
||||
start = start.charCodeAt(0);
|
||||
end = end.charCodeAt(0);
|
||||
|
||||
while (step > 0 ? end >= start : end <= start) {
|
||||
range.push(String.fromCharCode(start));
|
||||
start += step;
|
||||
}
|
||||
} else {
|
||||
throw TypeError("Only string and number types are supported");
|
||||
}
|
||||
|
||||
typeof step == "undefined" && (step = 1);
|
||||
|
||||
if (end < start) {
|
||||
step = -step;
|
||||
}
|
||||
|
||||
if (typeofStart == "number") {
|
||||
|
||||
while (step > 0 ? end >= start : end <= start) {
|
||||
range.push(start);
|
||||
start += step;
|
||||
}
|
||||
|
||||
} else if (typeofStart == "string") {
|
||||
|
||||
if (start.length != 1 || end.length != 1) {
|
||||
throw TypeError("Only strings with one character are supported.");
|
||||
}
|
||||
|
||||
start = start.charCodeAt(0);
|
||||
end = end.charCodeAt(0);
|
||||
|
||||
while (step > 0 ? end >= start : end <= start) {
|
||||
range.push(String.fromCharCode(start));
|
||||
start += step;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw TypeError("Only string and number types are supported");
|
||||
}
|
||||
|
||||
return range;
|
||||
|
||||
}
|
||||
return range;
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
|
||||
topics: function () {
|
||||
var res = ["All"];
|
||||
var res = ["All Topics"];
|
||||
this.$page.topics.edges.forEach((edge) => res.push(edge.node.title));
|
||||
return res;
|
||||
},
|
||||
@@ -200,8 +197,7 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
blogs() {
|
||||
blogs() {
|
||||
var res = {};
|
||||
var old = this.$page.entries;
|
||||
res.totalCount = old.totalCount;
|
||||
@@ -212,25 +208,27 @@ export default {
|
||||
var node = old.edges[i].node;
|
||||
|
||||
// Now check topic
|
||||
var topics = ["All"];
|
||||
var topics = ["All Topics"];
|
||||
node.tags.forEach((tag) => topics.push(tag.title));
|
||||
|
||||
var nodeDate = new Date(node.datetime);
|
||||
if (!topics.includes(this.selectedTopic)) continue;
|
||||
|
||||
// Check year
|
||||
var years = ["All", String(nodeDate.getFullYear())];
|
||||
var years = ["All Years", String(nodeDate.getFullYear())];
|
||||
|
||||
if (!years.includes(this.selectedYear)) continue;
|
||||
|
||||
// Check Month
|
||||
var months = ["All", this.months[nodeDate.getMonth() + 1]];
|
||||
// Check Month
|
||||
var months = ["All Months", this.months[nodeDate.getMonth() + 1]];
|
||||
if (!months.includes(this.selectedMonth)) continue;
|
||||
res.edges.push({ node: node, id: node.id });
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
|
||||
baseurl() {
|
||||
return "/blog/";
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -32,15 +32,15 @@
|
||||
:currentPage="$page.entries.pageInfo.currentPage"
|
||||
:totalPages="$page.entries.pageInfo.totalPages"
|
||||
:maxVisibleButtons="5"
|
||||
v-if="$page.entries.pageInfo.totalPages > 1"
|
||||
v-if="$page.entries.pageInfo.totalPages > 1 && news.edges.length > 0"
|
||||
/>
|
||||
</div>
|
||||
</Layout>
|
||||
</template>
|
||||
|
||||
<page-query>
|
||||
query{
|
||||
entries: allNews(sortBy: "created", order: DESC) {
|
||||
query($page: Int){
|
||||
entries: allNews(perPage: 10, page: $page, sortBy: "created", order: DESC, filter: {category: { id: {in: ["farming"]}}}) @paginate{
|
||||
totalCount
|
||||
pageInfo {
|
||||
totalPages
|
||||
@@ -55,6 +55,10 @@ query{
|
||||
path
|
||||
}
|
||||
excerpt
|
||||
category{
|
||||
id
|
||||
title
|
||||
}
|
||||
image(width:800)
|
||||
path
|
||||
humanTime : created(format:"DD MMM YYYY")
|
||||
@@ -82,7 +86,7 @@ import Pagination from "~/components/custom/Pagination.vue";
|
||||
export default {
|
||||
data() {
|
||||
const allMonths = [
|
||||
"All",
|
||||
"All Months",
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
@@ -97,14 +101,14 @@ export default {
|
||||
"December",
|
||||
];
|
||||
const currYear = new Date().getFullYear();
|
||||
var years = ["All"];
|
||||
var years = ["All Years"];
|
||||
var r = this.range(2019, currYear);
|
||||
r.forEach((year) => years.push(String(year)));
|
||||
|
||||
return {
|
||||
selectedTopic: "All",
|
||||
selectedYear: "All",
|
||||
selectedMonth: "All",
|
||||
selectedTopic: "All Topics",
|
||||
selectedYear: "All Years",
|
||||
selectedMonth: "All Months",
|
||||
months: allMonths,
|
||||
years: years,
|
||||
listArchive: false,
|
||||
@@ -131,9 +135,9 @@ export default {
|
||||
this.selectedMonth = month;
|
||||
},
|
||||
resetAll() {
|
||||
this.selectedTopic = "All";
|
||||
this.selectedYear = "All";
|
||||
this.selectedMonth = "All";
|
||||
this.selectedTopic = "All Topics";
|
||||
this.selectedYear = "All Years";
|
||||
this.selectedMonth = "All Months";
|
||||
},
|
||||
toggleListArchive() {
|
||||
if (this.listArchive) {
|
||||
@@ -198,13 +202,13 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
topics: function () {
|
||||
var res = ["All"];
|
||||
var res = ["All Topics"];
|
||||
this.$page.topics.edges.forEach((edge) => res.push(edge.node.title));
|
||||
return res;
|
||||
},
|
||||
|
||||
baseurl: function () {
|
||||
return "";
|
||||
return "/news/";
|
||||
},
|
||||
|
||||
news() {
|
||||
@@ -221,26 +225,26 @@ export default {
|
||||
const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
||||
var selected = false;
|
||||
|
||||
if (!this.listArchive && diffDays <= 30) {
|
||||
selected = true;
|
||||
} else if (this.listArchive && diffDays > 30) {
|
||||
selected = true;
|
||||
}
|
||||
// if (!this.listArchive && diffDays <= 180) {
|
||||
// selected = true;
|
||||
// } else if (this.listArchive && diffDays > 180) {
|
||||
// selected = true;
|
||||
// }
|
||||
|
||||
if (!selected) continue;
|
||||
// if (!selected) continue;
|
||||
|
||||
// Now check topic
|
||||
var topics = ["All"];
|
||||
var topics = ["All Topics"];
|
||||
node.tags.forEach((tag) => topics.push(tag.title));
|
||||
|
||||
if (!topics.includes(this.selectedTopic)) continue;
|
||||
|
||||
// Check year
|
||||
var years = ["All", String(nodeDate.getFullYear())];
|
||||
var years = ["All Years", String(nodeDate.getFullYear())];
|
||||
if (!years.includes(this.selectedYear)) continue;
|
||||
|
||||
// Check Month
|
||||
var months = ["All", this.months[nodeDate.getMonth() + 1]];
|
||||
var months = ["All Months", this.months[nodeDate.getMonth() + 1]];
|
||||
|
||||
if (!months.includes(this.selectedMonth)) continue;
|
||||
res.edges.push({ node: node, id: node.id });
|
||||
|
||||
Reference in New Issue
Block a user