-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
6 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,62 @@ | ||
const logger = require('../../utils/logger'); | ||
const config = require('../../core/project.config'); | ||
const _collect = require('../../commands/collect'); | ||
const _extract = require('../../commands/extract'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* work in progress, always add on top of existing ways and prevent | ||
* backwards compatibility issues | ||
* | ||
* Default include-paths are pages and posts. | ||
* @param {string} argv.dest If present, write result to destination file | ||
* @param {string} argv.path If present overrides configuration file | ||
*/ | ||
const extract = (argv) => { | ||
const project = { | ||
config: config.get(), | ||
collected: {}, | ||
content: {}, | ||
extracted: {}, | ||
}; | ||
|
||
_collect.run(project) | ||
.then((p) => { | ||
const b = _extract.run(p); | ||
console.log({ b }); | ||
return b; | ||
}) | ||
.then((p) => { | ||
console.log({ p }); | ||
const { config } = p; | ||
console.log({ e: p.extracted }); | ||
|
||
if (argv.dest) { | ||
const dest = `./${argv.dest}/extracted.${config._hash}.json`; | ||
const ztring = JSON.stringify(p.extracted); | ||
fs.writeFileSync(dest, ztring); | ||
} | ||
|
||
logger.log(p.extracted); | ||
|
||
return p; | ||
}); | ||
}; | ||
|
||
const options = { | ||
dest: { | ||
default: null, | ||
description: `Destination folder to output a json file with results.`, | ||
}, | ||
}; | ||
|
||
/** | ||
* Command to read md files and other data and create taxonomy | ||
*/ | ||
module.exports = { | ||
command: `extract [dest] [path]`, | ||
aliases: [], | ||
describe: `Traverses the source files and compiles to destination.`, | ||
builder: options, | ||
handler: extract, | ||
}; |
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
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,80 @@ | ||
|
||
const klaw = require('klaw'); | ||
const $q = require('q'); | ||
const logger = require('../utils/logger'); | ||
const fm = require('front-matter'); | ||
const path = require('path'); | ||
const fse = require('fs-extra'); | ||
const moment = require('moment'); | ||
|
||
const extract = (c, items) => { | ||
|
||
const stat = fse.statSync(c.path); | ||
|
||
if (stat.isDirectory()) { | ||
items.push({ | ||
destination: null, | ||
content: null, | ||
stat, | ||
isDir: true, | ||
}); | ||
return; | ||
} | ||
|
||
let content = ``; | ||
try { | ||
content = fse.readFileSync(c.path, `utf-8`); | ||
} catch (err) { | ||
if (err) { throw err; } | ||
} | ||
|
||
content = fm(content); | ||
const timestamp = moment.utc(content.date ? content.date : stat.birthtime).format('X'); | ||
|
||
const destination = { | ||
folder: '', | ||
file: path.basename(c.path), | ||
}; | ||
|
||
const a = { | ||
destination: destination, | ||
content: content.body, | ||
stat, | ||
fm: { timestamp, ...(content.attributes) }, | ||
}; | ||
|
||
items.push(a); | ||
return items; | ||
}; | ||
|
||
/** | ||
* Extracts the metadata from files and creates a taxonomy | ||
* | ||
* @param {*} project | ||
* @returns | ||
*/ | ||
const run = (project) => { | ||
const promise = new Promise((resolve, reject) => { | ||
if (!project.collected || !project.collected.include) { | ||
logger.error('Missing collected property in project at extract step'); | ||
return reject(); | ||
} | ||
|
||
const items = { | ||
include: [], | ||
}; | ||
|
||
project.collected.include.map((c) => { | ||
extract(c, items.include); | ||
}); | ||
|
||
project.extracted = items; | ||
return resolve(project); | ||
}); | ||
|
||
return promise; | ||
}; | ||
|
||
module.exports = { | ||
run, | ||
}; |
File renamed without changes.