feat(content): added a new command to extract content from a file
This commit is contained in:
parent
a80aeb2f7f
commit
d3eb21e7bf
2 changed files with 48 additions and 0 deletions
|
@ -27,6 +27,14 @@ markdown verb *.markdown
|
||||||
markdowny version
|
markdowny version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### content
|
||||||
|
|
||||||
|
> Extract the content from one or more files.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
markdowny content *.markdown
|
||||||
|
```
|
||||||
|
|
||||||
### count
|
### count
|
||||||
|
|
||||||
> Counts the number of words excluding the YAML header and displays it.
|
> Counts the number of words excluding the YAML header and displays it.
|
||||||
|
|
40
src/tools/content.ts
Normal file
40
src/tools/content.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import * as _ from "lodash";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import * as scanner from "../scanner";
|
||||||
|
import * as yargs from "yargs";
|
||||||
|
|
||||||
|
export var command = "content";
|
||||||
|
export var describe = "Extracts the content of the file without metadata";
|
||||||
|
|
||||||
|
export function builder(yargs: yargs.Arguments)
|
||||||
|
{
|
||||||
|
return yargs
|
||||||
|
.help("help")
|
||||||
|
|
||||||
|
.option(
|
||||||
|
"output",
|
||||||
|
{
|
||||||
|
alias: "o",
|
||||||
|
default: "-",
|
||||||
|
describe: "Write output to a file or `-` for standard out",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
.demand(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handler(argv: any)
|
||||||
|
{
|
||||||
|
// Parse through the files and retrieve the metadata.
|
||||||
|
var files = argv._.splice(1);
|
||||||
|
var data: any = scanner.scanFiles(argv, files);
|
||||||
|
var output = data.map(x => x.__content).join("\n");
|
||||||
|
|
||||||
|
// Figure out where to write.
|
||||||
|
if (argv.output === "-")
|
||||||
|
{
|
||||||
|
console.log(output);
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(argv.output, Buffer.from(output, "utf-8"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue