mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-11 18:56:14 +09:00
Consistent arrow function syntax
This commit is contained in:
+13
-13
@@ -57,16 +57,16 @@ function getPostTypes(allPostData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getItemsOfType(allPostData, type) {
|
function getItemsOfType(allPostData, type) {
|
||||||
return allPostData.filter(item => item.childValue('post_type') === type);
|
return allPostData.filter((item) => item.childValue('post_type') === type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectPosts(allPostData, postTypes) {
|
function collectPosts(allPostData, postTypes) {
|
||||||
let allPosts = [];
|
let allPosts = [];
|
||||||
postTypes.forEach(postType => {
|
postTypes.forEach((postType) => {
|
||||||
const postsForType = getItemsOfType(allPostData, postType)
|
const postsForType = getItemsOfType(allPostData, postType)
|
||||||
.filter(postData => postData.childValue('status') !== 'trash')
|
.filter((postData) => postData.childValue('status') !== 'trash')
|
||||||
.filter(postData => !(postType === 'page' && postData.childValue('post_name') === 'sample-page'))
|
.filter((postData) => !(postType === 'page' && postData.childValue('post_name') === 'sample-page'))
|
||||||
.map(postData => buildPost(postData));
|
.map((postData) => buildPost(postData));
|
||||||
|
|
||||||
if (postsForType.length > 0) {
|
if (postsForType.length > 0) {
|
||||||
if (postType === 'post') {
|
if (postType === 'post') {
|
||||||
@@ -120,11 +120,11 @@ function getPostMetaValue(data, key) {
|
|||||||
function collectAttachedImages(allPostData) {
|
function collectAttachedImages(allPostData) {
|
||||||
const images = getItemsOfType(allPostData, 'attachment')
|
const images = getItemsOfType(allPostData, 'attachment')
|
||||||
// filter to certain image file types
|
// filter to certain image file types
|
||||||
.filter(attachment => {
|
.filter((attachment) => {
|
||||||
const url = attachment.childValue('attachment_url');
|
const url = attachment.childValue('attachment_url');
|
||||||
return url && (/\.(gif|jpe?g|png|webp)$/i).test(url);
|
return url && (/\.(gif|jpe?g|png|webp)$/i).test(url);
|
||||||
})
|
})
|
||||||
.map(attachment => ({
|
.map((attachment) => ({
|
||||||
id: attachment.childValue('post_id'),
|
id: attachment.childValue('post_id'),
|
||||||
postId: attachment.optionalChildValue('post_parent') ?? 'nope', // may not exist (cover image in a squarespace export, for example)
|
postId: attachment.optionalChildValue('post_parent') ?? 'nope', // may not exist (cover image in a squarespace export, for example)
|
||||||
url: attachment.childValue('attachment_url')
|
url: attachment.childValue('attachment_url')
|
||||||
@@ -136,8 +136,8 @@ function collectAttachedImages(allPostData) {
|
|||||||
|
|
||||||
function collectScrapedImages(allPostData, postTypes) {
|
function collectScrapedImages(allPostData, postTypes) {
|
||||||
const images = [];
|
const images = [];
|
||||||
postTypes.forEach(postType => {
|
postTypes.forEach((postType) => {
|
||||||
getItemsOfType(allPostData, postType).forEach(postData => {
|
getItemsOfType(allPostData, postType).forEach((postData) => {
|
||||||
const postId = postData.childValue('post_id');
|
const postId = postData.childValue('post_id');
|
||||||
|
|
||||||
const postContent = postData.childValue('encoded');
|
const postContent = postData.childValue('encoded');
|
||||||
@@ -169,8 +169,8 @@ function collectScrapedImages(allPostData, postTypes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mergeImagesIntoPosts(images, posts) {
|
function mergeImagesIntoPosts(images, posts) {
|
||||||
images.forEach(image => {
|
images.forEach((image) => {
|
||||||
posts.forEach(post => {
|
posts.forEach((post) => {
|
||||||
let shouldAttach = false;
|
let shouldAttach = false;
|
||||||
|
|
||||||
// this image was uploaded as an attachment to this post
|
// this image was uploaded as an attachment to this post
|
||||||
@@ -192,9 +192,9 @@ function mergeImagesIntoPosts(images, posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populateFrontmatter(posts) {
|
function populateFrontmatter(posts) {
|
||||||
posts.forEach(post => {
|
posts.forEach((post) => {
|
||||||
post.frontmatter = {};
|
post.frontmatter = {};
|
||||||
shared.config.frontmatterFields.forEach(field => {
|
shared.config.frontmatterFields.forEach((field) => {
|
||||||
const [key, alias] = field.split(':');
|
const [key, alias] = field.split(':');
|
||||||
|
|
||||||
let frontmatterGetter = frontmatter[key];
|
let frontmatterGetter = frontmatter[key];
|
||||||
|
|||||||
+3
-3
@@ -18,13 +18,13 @@ function initTurndownService() {
|
|||||||
|
|
||||||
// preserve embedded tweets
|
// preserve embedded tweets
|
||||||
turndownService.addRule('tweet', {
|
turndownService.addRule('tweet', {
|
||||||
filter: node => node.nodeName === 'BLOCKQUOTE' && node.getAttribute('class') === 'twitter-tweet',
|
filter: (node) => node.nodeName === 'BLOCKQUOTE' && node.getAttribute('class') === 'twitter-tweet',
|
||||||
replacement: (content, node) => '\n\n' + node.outerHTML
|
replacement: (content, node) => '\n\n' + node.outerHTML
|
||||||
});
|
});
|
||||||
|
|
||||||
// preserve embedded codepens
|
// preserve embedded codepens
|
||||||
turndownService.addRule('codepen', {
|
turndownService.addRule('codepen', {
|
||||||
filter: node => {
|
filter: (node) => {
|
||||||
// codepen embed snippets have changed over the years
|
// codepen embed snippets have changed over the years
|
||||||
// but this series of checks should find the commonalities
|
// but this series of checks should find the commonalities
|
||||||
return (
|
return (
|
||||||
@@ -95,7 +95,7 @@ function initTurndownService() {
|
|||||||
|
|
||||||
// convert <pre> into a code block with language when appropriate
|
// convert <pre> into a code block with language when appropriate
|
||||||
turndownService.addRule('pre', {
|
turndownService.addRule('pre', {
|
||||||
filter: node => {
|
filter: (node) => {
|
||||||
// a <pre> with <code> inside will already render nicely, so don't interfere
|
// a <pre> with <code> inside will already render nicely, so don't interfere
|
||||||
return node.nodeName === 'PRE' && !node.querySelector('code');
|
return node.nodeName === 'PRE' && !node.querySelector('code');
|
||||||
},
|
},
|
||||||
|
|||||||
+5
-5
@@ -13,7 +13,7 @@ export async function writeFilesPromise(posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processPayloadsPromise(payloads, loadFunc) {
|
async function processPayloadsPromise(payloads, loadFunc) {
|
||||||
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);
|
||||||
@@ -28,7 +28,7 @@ async function processPayloadsPromise(payloads, loadFunc) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const results = await Promise.allSettled(promises);
|
const results = await Promise.allSettled(promises);
|
||||||
const failedCount = results.filter(result => result.status === 'rejected').length;
|
const failedCount = results.filter((result) => result.status === 'rejected').length;
|
||||||
if (failedCount === 0) {
|
if (failedCount === 0) {
|
||||||
console.log('Done, got them all!');
|
console.log('Done, got them all!');
|
||||||
} else {
|
} else {
|
||||||
@@ -45,7 +45,7 @@ async function writeMarkdownFilesPromise(posts) {
|
|||||||
// package up posts into payloads
|
// package up posts into payloads
|
||||||
let existingCount = 0;
|
let existingCount = 0;
|
||||||
let delay = 0;
|
let delay = 0;
|
||||||
const payloads = posts.flatMap(post => {
|
const payloads = posts.flatMap((post) => {
|
||||||
const destinationPath = shared.buildPostPath(post);
|
const destinationPath = shared.buildPostPath(post);
|
||||||
if (checkFile(destinationPath)) {
|
if (checkFile(destinationPath)) {
|
||||||
// already exists, don't need to save again
|
// already exists, don't need to save again
|
||||||
@@ -117,10 +117,10 @@ async function writeImageFilesPromise(posts) {
|
|||||||
// collect image data from all posts into a single flattened array of payloads
|
// collect image data from all posts into a single flattened array of payloads
|
||||||
let existingCount = 0;
|
let existingCount = 0;
|
||||||
let delay = 0;
|
let delay = 0;
|
||||||
const payloads = posts.flatMap(post => {
|
const payloads = posts.flatMap((post) => {
|
||||||
const postPath = shared.buildPostPath(post);
|
const postPath = shared.buildPostPath(post);
|
||||||
const imagesDir = path.join(path.dirname(postPath), 'images');
|
const imagesDir = path.join(path.dirname(postPath), 'images');
|
||||||
return post.imageUrls.flatMap(imageUrl => {
|
return post.imageUrls.flatMap((imageUrl) => {
|
||||||
const filename = shared.getFilenameFromUrl(imageUrl);
|
const filename = shared.getFilenameFromUrl(imageUrl);
|
||||||
const destinationPath = path.join(imagesDir, filename);
|
const destinationPath = path.join(imagesDir, filename);
|
||||||
if (checkFile(destinationPath)) {
|
if (checkFile(destinationPath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user