hexojs / hexo-generator-index Goto Github PK
View Code? Open in Web Editor NEWIndex generator plugin for Hexo.
License: MIT License
Index generator plugin for Hexo.
License: MIT License
index_generator:
path: ''
per_page: 10
order_by: -date
exclude: true //set true if you wanna exclude
exclude_list:
- novel //set categories name you wanna exclude
- gossip //set categories name you wanna exclude
'use strict';
const pagination = require('hexo-pagination');
const { sort } = require('timsort');
module.exports = function(locals) {
const config = this.config;
const posts = locals.posts.sort(config.index_generator.order_by);
const temp_posts = [];
sort(posts.data, (a, b) => (b.sticky || 0) - (a.sticky || 0));
const paginationDir = config.pagination_dir || 'page';
const path = config.index_generator.path || '';
if(config.index_generator.exclude){
posts.forEach(element => {
var mark=true;
element.categories.forEach(function(categories){
config.index_generator.exclude_list.forEach(function(category){
if(categories.name == category){
mark=false;
}
});
});
if(mark){
temp_posts.push(element);
}
});
}
return pagination(path, config.index_generator.exclude ? temp_posts : posts, {
perPage: config.index_generator.per_page,
layout: ['index', 'archive'],
format: paginationDir + '/%d/',
data: {
__index: true
}
});
};
hexo clean
, but the issue persists.Here is an example of Front Matter
sticky: 99
title: A simple test
date: 2022-07-24
tags:
- es
categories: es
updated: 2022-08-17
Articles with 'sticky' set are displayed at the top.
npm run server
.No response
- System: Windows 11 (21H2)
- HEXO: 6.3.0
- hexo-generator-index: 3.0.0
- NODE: v20.9.0
- NPM: 10.1.0
No response
for some reasons ,I need to hide some post,I do the procedure as follow:
then it show error!
it divide posts before redering which make the number of post in some page fewer than other pages.
you can visite my blog http://chenfengkg.cn.
my slution is to make redering post be first ,then divide page.so this can slove this problem.but I don't know how to change your code ,can you help me .or do you have any other solution? Thanks in advance.
I spent so many hours trying to find out how to have a blog
section (instead of using index as the blog page) together with a regular static index page in my hexo generated website.
I then found out through github issues that I could add a:
index_generator:
path: '/blog'
section to my config file to make it work (which it did!). However this should really be in the documentation or even the default _config.yml
since it must be a pretty normal use case? Can we add it? Thank you for a great product!
I want to add some words or HTML tags or markdowns into index, and keep the generated index rendered to, all solution I find can only create a custom index and remove this plugin, but I don't want to remove this plugin's index.
Is there anyway to keep both of those?
The sorting is hardcoded as
var posts = locals.posts.sort('-date');
Can it be made into hexo.config
?
Is it possible to add an option, e.g. hidden: true
, into front matter, and to remove this post from the index page?
I noticed that the order option has been made into _config.yml
, but I can't find more order options from hexo's official document.
# order_by: Posts order. (Order by date descending by default)
order_by: -date
Does it seem to be less humanity for only ordering by created date?
Due to my poor JS knowledge, if I miss more order options, can u update the hexo doc plz?
As the 'index' layout is used not only for index generation but also as fallback layout, it would be nice to be able to specify a different layout for the blog.
My use case is that I have a site that has a static page as index /and many other static pages...) and a blog in a subfolder. This basically works, but i loose the layout fallback the way it is right now.
The word 'index' is used very often with different meanings. What does this plugin actually do? Does it generates complete pages or strings, or what, and based on what? And how to access the result?
do not affect article order
When I run npm run test-cov
, then I get some errors
[zjf@aliyun hexo-generator-index]$ npm run test-cov
> [email protected] test-cov /home/zjf/git/hexo-generator-index
> istanbul cover --print both _mocha -- test/index.js
(node:3175) [DEP0061] DeprecationWarning: fs.SyncWriteStream is deprecated.
Index generator
1) "before all" hook
0 passing (26ms)
1 failing
1) Index generator "before all" hook:
TypeError: Cannot read property 'call' of undefined
at Model._Document.Document.<anonymous> (node_modules/[email protected]@hexo/lib/models/post.js:60:30)
at Model._Document.Document.permalink (node_modules/[email protected]@warehouse/lib/types/virtual.js:70:22)
at Model._Document.Document.Document.toObject (node_modules/[email protected]@warehouse/lib/document.js:79:42)
at Database._Model.Model.Model._insertOne (node_modules/[email protected]@warehouse/lib/model.js:189:21)
at node_modules/[email protected]@warehouse/lib/model.js:214:17
at tryCatcher (node_modules/[email protected]@bluebird/js/release/util.js:16:23)
at node_modules/[email protected]@bluebird/js/release/using.js:185:26
at tryCatcher (node_modules/[email protected]@bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (node_modules/[email protected]@bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (node_modules/[email protected]@bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (node_modules/[email protected]@bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (node_modules/[email protected]@bluebird/js/release/promise.js:693:18)
at Promise._fulfill (node_modules/[email protected]@bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (node_modules/[email protected]@bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (node_modules/[email protected]@bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (node_modules/[email protected]@bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (node_modules/[email protected]@bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (node_modules/[email protected]@bluebird/js/release/promise.js:693:18)
at Async._drainQueue (node_modules/[email protected]@bluebird/js/release/async.js:133:16)
at Async._drainQueues (node_modules/[email protected]@bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (node_modules/[email protected]@bluebird/js/release/async.js:17:14)
=============================================================================
Writing coverage object [/home/zjf/git/hexo-generator-index/coverage/coverage.json]
Writing coverage reports at [/home/zjf/git/hexo-generator-index/coverage]
=============================================================================
---------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
---------------|----------|----------|----------|----------|----------------|
lib/ | 28.57 | 0 | 0 | 28.57 | |
generator.js | 28.57 | 0 | 0 | 28.57 | 6,7,8,9,11 |
---------------|----------|----------|----------|----------|----------------|
All files | 28.57 | 0 | 0 | 28.57 | |
---------------|----------|----------|----------|----------|----------------|
=============================== Coverage summary ===============================
Statements : 28.57% ( 2/7 )
Branches : 0% ( 0/4 )
Functions : 0% ( 0/1 )
Lines : 28.57% ( 2/7 )
================================================================================
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test-cov: `istanbul cover --print both _mocha -- test/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test-cov script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/zjf/.npm/_logs/2017-06-25T17_02_28_120Z-debug.log
I don't know how to solve it, can anyone help me?
I've got following configuration in my _config.yml
url: http://website.com/child
root: /child/index_generator:
per_page: 10
And the link to first page will always take me to http://website.com , instead of https://website.com/child
This problem cannot be reproduced on Hexo server, because it always redirect http://localhost:4000/ to http://localhost:4000/child
it seemed in:
hexo-pagination/lib/pagination.js
Some special handling is needed for the first page. But I cannot find where since I'm not familiar with Hexo.
hexo-generator-index/README.md
Lines 21 to 27 in f8ef61c
according to README, pagination_dir
can be set by index_generator.pagination_dir
.
But from the code, index_generator.pagination_dir
is invalid.
hexo-generator-index/lib/generator.js
Line 11 in f8ef61c
Code and documentation should match, avoid misleading users.
No response
No response
No response
The date time of the article is set, and the sorting does not take effect
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.