mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Merge pull request #17 from jaslloyd/master
Add npm command so it be run via npx
This commit is contained in:
@@ -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 use this package:
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -23,5 +23,8 @@
|
||||
"request": "^2.88.0",
|
||||
"turndown": "^5.0.3",
|
||||
"xml2js": "^0.4.22"
|
||||
},
|
||||
"bin": {
|
||||
"wordpress-export-to-markdown": "./index.js"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user