diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6dc94c7..f22e260 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -6,11 +6,11 @@ jobs: linter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js 14.x - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - name: Use Node.js 18 + uses: actions/setup-node@v4 with: - node-version: '14.x' + node-version: "18" - name: Install Dependencies run: npm install - name: Lint diff --git a/.github/workflows/tester.yml b/.github/workflows/tester.yml index 55f32f4..1ad5b56 100644 --- a/.github/workflows/tester.yml +++ b/.github/workflows/tester.yml @@ -8,12 +8,12 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: ['14.x', '16.x', '18.x'] + node-version: [18, 20] fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install Dependencies @@ -27,11 +27,11 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: ['14.x'] + node-version: [18] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install Dependencies @@ -41,6 +41,6 @@ jobs: env: CI: true - name: Coveralls - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.github_token }} diff --git a/README.md b/README.md index c09e0d6..6e31363 100644 --- a/README.md +++ b/README.md @@ -10,32 +10,32 @@ It generates an archive of posts on your homepage, according to the `index` or ` ## Installation -``` bash -$ npm install hexo-generator-index --save +```bash +npm install hexo-generator-index --save ``` ## Options -Add or modify the following section to your root _config.yml file +Add or modify the following section to your root `_config.yml` file. -``` yaml +```yaml index_generator: - path: '' + path: "" per_page: 10 order_by: -date pagination_dir: page ``` -- **path**: Root path for your blog's index page. - - default: "" +- **path**: Root path for your blog's index page. + - default: `""` - **per_page**: Posts displayed per page. - default: [`config.per_page`](https://hexo.io/docs/configuration.html#Pagination) as specified in the official Hexo docs (if present), otherwise `10` - - `0` disables pagination -- **order_by**: Posts order. - - default: date descending + - `0` disables pagination. +- **order_by**: Posts order. + - default: `-date` (date descending) - **pagination_dir**: URL format. - - default: 'page' - - `awesome-page` makes the URL ends with 'awesome-page/' for second page and beyond. + - default: `page` + - e.g. set `awesome-page` makes the URL ends with `awesome-page/` for second page and beyond. ## Usage diff --git a/package.json b/package.json index 07ec387..fd4dfd2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lib/" ], "engines": { - "node": ">=14" + "node": ">=18" }, "repository": "hexojs/hexo-generator-index", "homepage": "https://hexo.io/", @@ -29,7 +29,7 @@ "author": "Tommy Chen (https://zespia.tw)", "license": "MIT", "devDependencies": { - "c8": "^9.0.0", + "c8": "^10.1.2", "chai": "^4.3.6", "eslint": "^8.25.0", "eslint-config-hexo": "^5.0.0", diff --git a/test/index.js b/test/index.js index e029211..a07c515 100644 --- a/test/index.js +++ b/test/index.js @@ -11,10 +11,14 @@ describe('Index generator', () => { locals; // Default config - hexo.config.index_generator = { + const default_index_generator = Object.freeze({ per_page: 10, order_by: '-date' - }; + }); + + beforeEach(() => { + hexo.config.index_generator = {...default_index_generator}; + }); before(() => hexo.init().then(() => Post.insert([ {source: 'foo', slug: 'foo', date: 1e8, order: 0}, @@ -57,8 +61,6 @@ describe('Index generator', () => { result[1].data.next_link.should.eql(''); result[1].data.__index.should.be.true; - // Restore config - hexo.config.index_generator.per_page = 10; }); it('pagination disabled', () => { @@ -81,8 +83,6 @@ describe('Index generator', () => { result[0].data.next_link.should.eql(''); result[0].data.__index.should.be.true; - // Restore config - hexo.config.index_generator.per_page = 10; }); describe('order', () => { @@ -109,8 +109,6 @@ describe('Index generator', () => { result[0].data.posts.eq(1).source.should.eql('baz'); result[0].data.posts.eq(2).source.should.eql('bar'); - // Restore config - delete hexo.config.index_generator.order_by; }); it('custom order - invalid order key', () => { @@ -122,8 +120,6 @@ describe('Index generator', () => { result[0].data.posts.eq(1).source.should.eql('bar'); result[0].data.posts.eq(2).source.should.eql('baz'); - // Restore config - delete hexo.config.index_generator.order_by; }); }); @@ -137,9 +133,6 @@ describe('Index generator', () => { result[1].path.should.eql('yo/2/'); result[2].path.should.eql('yo/3/'); - // Restore config - hexo.config.index_generator.per_page = 10; - hexo.config.pagination_dir = 'page'; }); it('custom pagination_dir - plugin setting', () => { @@ -156,5 +149,4 @@ describe('Index generator', () => { hexo.config.index_generator.per_page = 10; hexo.config.index_generator.pagination_dir = 'page'; }); - });