Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tryyyyy #2976

Closed
wants to merge 10 commits into from
Closed

tryyyyy #2976

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions _haikus/2023_Bugs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: haiku
title: Bug
author: Upendra Nayanajith
---

Bug in the code,
Comment it out, forget it,
Until code will break again.
9 changes: 9 additions & 0 deletions _haikus/2023_love/hate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: haiku
title: Love-Hate
author: Upendra Nayanajith
---

Love and hate entwined,
Like fire and ice combined,
Two sides of the same mind.
86 changes: 86 additions & 0 deletions node test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, it } from 'mocha'; // Import describe and it from Mocha
import { assert } from 'chai'; // Import assert from Chai
import remark from 'remark';
import frontmatter from 'remark-frontmatter';
import extract from 'remark-extract-frontmatter';
import yaml from 'yaml';
import strip from 'strip-markdown';
import vfile from 'to-vfile';
import syllable from 'syllable';
import fs from 'fs';

const dir = './_haikus/';
const blockList = ['haikus.md'];

async function processMarkdown(filename) {
return new Promise((resolve, reject) => {
remark()
.use(frontmatter)
.use(extract, { yaml })
.use(strip)
.process(vfile.readSync(filename), (err, file) => {
if (err) {
reject(err);
} else {
resolve([file.toString(), file.data]);
}
});
});
}

async function validateHaiku(filename, lines, meta) {
describe(filename, () => {
it("should have a '.md' file extension", () => {
assert.ok(/\.md$/.test(filename), "extension does not match '.md'");
});

describe('file metadata', () => {
it("should have layout equal to 'haiku'", () => {
assert.equal(meta.layout, 'haiku', "layout metadata should equal 'haiku'");
});

it('should have non-blank title', () => {
assert.equal(typeof meta.title, 'string', 'title metadata is missing');
});

it('should have non-blank author', () => {
assert.equal(typeof meta.author, 'string', 'author metadata is missing');
});
});

describe('haiku structure', () => {
it('should have three lines', () => {
assert.equal(lines.length, 3);
});

it('should have five syllables on the first line', () => {
assert.equal(syllable(lines[0]), 5);
});

it('should have seven syllables on the second line', () => {
assert.equal(syllable(lines[1]), 7);
});

it('should have five syllables on the third line', () => {
assert.equal(syllable(lines[2]), 5);
});
});
});
}

async function main() {
const files = fs.readdirSync(dir);

for (const file of files) {
if (!blockList.includes(file)) {
const [text, meta] = await processMarkdown(dir + file);
const lines = text.split('\n').filter((line) => line !== '');

if (meta.test !== false) {
await validateHaiku(file, lines, meta);
}
}
}
}

main(); // Call the main function to start the validation process
58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "cloud_haiku",
"version": "1.0.0",
"description": "Haiku structure testing for cloud_haiku repo",
"main": "test.js",
"scripts": {
"test": "tap 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": {
"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"
}
}
86 changes: 0 additions & 86 deletions test.js

This file was deleted.

36 changes: 36 additions & 0 deletions validateHaiku.js
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', () => {});
});
});
}
Loading