-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5a8308
commit 1ceb3c0
Showing
4 changed files
with
107 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
{ | ||
"name": "cloud_haiku", | ||
"version": "1.0.0", | ||
"description": "Haiku structure testing for cloud_haiku repo", | ||
"main": "node test.js", | ||
"scripts": { | ||
"test": "tap node test.js -R min --no-coverage-report --timeout=300" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/do-community/cloud_haiku.git" | ||
}, | ||
"author": "DigitalOcean Community Team", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/do-community/cloud_haiku/issues" | ||
}, | ||
"homepage": "https://github.com/do-community/cloud_haiku#readme", | ||
"dependencies": { | ||
"node-fetch": "^2.6.1", | ||
"remark": "^14.0.2", | ||
"remark-extract-frontmatter": "^2.0.0", | ||
"remark-frontmatter": "^1.3.2", | ||
"strip-markdown": "^3.1.1", | ||
"syllable": "^4.0.0", | ||
"tap": "^14.6.9", | ||
"to-vfile": "^6.0.0", | ||
"yaml": "^1.7.0" | ||
} | ||
} | ||
"name": "cloud_haiku", | ||
"version": "1.0.0", | ||
"description": "Haiku structure testing for cloud_haiku repo", | ||
"main": "node test.js", | ||
"scripts": { | ||
"test": "tap node test.js -R min --no-coverage-report --timeout=300" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/do-community/cloud_haiku.git" | ||
}, | ||
"author": "DigitalOcean Community Team", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/do-community/cloud_haiku/issues" | ||
}, | ||
"homepage": "https://github.com/do-community/cloud_haiku#readme", | ||
"dependencies": { | ||
"append-transform": "^latest", | ||
"node-fetch": "^2.6.1", | ||
"remark": "^14.0.2", | ||
"remark-extract-frontmatter": "^2.0.0", | ||
"remark-frontmatter": "^1.3.2", | ||
"strip-markdown": "^3.1.1", | ||
"syllable": "^4.0.0", | ||
"tap": "^14.6.9", | ||
"to-vfile": "^6.0.0", | ||
"yaml": "^1.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const assert = require('assert'); | ||
import remark from 'remark'; | ||
import { validateHaiku } from './validateHaiku'; | ||
const frontmatter = require('remark-frontmatter'); | ||
const extract = require('remark-extract-frontmatter'); | ||
const yaml = require('yaml').parse; | ||
const strip = require('strip-markdown'); | ||
const vfile = require('to-vfile'); | ||
const fs = require('fs'); | ||
|
||
const dir = './_haikus/'; | ||
const blockList = ['haikus.md']; | ||
|
||
const files = fs.readdirSync(dir); | ||
|
||
files.forEach(async(file) => { | ||
if (!blockList.includes(file)) { | ||
const [text, meta] = await processMarkdown(dir + file); | ||
const lines = text.split('\n').filter((line) => line !== ''); | ||
|
||
if (meta.test !== false) { | ||
validateHaiku(file, lines, meta); | ||
} | ||
} | ||
}); | ||
|
||
async function processMarkdown(filename) { | ||
return new Promise((resolve, reject) => { | ||
remark() | ||
.use(frontmatter) | ||
.use(extract, { yaml: yaml }) | ||
.use(strip) | ||
.process(vfile.readSync(filename), (err, file) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve([file.toString(), file.data]); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const tap = require('tap'); | ||
const syllable = require('syllable'); | ||
|
||
export function validateHaiku(filename, lines, meta) { | ||
tap.test(filename, () => { | ||
tap.test('should have a '.md, ' file extension', () => { | ||
tap.ok(/\.md$/.test(filename), 'extension does not match '.md, ''); | ||
}); | ||
|
||
tap.test('file metadata', () => { | ||
tap.test('should have layout equal to \'haiku\'', () => { | ||
tap.equal(meta.layout, 'haiku', 'layout metadata should equal \'haiku\''); | ||
}); | ||
|
||
tap.test('should have non-blank title', () => { | ||
tap.equal(typeof meta.title, 'string', 'title metadata is missing'); | ||
}); | ||
|
||
tap.test('should have non-blank author', () => { | ||
tap.equal(typeof meta.author, 'string', 'author metadata is missing'); | ||
}); | ||
}); | ||
|
||
tap.test('haiku structure', () => { | ||
tap.test('should have three lines', () => { | ||
tap.equal(lines.length, 3); | ||
}); | ||
|
||
tap.test('should have five syllables on the first line', () => { | ||
tap.equal(syllable(lines[0]), 5); | ||
}); | ||
|
||
tap.test('should have seven syllables on the second line', () => {}); | ||
}); | ||
}); | ||
} |