Added infinite scroll and pagination
This commit is contained in:
parent
b1f096102b
commit
d36bd76d52
5 changed files with 57 additions and 48 deletions
|
|
@ -1,31 +1,12 @@
|
||||||
<!-- Default number of columns is two. If 3 is defined, then third column is added-->
|
<!-- Default number of columns is two. If 3 is defined, then third column is added-->
|
||||||
<% columns = theme.column; %> <!-- Number of columns -->
|
<div id="masonry">
|
||||||
<div class="posts-container">
|
<% page.posts.forEach(function(post) { %>
|
||||||
<div class="column column-0">
|
|
||||||
<% item.forEach(function(post, index) { %>
|
|
||||||
<% if (index % columns === 0) { %>
|
|
||||||
<%- include('post_feed', { post: post }) %>
|
<%- include('post_feed', { post: post }) %>
|
||||||
<% } %>
|
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</div>
|
</div>
|
||||||
<div class="column column-1">
|
|
||||||
<% item.forEach(function(post, index) { %>
|
<div class="pagination">
|
||||||
<% if (index % columns === 1) { %>
|
<% if (page.next) { %>
|
||||||
<%- include('post_feed', { post: post }) %>
|
<a href="<%- url_for(page.next_link) %>"></a>
|
||||||
<% } %>
|
|
||||||
<% }); %>
|
|
||||||
</div>
|
|
||||||
<!-- Condition for column number 3 -->
|
|
||||||
<% if (columns === 3) { %>
|
|
||||||
<div class="column column-2">
|
|
||||||
<% item.forEach(function(post, index) { %>
|
|
||||||
<% if (index % columns === 2) { %>
|
|
||||||
<%- include('post_feed', { post: post }) %>
|
|
||||||
<% } %>
|
|
||||||
<% }); %>
|
|
||||||
</div>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<div id="loader" style="text-align: center; display: none;">
|
|
||||||
<p>Loading more posts...</p>
|
|
||||||
</div>
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<!-- This is the template for the post. It is used to display the posts in the feeds. -->
|
<!-- This is the template for the post. It is used to display the posts in the feeds. -->
|
||||||
<div class="post">
|
<div class="post post-feed">
|
||||||
<% if(post.photos) { %>
|
<% if(post.photos) { %>
|
||||||
<div class="cover">
|
<div class="cover">
|
||||||
<a href='<%= url_for(post.path) %>'>
|
<a href='<%= url_for(post.path) %>'>
|
||||||
<img class="gallery" src="<%- config.root %>thumbnails/<%- (theme.column == 2 ? 'medium' : 'small') + '-' + post.photos[0].replace(/^images\//, '') %>" alt="<%- post.title || 'Untitled' %>">
|
<img class="gallery" src="<%- config.root %>thumbnails/small-<%- post.photos[0].replace(/^images\//, '') %>" alt="<%- post.title || 'Untitled' %>">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,28 @@
|
||||||
<script src="<%= url_for(theme.fontawesome) %>" crossorigin="anonymous"></script>
|
<script src="<%= url_for(theme.fontawesome) %>" crossorigin="anonymous"></script>
|
||||||
<script src="<%- config.root %>js/infinite-scroll.js"></script>
|
<script src="<%- config.root %>js/infinite-scroll.js"></script>
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/infinite-scroll@4/dist/infinite-scroll.pkgd.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const grid = document.querySelector('#masonry');
|
||||||
|
const msn = new Masonry(grid, { itemSelector: '.post', percentPosition: true, gutter: 16 });
|
||||||
|
|
||||||
|
imagesLoaded(grid, () => msn.layout());
|
||||||
|
|
||||||
|
const infScroll = new InfiniteScroll(grid, {
|
||||||
|
path: '.pagination a',
|
||||||
|
append: '.post',
|
||||||
|
outlayer: msn,
|
||||||
|
history: false
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<title><%= config.title %></title>
|
<title><%= config.title %></title>
|
||||||
<link rel="stylesheet" href="<%= url_for('/css/style.css') %>">
|
<link rel="stylesheet" href="<%= url_for('/css/style.css') %>">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,8 @@ hexo.extend.filter.register('after_init', async function() {
|
||||||
|
|
||||||
// Thumbnail sizes
|
// Thumbnail sizes
|
||||||
const sizes = [
|
const sizes = [
|
||||||
{ name: 'small', width: 333 }, // Three-column layout
|
{ name: 'small', width: 512 }, // Three-column layout
|
||||||
{ name: 'medium', width: 666 }, // Two-column layout
|
{ name: 'large', width: 1024 } // Normal post
|
||||||
{ name: 'large', width: 1000 } // Normal post
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const getAllFilesInclSubfolders = (dir) => {
|
const getAllFilesInclSubfolders = (dir) => {
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,18 @@ nav a {
|
||||||
color: #dcdcdf !important;
|
color: #dcdcdf !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post {
|
||||||
|
padding: 1em;
|
||||||
|
background-color: #dcdcdf;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-feed {
|
||||||
|
width: 32%;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.sidebar-content {
|
.sidebar-content {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
@ -195,6 +207,10 @@ nav a {
|
||||||
.content {
|
.content {
|
||||||
width: calc(100% - 1em);
|
width: calc(100% - 1em);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-feed {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Medium devices (tablets, 576px-768px) */
|
/* Medium devices (tablets, 576px-768px) */
|
||||||
|
|
@ -224,6 +240,10 @@ nav a {
|
||||||
body{
|
body{
|
||||||
width: 769px;
|
width: 769px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-feed {
|
||||||
|
width: 48%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 993px) and (max-width: 1199px) {
|
@media (min-width: 993px) and (max-width: 1199px) {
|
||||||
|
|
@ -253,12 +273,6 @@ img:hover {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Post */
|
/* Post */
|
||||||
.posts-container {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.column {
|
.column {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
@ -266,13 +280,6 @@ img:hover {
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post {
|
|
||||||
padding: 1em;
|
|
||||||
background-color: #dcdcdf;
|
|
||||||
border-radius: 10px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-header {
|
.post-header {
|
||||||
line-height: 100%;
|
line-height: 100%;
|
||||||
color:#343a40;
|
color:#343a40;
|
||||||
|
|
@ -283,7 +290,7 @@ img:hover {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Poskt - Top section */
|
/* Post - Top section */
|
||||||
.article {
|
.article {
|
||||||
font-size: 35px !important;
|
font-size: 35px !important;
|
||||||
line-height: 40px !important;
|
line-height: 40px !important;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue