Skip to content

Commit

Permalink
[skip changelog] Formatted source w. Prettier, updated .release-it.js…
Browse files Browse the repository at this point in the history
…on config
  • Loading branch information
webketje committed Dec 11, 2021
1 parent 74f99c0 commit 00dadcd
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 98 deletions.
5 changes: 3 additions & 2 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"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": {
"commitMessage": "Release ${version}",
"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
Expand Down
35 changes: 24 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

<!-- auto-changelog-above -->

## [1.4.1][] - 2020-11-04

- Fixed CI issue for NodeJS v10
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 21 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
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.
*
* @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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
122 changes: 61 additions & 61 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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('<p>excerpt</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>excerpt</p>', 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('<p>excerpt</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>excerpt</p>', 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('<p>excerpt</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>excerpt</p>', 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('<p>This is <a href="http://example.com">a link</a>.</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>This is <a href="http://example.com">a link</a>.</p>', 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('<p>This is the excerpt.</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>This is the excerpt.</p>', 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('<p>This is <a href="http://example.com">a link</a>.</p>', files['index.html'].excerpt.html);
assert.equal('This is a link.', files['index.html'].excerpt.text);
done();
});
});
assert.equal('<p>This is <a href="http://example.com">a link</a>.</p>', 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('<p>This is the excerpt.</p>', files['index.html'].excerpt);
done();
});
});
assert.equal('<p>This is the excerpt.</p>', 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()
})
})

0 comments on commit 00dadcd

Please sign in to comment.