mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
filter-categories and strict-ssl questions
This commit is contained in:
+2
-2
@@ -8,7 +8,7 @@ export function author(post) {
|
||||
}
|
||||
|
||||
// get array of decoded category names, filtered as specified in settings
|
||||
export function categories(post) {
|
||||
export function categories(post, config) {
|
||||
if (!post.data.category) {
|
||||
return [];
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export function categories(post) {
|
||||
.filter(category => category.$.domain === 'category')
|
||||
.map(({ $: attributes }) => decodeURIComponent(attributes.nicename));
|
||||
|
||||
return categories.filter(category => !settings.filter_categories.includes(category));
|
||||
return categories.filter((category) => !config.filterCategories.includes(category));
|
||||
}
|
||||
|
||||
// get cover image filename, previously decoded and set on post.meta
|
||||
|
||||
@@ -125,4 +125,14 @@ export const all = [
|
||||
type: 'boolean',
|
||||
default: false
|
||||
},
|
||||
{
|
||||
name: 'filter-categories',
|
||||
type: 'list',
|
||||
default: ['uncategorized']
|
||||
},
|
||||
{
|
||||
name: 'strict-ssl',
|
||||
type: 'boolean',
|
||||
default: true
|
||||
}
|
||||
];
|
||||
|
||||
+10
-11
@@ -4,7 +4,6 @@ import fs from 'fs';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import path from 'path';
|
||||
import * as settings from './settings.js';
|
||||
import * as shared from './shared.js';
|
||||
|
||||
export async function writeFilesPromise(posts, config) {
|
||||
@@ -12,11 +11,11 @@ export async function writeFilesPromise(posts, config) {
|
||||
await writeImageFilesPromise(posts, config);
|
||||
}
|
||||
|
||||
async function processPayloadsPromise(payloads, loadFunc) {
|
||||
async function processPayloadsPromise(payloads, loadFunc, config) {
|
||||
const promises = payloads.map(payload => new Promise((resolve, reject) => {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const data = await loadFunc(payload.item);
|
||||
const data = await loadFunc(payload.item, config);
|
||||
await writeFile(payload.destinationPath, data);
|
||||
console.log(chalk.green('[OK]') + ' ' + payload.name);
|
||||
resolve();
|
||||
@@ -68,7 +67,7 @@ async function writeMarkdownFilesPromise(posts, config) {
|
||||
console.log('\nNo posts to save...');
|
||||
} else {
|
||||
console.log(`\nSaving ${remainingCount} posts (${skipCount} already exist)...`);
|
||||
await processPayloadsPromise(payloads, loadMarkdownFilePromise);
|
||||
await processPayloadsPromise(payloads, loadMarkdownFilePromise, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,15 +130,15 @@ async function writeImageFilesPromise(posts, config) {
|
||||
console.log('\nNo images to download and save...');
|
||||
} else {
|
||||
console.log(`\nDownloading and saving ${remainingCount} images (${skipCount} already exist)...`);
|
||||
await processPayloadsPromise(payloads, loadImageFilePromise);
|
||||
await processPayloadsPromise(payloads, loadImageFilePromise, config);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadImageFilePromise(imageUrl) {
|
||||
async function loadImageFilePromise(imageUrl, config) {
|
||||
// only encode the URL if it doesn't already have encoded characters
|
||||
const url = (/%[\da-f]{2}/i).test(imageUrl) ? imageUrl : encodeURI(imageUrl);
|
||||
|
||||
const config = {
|
||||
const requestConfig = {
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
@@ -148,15 +147,15 @@ async function loadImageFilePromise(imageUrl) {
|
||||
responseType: 'arraybuffer'
|
||||
};
|
||||
|
||||
if (!settings.strict_ssl) {
|
||||
if (!config.strictSsl) {
|
||||
// custom agents to disable SSL errors (adding both http and https, just in case)
|
||||
config.httpAgent = new http.Agent({ rejectUnauthorized: false });
|
||||
config.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||
requestConfig.httpAgent = new http.Agent({ rejectUnauthorized: false });
|
||||
requestConfig.httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
||||
}
|
||||
|
||||
let buffer;
|
||||
try {
|
||||
const response = await axios(config);
|
||||
const response = await axios(requestConfig);
|
||||
buffer = Buffer.from(response.data, 'binary');
|
||||
} catch (ex) {
|
||||
if (ex.response) {
|
||||
|
||||
Reference in New Issue
Block a user