Skip to content

Commit

Permalink
Use metalsmith.debug instead of debug
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Nov 2, 2022
1 parent 9654d29 commit b745991
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { basename, dirname, extname, join } = require('path')
const debug = require('debug')('@metalsmith/markdown')
const get = require('dlv')
const set = require('dset').dset
const { marked } = require('marked')
Expand All @@ -14,7 +13,7 @@ function isMarkdown(filePath) {
return /\.md$|\.markdown$/.test(extname(filePath))
}

function render(data, key, options) {
function render(data, key, options, debug) {
const value = get(data, key)
if (typeof value === 'string') {
set(data, key, marked(value, options))
Expand Down Expand Up @@ -46,6 +45,7 @@ function initMarkdown(options = defaultOptions) {
}

return function markdown(files, metalsmith, done) {
const debug = metalsmith.debug('@metalsmith/markdown')
setImmediate(done)

Object.keys(files).forEach(function (file) {
Expand All @@ -67,7 +67,7 @@ function initMarkdown(options = defaultOptions) {
if (options.wildcard) {
keys = expandWildcardKeypaths(data, options.keys, '*')
}
keys.forEach((k) => render(data, k, options))
keys.forEach((k) => render(data, k, options, debug))

delete files[file]
files[html] = data
Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"test": "nyc mocha"
},
"dependencies": {
"debug": "^4.3.4",
"dlv": "^1.1.3",
"dset": "^3.1.2",
"marked": "^4.2.0"
Expand Down
16 changes: 11 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-env node, mocha */

const assert = require('assert')
const equal = require('assert-dir-equal')
const Metalsmith = require('metalsmith')
const { describe, it } = require('mocha')
const { name } = require('../package.json')
const markdown = require('..')
const expandWildcardKeypath = require('../lib/expand-wildcard-keypath')
Expand All @@ -19,6 +20,7 @@ describe('@metalsmith/markdown', function () {

it('should not crash the metalsmith build when using default options', function (done) {
Metalsmith('test/fixtures/default')
.env('DEBUG', process.env.DEBUG)
.use(markdown())
.build((err) => {
assert.strictEqual(err, null)
Expand All @@ -40,19 +42,19 @@ describe('@metalsmith/markdown', function () {
Promise.all([
new Promise((resolve) => {
const files = getFiles()
markdown(true)(files, {}, () => {
markdown(true)(files, Metalsmith(__dirname), () => {
resolve(files)
})
}),
new Promise((resolve) => {
const files = getFiles()
markdown()(files, {}, () => {
markdown()(files, Metalsmith(__dirname), () => {
resolve(files)
})
}),
new Promise((resolve) => {
const files = getFiles()
markdown({ smartypants: true })(files, {}, () => {
markdown({ smartypants: true })(files, Metalsmith(__dirname), () => {
resolve(files)
})
})
Expand All @@ -69,6 +71,7 @@ describe('@metalsmith/markdown', function () {

it('should convert markdown files', function (done) {
Metalsmith('test/fixtures/basic')
.env('DEBUG', process.env.DEBUG)
.use(
markdown({
smartypants: true
Expand All @@ -83,14 +86,15 @@ describe('@metalsmith/markdown', function () {

it('should skip non-markdown files', function (done) {
const files = { 'index.css': {} }
markdown(true)(files, {}, () => {
markdown(true)(files, Metalsmith(__dirname), () => {
assert.deepStrictEqual(files, { 'index.css': {} })
done()
})
})

it('should allow a "keys" option', function (done) {
Metalsmith('test/fixtures/keys')
.env('DEBUG', process.env.DEBUG)
.use(
markdown({
keys: ['custom'],
Expand All @@ -106,6 +110,7 @@ describe('@metalsmith/markdown', function () {

it('should parse nested key paths', function (done) {
Metalsmith('test/fixtures/nested-keys')
.env('DEBUG', process.env.DEBUG)
.use(
markdown({
keys: ['custom', 'nested.key.path'],
Expand Down Expand Up @@ -139,6 +144,7 @@ describe('@metalsmith/markdown', function () {

it('should recognize a keys option loop placeholder', function (done) {
Metalsmith('test/fixtures/array-index-keys')
.env('DEBUG', process.env.DEBUG)
.use(
markdown({
keys: ['arr.*', 'objarr.*.prop', 'wildcard.faq.*.*', 'wildcard.titles.*'],
Expand Down

0 comments on commit b745991

Please sign in to comment.