markdowny/src/scanner.ts
D. Moonfire dce80229c9 Refactoring layout to fit with a different standard.
- Same directory for the source and library files.
- Switched from dotted to lodash directly.
- tscconfig.json moved up a level.
- Updated TypeScript packages.
	- Updated various files that were now throwing errors.
2017-10-19 18:39:45 -05:00

33 lines
885 B
TypeScript

import * as fs from "fs";
import * as path from "path";
import * as yamlFrontMatter from "yaml-front-matter";
/**
* Parses the input files and returns a list of YAML metadata with special
* columns for calculated values.
*/
export function scanFiles(argv, files: string[])
{
var list: any[] = [];
for (var file of files)
{
// Load the metadata from the given file.
var contents = fs.readFileSync(file, 'utf8')
var metadata = yamlFrontMatter.loadFront(contents);
// Add in the standard fields as "_" entries.
metadata._filename = file.replace(argv.prefix, "");
metadata._basename = path.basename(file);
metadata._words = metadata.__content
.replace("'", "")
.split(/\s+/g)
.length;
// Add the metadata to the list.
list.push(metadata);
}
return list;
}