From 00dadcd46976cab8927d8f9a5318f93c8036e9c8 Mon Sep 17 00:00:00 2001 From: Kevin Van Lierde Date: Sat, 11 Dec 2021 20:46:08 +0100 Subject: [PATCH] [skip changelog] Formatted source w. Prettier, updated .release-it.json config --- .release-it.json | 5 +- CHANGELOG.md | 35 +++++++++----- README.md | 4 +- lib/index.js | 42 ++++++++-------- package.json | 3 +- test/index.js | 122 +++++++++++++++++++++++------------------------ 6 files changed, 113 insertions(+), 98 deletions(-) diff --git a/.release-it.json b/.release-it.json index 6a50091..e528caf 100644 --- a/.release-it.json +++ b/.release-it.json @@ -1,7 +1,8 @@ { "hooks": { "before:init": ["npm run lint", "npm test"], - "after:bump": "auto-changelog --sort-commits date -p -u --starting-version v1.4.1", + "after:bump": "auto-changelog --sort-commits date -p --starting-date 2021-12-01 --commit-limit false --ignore-commit-pattern '(skip changelog|Release)'", + "after:npm:bump": "npm pack", "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." }, "git": { @@ -9,7 +10,7 @@ "commitArgs": ["-S"], "tagAnnotation": "Release ${version}", "tagArgs": ["-s"], - "changelog": "git log --no-merges --pretty=format:\"* %s (%h)\" ${from}...${to} " + "changelog": "auto-changelog --sort-commits date -u --starting-date 2021-12-01 --commit-limit false --ignore-commit-pattern '(skip changelog|Release)'" }, "npm": { "publish": false diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bacf42..c5aa535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,18 @@ +### Changelog + +All notable changes to this project will be documented in this file. Dates are displayed in UTC. + +Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). + +#### [Unreleased](https://github.com/metalsmith/excerpts/compare/v1.4.1...HEAD) + +- Added build CI Badge [`9c1a075`](https://github.com/metalsmith/excerpts/commit/9c1a075d41c07a00e26aca47b6e70116eb24f268) +- Aligned dotfiles & default repository files with core metalsmith plugins [`fa74f1d`](https://github.com/metalsmith/excerpts/commit/fa74f1d872b072510422628fcac074c4695ab77e) +- Added nyc, coveralls, prettier, ESlint & replaced xo with mocha. Added NPM CI/CD scripts [`c6d7caf`](https://github.com/metalsmith/excerpts/commit/c6d7caf34f4b767c4832922ec7ac274d0e7aa171) +- Aligned README structure & package.json, updated cheerio, debug. [`337f2a7`](https://github.com/metalsmith/excerpts/commit/337f2a7835aef0331f6f21483a8eb7286981d30d) + + ## [1.4.1][] - 2020-11-04 - Fixed CI issue for NodeJS v10 @@ -58,14 +72,13 @@ --- -[unreleased]: https://github.com/segmentio/metalsmith-excerpts/compare/v1.4.1...HEAD -[1.4.1]: https://github.com/segmentio/metalsmith-excerpts/compare/v1.4.0...v1.4.1 -[1.4.0]: https://github.com/segmentio/metalsmith-excerpts/compare/v1.3.0...v1.4.0 -[1.3.0]: https://github.com/segmentio/metalsmith-excerpts/compare/1.2.0...v1.3.0 -[1.2.0]: https://github.com/segmentio/metalsmith-excerpts/compare/1.0.0...1.2.0 -[1.0.0]: https://github.com/segmentio/metalsmith-excerpts/compare/0.3.1...1.0.0 -[0.3.1]: https://github.com/segmentio/metalsmith-excerpts/compare/0.3.0...0.3.1 -[0.3.0]: https://github.com/segmentio/metalsmith-excerpts/compare/0.2.0...0.3.0 -[0.2.0]: https://github.com/segmentio/metalsmith-excerpts/compare/0.1.1...0.2.0 -[0.1.1]: https://github.com/segmentio/metalsmith-excerpts/compare/0.1.0...0.1.1 -[0.1.0]: https://github.com/segmentio/metalsmith-excerpts/compare/0.0.1...0.1.0 +[1.4.1]: https://github.com/metalsmith/excerpts/compare/v1.4.0...v1.4.1 +[1.4.0]: https://github.com/metalsmith/excerpts/compare/v1.3.0...v1.4.0 +[1.3.0]: https://github.com/metalsmith/excerpts/compare/1.2.0...v1.3.0 +[1.2.0]: https://github.com/metalsmith/excerpts/compare/1.0.0...1.2.0 +[1.0.0]: https://github.com/metalsmith/excerpts/compare/0.3.1...1.0.0 +[0.3.1]: https://github.com/metalsmith/excerpts/compare/0.3.0...0.3.1 +[0.3.0]: https://github.com/metalsmith/excerpts/compare/0.2.0...0.3.0 +[0.2.0]: https://github.com/metalsmith/excerpts/compare/0.1.1...0.2.0 +[0.1.1]: https://github.com/metalsmith/excerpts/compare/0.1.0...0.1.1 +[0.1.0]: https://github.com/metalsmith/excerpts/compare/0.0.1...0.1.0 diff --git a/README.md b/README.md index ab62b92..8260d5f 100644 --- a/README.md +++ b/README.md @@ -76,5 +76,5 @@ Add the `@metalsmith/excerpts` key to your `metalsmith.json` plugins key: [metalsmith-url]: https://metalsmith.io [codecov-badge]: https://img.shields.io/coveralls/github/metalsmith/excerpts [codecov-url]: https://coveralls.io/github/metalsmith/excerpts -[license-badge]: LICENSE -[license-url]: https://img.shields.io/github/license/metalsmith/excerpts +[license-badge]: https://img.shields.io/github/license/metalsmith/excerpts +[license-url]: LICENSE diff --git a/lib/index.js b/lib/index.js index 6b4ee78..9cf227a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ -const extname = require('path').extname; -const debug = require('debug')('metalsmith-excerpts'); -const cheerio = require('cheerio'); +const extname = require('path').extname +const debug = require('debug')('metalsmith-excerpts') +const cheerio = require('cheerio') /** * Check if a `file` is HTML. @@ -8,45 +8,45 @@ const cheerio = require('cheerio'); * @param {String} file * @return {Boolean} */ -const html = file => /\.html?/.test(extname(file)); +const html = (file) => /\.html?/.test(extname(file)) /** * A Metalsmith plugin to extract an excerpt from HTML files. * * @return {Function} */ -const plugin = options => (files, metalsmith, done) => { - options = options || {}; - setImmediate(done); - Object.keys(files).forEach(file => { - debug('checking file: %s', file); +const plugin = (options) => (files, metalsmith, done) => { + options = options || {} + setImmediate(done) + Object.keys(files).forEach((file) => { + debug('checking file: %s', file) if (!html(file)) { - return; + return } - const data = files[file]; + const data = files[file] if (typeof data.excerpt === 'string' && data.excerpt.length > 0) { - return; // Don't mutate data + return // Don't mutate data } - debug('storing excerpt: %s', file); - const $ = cheerio.load(data.contents.toString()); - let p = $('p').first(); + debug('storing excerpt: %s', file) + const $ = cheerio.load(data.contents.toString()) + let p = $('p').first() while (p.children('img').length > 0) { - p = p.next(); + p = p.next() } if (options.multipleFormats) { data.excerpt = { html: $.html(p).trim(), text: $.text(p).trim() - }; + } } else { - data.excerpt = $.html(p).trim(); + data.excerpt = $.html(p).trim() } - }); -}; + }) +} // Expose `plugin` -module.exports = plugin; +module.exports = plugin diff --git a/package.json b/package.json index 5001fb6..f9a5637 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,13 @@ "lib/*" ], "scripts": { + "changelog": "auto-changelog -u --sort-commits date --starting-date 2021-12-01 --commit-limit false --ignore-commit-pattern '(skip changelog|Release)'", "coverage": "nyc report --reporter=text-lcov > ./coverage.info", "coveralls": "npm run coverage && cat ./coverage.info | coveralls", "format": "prettier --write .", "lint": "eslint .", "publish": "npm publish --access public", - "release": "npm pack && release-it .", + "release": "release-it .", "test": "nyc mocha" }, "dependencies": { diff --git a/test/index.js b/test/index.js index ab49ce9..95e012c 100644 --- a/test/index.js +++ b/test/index.js @@ -1,131 +1,131 @@ -const assert = require('assert'); -const { it } = require('mocha'); -const markdown = require('@metalsmith/markdown'); -const metalsmith = require('metalsmith'); -const excerpt = require('..'); +const assert = require('assert') +const { it } = require('mocha') +const markdown = require('@metalsmith/markdown') +const metalsmith = require('metalsmith') +const excerpt = require('..') -it('should convert excerpt files', done => { +it('should convert excerpt files', (done) => { metalsmith('test/fixtures/basic') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

excerpt

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

excerpt

', files['index.html'].excerpt) + done() + }) +}) -it('should convert excerpt files that have leading whitespace', done => { +it('should convert excerpt files that have leading whitespace', (done) => { metalsmith('test/fixtures/whitespace') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

excerpt

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

excerpt

', files['index.html'].excerpt) + done() + }) +}) -it('should convert excerpt files that only have one paragraph', done => { +it('should convert excerpt files that only have one paragraph', (done) => { metalsmith('test/fixtures/one-paragraph') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

excerpt

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

excerpt

', files['index.html'].excerpt) + done() + }) +}) -it('should convert excerpt files with reference-style links', done => { +it('should convert excerpt files with reference-style links', (done) => { metalsmith('test/fixtures/reference-links') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

This is a link.

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

This is a link.

', files['index.html'].excerpt) + done() + }) +}) -it('should skip excerpts with leading whitespace', done => { +it('should skip excerpts with leading whitespace', (done) => { metalsmith('test/fixtures/indented-paragraph') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

This is the excerpt.

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

This is the excerpt.

', files['index.html'].excerpt) + done() + }) +}) -it('should convert excerpts with multiple formats', done => { +it('should convert excerpts with multiple formats', (done) => { metalsmith('test/fixtures/reference-links') .use(markdown()) - .use(excerpt({multipleFormats: true})) + .use(excerpt({ multipleFormats: true })) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

This is a link.

', files['index.html'].excerpt.html); - assert.equal('This is a link.', files['index.html'].excerpt.text); - done(); - }); -}); + assert.equal('

This is a link.

', files['index.html'].excerpt.html) + assert.equal('This is a link.', files['index.html'].excerpt.text) + done() + }) +}) -it('should skip excerpts with images', done => { +it('should skip excerpts with images', (done) => { metalsmith('test/fixtures/first-paragraph-image') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('

This is the excerpt.

', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('

This is the excerpt.

', files['index.html'].excerpt) + done() + }) +}) -it('should skip excerpts that are not html', done => { +it('should skip excerpts that are not html', (done) => { metalsmith('test/fixtures/not-html') .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.ok('template: layout', files['file.yaml'].contents.toString().trim()); - done(); - }); -}); + assert.ok('template: layout', files['file.yaml'].contents.toString().trim()) + done() + }) +}) -it('should not mutate an existing excerpts', done => { +it('should not mutate an existing excerpts', (done) => { metalsmith('test/fixtures/no-mutation') .use(markdown()) .use(excerpt()) .build((err, files) => { if (err) { - return err; + return err } - assert.equal('beans', files['index.html'].excerpt); - done(); - }); -}); + assert.equal('beans', files['index.html'].excerpt) + done() + }) +})