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