├── .editorconfig ├── .eslintrc.yml ├── .gitattributes ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc.yml ├── .release-it.json ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── lib └── index.js ├── package-lock.json ├── package.json └── test ├── fixtures ├── basic │ ├── expected │ │ └── index.md │ └── src │ │ └── index.md ├── first-paragraph-image │ └── src │ │ └── index.md ├── indented-paragraph │ └── src │ │ └── index.md ├── no-mutation │ └── src │ │ └── index.md ├── not-html │ ├── expected │ │ └── file.yaml │ └── src │ │ └── file.yaml ├── one-paragraph │ ├── expected │ │ └── index.md │ └── src │ │ └── index.md ├── reference-links │ └── src │ │ └── index.md └── whitespace │ ├── expected │ └── index.md │ └── src │ └── index.md └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | 6 | [*.{js,json}] 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | es6: true 4 | extends: 5 | - 'eslint:recommended' 6 | - 'prettier' 7 | parserOptions: 8 | ecmaVersion: 2017 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | # http://git-scm.com/docs/gitattributes#_end_of_line_conversion 3 | * text=auto 4 | 5 | # For the following file types, normalize line endings to LF on 6 | # checkin and prevent conversion to CRLF when they are checked out 7 | # (this is required in order to prevent newline related issues like, 8 | # for example, after the build script is run) 9 | .* text eol=lf 10 | *.css text eol=lf 11 | *.html text eol=lf 12 | *.js text eol=lf 13 | *.json text eol=lf 14 | *.md text eol=lf 15 | *.sh text eol=lf 16 | *.txt text eol=lf 17 | *.xml text eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .nyc_output 3 | coverage.info 4 | test/fixtures/*/build 5 | *.tgz -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock.json = false 2 | sign-git-tag = true 3 | message = Bump package.json to %s -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | test/fixtures/** 2 | .nyc_output/** -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | trailingComma: none 2 | tabWidth: 2 3 | semi: false 4 | singleQuote: true 5 | bracketSpacing: true 6 | arrowParens: always 7 | printWidth: 120 8 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "before:init": ["npm run lint", "npm test"], 4 | "after:bump": "auto-changelog -p --starting-date 2021-12-01 --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release|skip changelog)'", 5 | "after:npm:bump": "npm pack", 6 | "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." 7 | }, 8 | "git": { 9 | "commitMessage": "Release ${version}", 10 | "commitArgs": ["-S"], 11 | "tagAnnotation": "Release ${version}", 12 | "tagArgs": ["-s"], 13 | "changelog": "auto-changelog --starting-date 2021-12-01 -u --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release|skip changelog)' --stdout -t https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs" 14 | }, 15 | "npm": { 16 | "publish": false 17 | }, 18 | "github": { 19 | "release": true, 20 | "releaseName": "@metalsmith/excerpts ${version}", 21 | "tokenRef": "GITHUB_TOKEN", 22 | "assets": ["metalsmith-*.tgz"] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | dist: xenial 3 | 4 | node_js: 5 | - 8 6 | - 12 7 | - 14 8 | - node 9 | 10 | os: 11 | - linux 12 | 13 | stages: 14 | - lint 15 | - test_windows 16 | - test 17 | - codecov 18 | 19 | jobs: 20 | include: 21 | - stage: lint 22 | name: ESlint 23 | node_js: node 24 | os: linux 25 | script: npm run lint 26 | - stage: test_windows 27 | name: Oldest supported version on Windows 28 | node_js: 8 29 | os: windows 30 | - stage: codecov 31 | name: Coveralls 32 | node_js: node 33 | os: linux 34 | script: npm run test && npm run coveralls 35 | 36 | script: npm run test 37 | 38 | notifications: 39 | email: false 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### Changelog 2 | 3 | All notable changes to this project will be documented in this file. Dates are displayed in UTC. 4 | 5 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 6 | 7 | #### [v1.5.1](https://github.com/metalsmith/excerpts/compare/v1.5.0...v1.5.1) 8 | 9 | - Adds better JSDoc types and exports named plugin [`a49e465`](https://github.com/metalsmith/excerpts/commit/a49e4655c83ab26cf450c6c18fb5ccf9f99fe4e0) 10 | - Fixes incorrect debug namespace to @metalsmith/excerpts [`fc4301c`](https://github.com/metalsmith/excerpts/commit/fc4301c49af9619a9ecb97cc76211c56114121aa) 11 | 12 | #### [v1.5.0](https://github.com/metalsmith/excerpts/compare/v1.4.1...v1.5.0) 13 | 14 | > 11 December 2021 15 | 16 | - Added nyc, coveralls, prettier, ESlint & replaced xo with mocha. Added NPM CI/CD scripts [`c6d7caf`](https://github.com/metalsmith/excerpts/commit/c6d7caf34f4b767c4832922ec7ac274d0e7aa171) 17 | - Aligned README structure & package.json, updated cheerio, debug. [`337f2a7`](https://github.com/metalsmith/excerpts/commit/337f2a7835aef0331f6f21483a8eb7286981d30d) 18 | - [skip changelog] Downgrade mocha to Node 8 compat [`74f99c0`](https://github.com/metalsmith/excerpts/commit/74f99c033ff21ca922b44c33cfed6de9288bdd6d) 19 | - [skip changelog] Formatted source w. Prettier, updated .release-it.json config [`00dadcd`](https://github.com/metalsmith/excerpts/commit/00dadcd46976cab8927d8f9a5318f93c8036e9c8) 20 | - Aligned dotfiles & default repository files with core metalsmith plugins [`fa74f1d`](https://github.com/metalsmith/excerpts/commit/fa74f1d872b072510422628fcac074c4695ab77e) 21 | - Added build CI Badge [`9c1a075`](https://github.com/metalsmith/excerpts/commit/9c1a075d41c07a00e26aca47b6e70116eb24f268) 22 | 23 | 24 | 25 | ## [1.4.1][] - 2020-11-04 26 | 27 | - Fixed CI issue for NodeJS v10 28 | 29 | # Previous 30 | 31 | ## [1.4.0][] - 2020-11-04 32 | 33 | - Add support for multiple formats: text & html 34 | - Updated packages 35 | - ESLint error fix 36 | 37 | ## [1.3.0][] - 2019-10-30 38 | 39 | - Updated packages 40 | - Removed unnecessary Makefile 41 | - Modernised repo with xo, tap (which has coverage) 42 | - Added tests to fix coverage issues 43 | - Updated readme with badges 44 | 45 | ## [1.2.0][] - 2017-03-11 46 | 47 | - fix images in the first paragraph so they are ignored 48 | 49 | ## [1.0.0][] - May 6, 2014 50 | 51 | - change to expect `.html` files 52 | 53 | ## [0.3.1][] - April 28, 2014 54 | 55 | - fix whitespace-leading files 56 | - fix single-paragraph files 57 | 58 | ## [0.3.0][] - March 23, 2014 59 | 60 | - add converting excerpt to HTML 61 | 62 | ## [0.2.0][] - March 5, 2014 63 | 64 | - rename to `metalsmith-excerpts` 65 | 66 | ## [0.1.1][] - February 6, 2014 67 | 68 | - add debug statements 69 | 70 | ## [0.1.0][] - February 6, 2014 71 | 72 | - update to use buffers 73 | 74 | ## 0.0.1 - February 5, 2014 75 | 76 | - Initial commit 77 | 78 | --- 79 | 80 | :sparkles: 81 | 82 | --- 83 | 84 | [1.4.1]: https://github.com/metalsmith/excerpts/compare/v1.4.0...v1.4.1 85 | [1.4.0]: https://github.com/metalsmith/excerpts/compare/v1.3.0...v1.4.0 86 | [1.3.0]: https://github.com/metalsmith/excerpts/compare/1.2.0...v1.3.0 87 | [1.2.0]: https://github.com/metalsmith/excerpts/compare/1.0.0...1.2.0 88 | [1.0.0]: https://github.com/metalsmith/excerpts/compare/0.3.1...1.0.0 89 | [0.3.1]: https://github.com/metalsmith/excerpts/compare/0.3.0...0.3.1 90 | [0.3.0]: https://github.com/metalsmith/excerpts/compare/0.2.0...0.3.0 91 | [0.2.0]: https://github.com/metalsmith/excerpts/compare/0.1.1...0.2.0 92 | [0.1.1]: https://github.com/metalsmith/excerpts/compare/0.1.0...0.1.1 93 | [0.1.0]: https://github.com/metalsmith/excerpts/compare/0.0.1...0.1.0 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 webketje 4 | Copyright (c) 2014-2021 Segment 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @metalsmith/excerpts 2 | 3 | A Metalsmith plugin to extract an excerpt from HTML files. 4 | 5 | [![metalsmith: core plugin][metalsmith-badge]][metalsmith-url] 6 | [![npm: version][npm-badge]][npm-url] 7 | [![ci: build][ci-badge]][ci-url] 8 | [![code coverage][codecov-badge]][codecov-url] 9 | [![license: MIT][license-badge]][license-url] 10 | 11 | ## Installation 12 | 13 | NPM: 14 | 15 | ``` 16 | npm install @metalsmith/excerpts 17 | ``` 18 | 19 | Yarn: 20 | 21 | ``` 22 | yarn add @metalsmith/excerpts 23 | ``` 24 | 25 | ## Usage 26 | 27 | The excerpt is scraped from the first paragraph (`
` tag) of the rendered HTML `contents` of a file and added to its metadata `excerpt` key. 28 | 29 | ```js 30 | const excerpts = require('@metalsmith/excerpts') 31 | 32 | metalsmith.use(excerpts()) // default -> file.excerpt 33 | metalsmith.use(excerpts({ multipleFormats: true })) // -> file.excerpt.html & file.excerpt.text 34 | ``` 35 | 36 | ### Custom excerpts 37 | 38 | You can define a custom `excerpt` in the front-matter of specific files: 39 | 40 | ```md 41 | --- 42 | excerpt: This will be the excerpt 43 | --- 44 | 45 | This would be the excerpt if none was specified in the front-matter 46 | ``` 47 | 48 | ### Excerpts with tags stripped 49 | 50 | Sometimes you may need access to the text content of the excerpt without HTML tags. 51 | Pass the `multipleFormats: true` option to store an excerpt object with both HTML and text excerpts `{ html: '...', text: '...' }`: 52 | 53 | ```js 54 | metalsmith.use(excerpts({ multipleFormats: true })) 55 | ``` 56 | 57 | ### CLI usage 58 | 59 | Add the `@metalsmith/excerpts` key to your `metalsmith.json` plugins key: 60 | 61 | ```json 62 | { 63 | "plugins": [{ "@metalsmith/excerpts": { "multipleFormats": false } }] 64 | } 65 | ``` 66 | 67 | ## License 68 | 69 | [MIT](LICENSE) 70 | 71 | [npm-badge]: https://img.shields.io/npm/v/@metalsmith/excerpts.svg 72 | [npm-url]: https://www.npmjs.com/package/@metalsmith/excerpts 73 | [ci-badge]: https://app.travis-ci.com/metalsmith/excerpts.svg?branch=master 74 | [ci-url]: https://app.travis-ci.com/github/metalsmith/excerpts 75 | [metalsmith-badge]: https://img.shields.io/badge/metalsmith-core_plugin-green.svg?longCache=true 76 | [metalsmith-url]: https://metalsmith.io 77 | [codecov-badge]: https://img.shields.io/coveralls/github/metalsmith/excerpts 78 | [codecov-url]: https://coveralls.io/github/metalsmith/excerpts 79 | [license-badge]: https://img.shields.io/github/license/metalsmith/excerpts 80 | [license-url]: LICENSE 81 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | const { extname } = require('path') 2 | const debug = require('debug')('@metalsmith/excerpts') 3 | const cheerio = require('cheerio') 4 | 5 | /** 6 | * Check if a `file` is HTML. 7 | * 8 | * @param {String} file 9 | * @return {Boolean} 10 | */ 11 | const html = (file) => /\.html?/.test(extname(file)) 12 | 13 | /** 14 | * @typedef {Object} Options 15 | * @property {Boolean} [multipleFormats] set to true to store both a `excerpt.html` and `excerpt.text` 16 | */ 17 | 18 | /** 19 | * A Metalsmith plugin to extract an excerpt from HTML files. 20 | * 21 | * @param {Options} [options] 22 | * @return {import('metalsmith').Plugin} 23 | */ 24 | function plugin(options) { 25 | return function excerpts(files, metalsmith, done) { 26 | setImmediate(done) 27 | 28 | options = options || {} 29 | 30 | Object.keys(files).forEach((file) => { 31 | debug('checking file: %s', file) 32 | if (!html(file)) { 33 | return 34 | } 35 | 36 | const data = files[file] 37 | 38 | if (typeof data.excerpt === 'string' && data.excerpt.length > 0) { 39 | return // Don't mutate data 40 | } 41 | 42 | debug('storing excerpt: %s', file) 43 | const $ = cheerio.load(data.contents.toString()) 44 | let p = $('p').first() 45 | while (p.children('img').length > 0) { 46 | p = p.next() 47 | } 48 | 49 | if (options.multipleFormats) { 50 | data.excerpt = { 51 | html: $.html(p).trim(), 52 | text: $.text(p).trim() 53 | } 54 | } else { 55 | data.excerpt = $.html(p).trim() 56 | } 57 | }) 58 | } 59 | } 60 | 61 | module.exports = plugin 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@metalsmith/excerpts", 3 | "version": "1.5.1", 4 | "description": "A Metalsmith plugin to extract an excerpt from HTML files.", 5 | "keywords": [ 6 | "excerpt", 7 | "metalsmith-plugin", 8 | "metalsmith" 9 | ], 10 | "homepage": "https://github.com/metalsmith/excerpts#readme", 11 | "bugs": "https://github.com/metalsmith/excerpts/issues", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/metalsmith/excerpts.git" 15 | }, 16 | "license": "MIT", 17 | "main": "lib/index.js", 18 | "directories": { 19 | "lib": "lib", 20 | "test": "test" 21 | }, 22 | "files": [ 23 | "lib", 24 | "CHANGELOG.md" 25 | ], 26 | "scripts": { 27 | "changelog": "auto-changelog -u --starting-date 2021-12-01 --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release|skip changelog)'", 28 | "coverage": "nyc report --reporter=text-lcov > ./coverage.info", 29 | "coveralls": "npm run coverage && cat ./coverage.info | coveralls", 30 | "format": "prettier --write \"**/*.{yml,md,js,json}\"", 31 | "lint": "eslint .", 32 | "release": "release-it .", 33 | "test": "nyc mocha" 34 | }, 35 | "dependencies": { 36 | "cheerio": "^1.0.0-rc.10", 37 | "debug": "^4.3.3" 38 | }, 39 | "devDependencies": { 40 | "@metalsmith/markdown": "^1.3.0", 41 | "auto-changelog": "^2.3.0", 42 | "coveralls": "^3.1.1", 43 | "eslint": "^8.4.1", 44 | "eslint-config-prettier": "^8.3.0", 45 | "metalsmith": "^2.3.0", 46 | "mocha": "^7.2.0", 47 | "nyc": "^15.1.0", 48 | "prettier": "^2.5.1", 49 | "release-it": "^14.11.8" 50 | }, 51 | "peerDependencies": { 52 | "metalsmith": "^2.3.0" 53 | }, 54 | "engines": { 55 | "node": ">=8" 56 | }, 57 | "publishConfig": { 58 | "access": "public" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/fixtures/basic/expected/index.md: -------------------------------------------------------------------------------- 1 | excerpt -------------------------------------------------------------------------------- /test/fixtures/basic/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | template: layout 3 | --- 4 | 5 | excerpt 6 | 7 | more content -------------------------------------------------------------------------------- /test/fixtures/first-paragraph-image/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Testing first paragraphs with images 3 | --- 4 | 5 |  6 | 7 |  8 | 9 | This is the excerpt. 10 | -------------------------------------------------------------------------------- /test/fixtures/indented-paragraph/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Testing indented first paragraphs 3 | --- 4 | 5 | This is code. 6 | 7 | This is the excerpt. 8 | 9 | -------------------------------------------------------------------------------- /test/fixtures/no-mutation/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | template: layout 3 | excerpt: beans 4 | --- 5 | 6 | excerpt 7 | 8 | more content 9 | -------------------------------------------------------------------------------- /test/fixtures/not-html/expected/file.yaml: -------------------------------------------------------------------------------- 1 | template: layout 2 | -------------------------------------------------------------------------------- /test/fixtures/not-html/src/file.yaml: -------------------------------------------------------------------------------- 1 | template: layout 2 | -------------------------------------------------------------------------------- /test/fixtures/one-paragraph/expected/index.md: -------------------------------------------------------------------------------- 1 | excerpt -------------------------------------------------------------------------------- /test/fixtures/one-paragraph/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | template: layout 3 | --- 4 | 5 | excerpt 6 | -------------------------------------------------------------------------------- /test/fixtures/reference-links/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Test reference links 3 | --- 4 | 5 | This is [a link][a]. 6 | 7 | [a]: http://example.com 8 | 9 | -------------------------------------------------------------------------------- /test/fixtures/whitespace/expected/index.md: -------------------------------------------------------------------------------- 1 | excerpt -------------------------------------------------------------------------------- /test/fixtures/whitespace/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | template: layout 3 | --- 4 | 5 | 6 | 7 | 8 | 9 | excerpt 10 | 11 | more content 12 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | const { it } = require('mocha') 3 | const markdown = require('@metalsmith/markdown') 4 | const metalsmith = require('metalsmith') 5 | const excerpt = require('..') 6 | 7 | it('should convert excerpt files', (done) => { 8 | metalsmith('test/fixtures/basic') 9 | .use(markdown()) 10 | .use(excerpt()) 11 | .build((err, files) => { 12 | if (err) { 13 | return err 14 | } 15 | 16 | assert.equal('
excerpt
', files['index.html'].excerpt) 17 | done() 18 | }) 19 | }) 20 | 21 | it('should convert excerpt files that have leading whitespace', (done) => { 22 | metalsmith('test/fixtures/whitespace') 23 | .use(markdown()) 24 | .use(excerpt()) 25 | .build((err, files) => { 26 | if (err) { 27 | return err 28 | } 29 | 30 | assert.equal('excerpt
', files['index.html'].excerpt) 31 | done() 32 | }) 33 | }) 34 | 35 | it('should convert excerpt files that only have one paragraph', (done) => { 36 | metalsmith('test/fixtures/one-paragraph') 37 | .use(markdown()) 38 | .use(excerpt()) 39 | .build((err, files) => { 40 | if (err) { 41 | return err 42 | } 43 | 44 | assert.equal('excerpt
', files['index.html'].excerpt) 45 | done() 46 | }) 47 | }) 48 | 49 | it('should convert excerpt files with reference-style links', (done) => { 50 | metalsmith('test/fixtures/reference-links') 51 | .use(markdown()) 52 | .use(excerpt()) 53 | .build((err, files) => { 54 | if (err) { 55 | return err 56 | } 57 | 58 | assert.equal('This is a link.
', files['index.html'].excerpt) 59 | done() 60 | }) 61 | }) 62 | 63 | it('should skip excerpts with leading whitespace', (done) => { 64 | metalsmith('test/fixtures/indented-paragraph') 65 | .use(markdown()) 66 | .use(excerpt()) 67 | .build((err, files) => { 68 | if (err) { 69 | return err 70 | } 71 | 72 | assert.equal('This is the excerpt.
', files['index.html'].excerpt) 73 | done() 74 | }) 75 | }) 76 | 77 | it('should convert excerpts with multiple formats', (done) => { 78 | metalsmith('test/fixtures/reference-links') 79 | .use(markdown()) 80 | .use(excerpt({ multipleFormats: true })) 81 | .build((err, files) => { 82 | if (err) { 83 | return err 84 | } 85 | 86 | assert.equal('This is a link.
', files['index.html'].excerpt.html) 87 | assert.equal('This is a link.', files['index.html'].excerpt.text) 88 | done() 89 | }) 90 | }) 91 | 92 | it('should skip excerpts with images', (done) => { 93 | metalsmith('test/fixtures/first-paragraph-image') 94 | .use(markdown()) 95 | .use(excerpt()) 96 | .build((err, files) => { 97 | if (err) { 98 | return err 99 | } 100 | 101 | assert.equal('This is the excerpt.
', files['index.html'].excerpt) 102 | done() 103 | }) 104 | }) 105 | 106 | it('should skip excerpts that are not html', (done) => { 107 | metalsmith('test/fixtures/not-html') 108 | .use(excerpt()) 109 | .build((err, files) => { 110 | if (err) { 111 | return err 112 | } 113 | 114 | assert.ok('template: layout', files['file.yaml'].contents.toString().trim()) 115 | done() 116 | }) 117 | }) 118 | 119 | it('should not mutate an existing excerpts', (done) => { 120 | metalsmith('test/fixtures/no-mutation') 121 | .use(markdown()) 122 | .use(excerpt()) 123 | .build((err, files) => { 124 | if (err) { 125 | return err 126 | } 127 | 128 | assert.equal('beans', files['index.html'].excerpt) 129 | done() 130 | }) 131 | }) 132 | --------------------------------------------------------------------------------