first commit
This commit is contained in:
7
node_modules/hexo-generator-archive/LICENSE
generated
vendored
Normal file
7
node_modules/hexo-generator-archive/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2014 Tommy Chen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
38
node_modules/hexo-generator-archive/README.md
generated
vendored
Normal file
38
node_modules/hexo-generator-archive/README.md
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
# hexo-generator-archive
|
||||
|
||||
[](https://github.com/hexojs/hexo-generator-archive/actions?query=workflow%3ATester)
|
||||
[](https://www.npmjs.com/package/hexo-generator-archive)
|
||||
[](https://coveralls.io/r/hexojs/hexo-generator-archive?branch=master)
|
||||
|
||||
Archive generator for [Hexo].
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
$ npm install hexo-generator-archive --save
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
``` yaml
|
||||
archive_generator:
|
||||
enabled: true
|
||||
per_page: 10
|
||||
yearly: true
|
||||
monthly: true
|
||||
daily: false
|
||||
order_by: -date
|
||||
```
|
||||
|
||||
- **enabled**: The default value is **true**, set to **false** if you do not want to enable the plugin
|
||||
- **per_page**: Posts displayed per page. (**0** = disable pagination)
|
||||
- **yearly**: Generate yearly archive.
|
||||
- **monthly**: Generate monthly archive.
|
||||
- **daily**: Generate daily archive.
|
||||
- **order_by**: Posts order. (Order by date descending by default)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[Hexo]: https://hexo.io/
|
||||
25
node_modules/hexo-generator-archive/index.js
generated
vendored
Normal file
25
node_modules/hexo-generator-archive/index.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/* global hexo */
|
||||
|
||||
'use strict';
|
||||
|
||||
if (!(hexo.config.archive_generator && hexo.config.archive_generator.enabled === false)) {
|
||||
// when archive disabled pagination, per_page should be 0.
|
||||
let per_page;
|
||||
|
||||
if (hexo.config.archive === 1) {
|
||||
per_page = 0;
|
||||
} else if (typeof hexo.config.per_page === 'undefined') {
|
||||
per_page = 10;
|
||||
} else {
|
||||
per_page = hexo.config.per_page;
|
||||
}
|
||||
|
||||
hexo.config.archive_generator = Object.assign({
|
||||
per_page,
|
||||
yearly: true,
|
||||
monthly: true,
|
||||
daily: false
|
||||
}, hexo.config.archive_generator);
|
||||
|
||||
hexo.extend.generator.register('archive', require('./lib/generator'));
|
||||
}
|
||||
118
node_modules/hexo-generator-archive/lib/generator.js
generated
vendored
Normal file
118
node_modules/hexo-generator-archive/lib/generator.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
const pagination = require('hexo-pagination');
|
||||
|
||||
const fmtNum = num => num.toString().padStart(2, '0');
|
||||
|
||||
module.exports = function(locals) {
|
||||
const { config } = this;
|
||||
|
||||
let archiveDir = config.archive_dir;
|
||||
const paginationDir = config.pagination_dir || 'page';
|
||||
const allPosts = locals.posts.sort(config.archive_generator.order_by || '-date');
|
||||
const perPage = config.archive_generator.per_page;
|
||||
const result = [];
|
||||
|
||||
if (!allPosts.length) return;
|
||||
|
||||
if (archiveDir[archiveDir.length - 1] !== '/') archiveDir += '/';
|
||||
|
||||
function generate(path, posts, options = {}) {
|
||||
options.archive = true;
|
||||
|
||||
result.push(...pagination(path, posts, {
|
||||
perPage,
|
||||
layout: ['archive', 'index'],
|
||||
format: paginationDir + '/%d/',
|
||||
data: options
|
||||
}));
|
||||
}
|
||||
|
||||
generate(archiveDir, allPosts);
|
||||
|
||||
if (!config.archive_generator.yearly) return result;
|
||||
|
||||
const posts = {};
|
||||
|
||||
// Organize posts by date
|
||||
allPosts.forEach(post => {
|
||||
const date = post.date;
|
||||
const year = date.year();
|
||||
const month = date.month() + 1; // month is started from 0
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(posts, year)) {
|
||||
// 13 arrays. The first array is for posts in this year
|
||||
// and the other arrays is for posts in this month
|
||||
posts[year] = [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
posts[year][0].push(post);
|
||||
posts[year][month].push(post);
|
||||
// Daily
|
||||
if (config.archive_generator.daily) {
|
||||
const day = date.date();
|
||||
if (!Object.prototype.hasOwnProperty.call(posts[year][month], 'day')) {
|
||||
posts[year][month].day = {};
|
||||
}
|
||||
|
||||
(posts[year][month].day[day] || (posts[year][month].day[day] = [])).push(post);
|
||||
}
|
||||
});
|
||||
|
||||
const { Query } = this.model('Post');
|
||||
const years = Object.keys(posts);
|
||||
let year, data, month, monthData, url;
|
||||
|
||||
// Yearly
|
||||
for (let i = 0, len = years.length; i < len; i++) {
|
||||
year = +years[i];
|
||||
data = posts[year];
|
||||
url = archiveDir + year + '/';
|
||||
if (!data[0].length) continue;
|
||||
|
||||
generate(url, new Query(data[0]), { year });
|
||||
|
||||
if (!config.archive_generator.monthly && !config.archive_generator.daily) continue;
|
||||
|
||||
// Monthly
|
||||
for (month = 1; month <= 12; month++) {
|
||||
monthData = data[month];
|
||||
if (!monthData.length) continue;
|
||||
if (config.archive_generator.monthly) {
|
||||
generate(url + fmtNum(month) + '/', new Query(monthData), {
|
||||
year,
|
||||
month
|
||||
});
|
||||
}
|
||||
|
||||
if (!config.archive_generator.daily) continue;
|
||||
|
||||
// Daily
|
||||
for (let day = 1; day <= 31; day++) {
|
||||
const dayData = monthData.day[day];
|
||||
if (!dayData || !dayData.length) continue;
|
||||
generate(url + fmtNum(month) + '/' + fmtNum(day) + '/', new Query(dayData), {
|
||||
year,
|
||||
month,
|
||||
day
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
41
node_modules/hexo-generator-archive/package.json
generated
vendored
Normal file
41
node_modules/hexo-generator-archive/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "hexo-generator-archive",
|
||||
"version": "2.0.0",
|
||||
"description": "Archive generator for Hexo.",
|
||||
"main": "index",
|
||||
"scripts": {
|
||||
"eslint": "eslint .",
|
||||
"test": "mocha test/index.js",
|
||||
"test-cov": "c8 --reporter=lcovonly npm run test"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib/"
|
||||
],
|
||||
"repository": "hexojs/hexo-generator-archive",
|
||||
"homepage": "https://hexo.io/",
|
||||
"keywords": [
|
||||
"hexo",
|
||||
"generator",
|
||||
"archive"
|
||||
],
|
||||
"author": "Tommy Chen <tommy351@gmail.com> (https://zespia.tw)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.25.0",
|
||||
"eslint-config-hexo": "^5.0.0",
|
||||
"hexo": "^6.3.0",
|
||||
"mocha": "^10.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"hexo-pagination": "3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user