From ebfcce977af578f8dc919167359f848392c2f8f9 Mon Sep 17 00:00:00 2001 From: Jason Lloyd Date: Thu, 16 Jan 2020 17:44:50 +0000 Subject: [PATCH 1/4] create npm command --- index.js | 14 ++++++++------ package.json | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8f50b13..9699fba 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + const fs = require('fs'); const luxon = require('luxon'); const minimist = require('minimist'); @@ -49,11 +51,11 @@ function readFile(path) { } function parseFileContent(content) { - const processors = { tagNameProcessors: [ xml2js.processors.stripPrefix ] }; + const processors = { tagNameProcessors: [xml2js.processors.stripPrefix] }; xml2js.parseString(content, processors, (err, data) => { if (err) { console.log('Unable to parse file content.'); - console.log(err); + console.log(err); } else { processData(data); } @@ -112,7 +114,7 @@ function addContentImages(data, images) { console.log('Scraped ' + url + '.'); } } - }); + }); } function collectPosts(data) { @@ -155,13 +157,13 @@ function initTurndownService() { // but this series of checks should find the commonalities return ( ['P', 'DIV'].includes(node.nodeName) && - node.attributes['data-slug-hash'] && + node.attributes['data-slug-hash'] && node.getAttribute('class') === 'codepen' ); }, replacement: (content, node) => '\n\n' + node.outerHTML }); - + // preserve embedded scripts (for tweets, codepens, gists, etc.) turndownService.addRule('script', { filter: 'script', @@ -294,7 +296,7 @@ function writeMarkdownFile(post, postDir) { return accumulator + pair[0] + ': "' + pair[1] + '"\n' }, ''); const data = '---\n' + frontmatter + '---\n\n' + post.content + '\n'; - + const postPath = path.join(postDir, getPostFilename(post)); fs.writeFile(postPath, data, (err) => { if (err) { diff --git a/package.json b/package.json index bacac2d..1d44cd9 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,8 @@ "request": "^2.88.0", "turndown": "^5.0.3", "xml2js": "^0.4.22" + }, + "bin": { + "w2m": "./index.js" } -} +} \ No newline at end of file From 75e83d3f9e35fbf986e2da52aef65a83ab10d8f4 Mon Sep 17 00:00:00 2001 From: Jason Lloyd Date: Thu, 16 Jan 2020 18:20:35 +0000 Subject: [PATCH 2/4] Update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9d6f1e..437fdf1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,11 @@ You'll need: - [Node.js](https://nodejs.org/) v10.12 or later - Your [WordPress export file](https://codex.wordpress.org/Tools_Export_Screen) -Open your terminal to this package's directory. Run `npm install` and then `node index.js`. +There are a few ways you can run the package: + +1. use npx example: `npx w2m --input=wordpress_export_file.xml` +2. install it via npm: `npm i wordpress-export-to-markdown` then run `w2m --input=wordpress_export_file.xml` +3. Clone this repository, open your terminal then run `npm install` and then `node index.js`. This will create an `/output` folder filled with your posts and images. From 5850ece843035a6a294ec497dad0878428116623 Mon Sep 17 00:00:00 2001 From: Jason Lloyd Date: Thu, 16 Jan 2020 19:29:03 +0000 Subject: [PATCH 3/4] Change command to match repo --- README.md | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 437fdf1..c4440fe 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ You'll need: There are a few ways you can run the package: -1. use npx example: `npx w2m --input=wordpress_export_file.xml` -2. install it via npm: `npm i wordpress-export-to-markdown` then run `w2m --input=wordpress_export_file.xml` +1. use npx example: `npx wordpress-export-to-markdown --input=wordpress_export_file.xml` +2. install it via npm: `npm i wordpress-export-to-markdown` then run `wordpress-export-to-markdown --input=wordpress_export_file.xml` 3. Clone this repository, open your terminal then run `npm install` and then `node index.js`. This will create an `/output` folder filled with your posts and images. diff --git a/package.json b/package.json index 1d44cd9..054d0d1 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,6 @@ "xml2js": "^0.4.22" }, "bin": { - "w2m": "./index.js" + "wordpress-export-to-markdown": "./index.js" } -} \ No newline at end of file +} From 3f64dd6a9987ce45a23acb54e8e56a256e4a1d80 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sat, 18 Jan 2020 09:37:12 -0500 Subject: [PATCH 4/4] Words Cleaning up some words, capitalization, etc. Side note: I'm rewriting this entire README with v2, publishing very soon (maybe today!). --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c4440fe..c17f3a3 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ You'll need: - [Node.js](https://nodejs.org/) v10.12 or later - Your [WordPress export file](https://codex.wordpress.org/Tools_Export_Screen) -There are a few ways you can run the package: +There are a few ways you can use this package: -1. use npx example: `npx wordpress-export-to-markdown --input=wordpress_export_file.xml` -2. install it via npm: `npm i wordpress-export-to-markdown` then run `wordpress-export-to-markdown --input=wordpress_export_file.xml` -3. Clone this repository, open your terminal then run `npm install` and then `node index.js`. +1. To run via `npx`, run `npx wordpress-export-to-markdown` +2. To add to an existing repo, run `npm i wordpress-export-to-markdown` and then `wordpress-export-to-markdown` +3. Clone this repo, open your terminal to this package's directory, then run `npm install` and then `node index.js` This will create an `/output` folder filled with your posts and images.