diff --git a/src/parser.js b/src/parser.js index 5e22d36..d538e3a 100644 --- a/src/parser.js +++ b/src/parser.js @@ -57,16 +57,16 @@ function getPostTypes(allPostData) { } 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) { let allPosts = []; - postTypes.forEach(postType => { + postTypes.forEach((postType) => { const postsForType = getItemsOfType(allPostData, postType) - .filter(postData => postData.childValue('status') !== 'trash') - .filter(postData => !(postType === 'page' && postData.childValue('post_name') === 'sample-page')) - .map(postData => buildPost(postData)); + .filter((postData) => postData.childValue('status') !== 'trash') + .filter((postData) => !(postType === 'page' && postData.childValue('post_name') === 'sample-page')) + .map((postData) => buildPost(postData)); if (postsForType.length > 0) { if (postType === 'post') { @@ -120,11 +120,11 @@ function getPostMetaValue(data, key) { function collectAttachedImages(allPostData) { const images = getItemsOfType(allPostData, 'attachment') // filter to certain image file types - .filter(attachment => { + .filter((attachment) => { const url = attachment.childValue('attachment_url'); return url && (/\.(gif|jpe?g|png|webp)$/i).test(url); }) - .map(attachment => ({ + .map((attachment) => ({ id: attachment.childValue('post_id'), postId: attachment.optionalChildValue('post_parent') ?? 'nope', // may not exist (cover image in a squarespace export, for example) url: attachment.childValue('attachment_url') @@ -136,8 +136,8 @@ function collectAttachedImages(allPostData) { function collectScrapedImages(allPostData, postTypes) { const images = []; - postTypes.forEach(postType => { - getItemsOfType(allPostData, postType).forEach(postData => { + postTypes.forEach((postType) => { + getItemsOfType(allPostData, postType).forEach((postData) => { const postId = postData.childValue('post_id'); const postContent = postData.childValue('encoded'); @@ -169,8 +169,8 @@ function collectScrapedImages(allPostData, postTypes) { } function mergeImagesIntoPosts(images, posts) { - images.forEach(image => { - posts.forEach(post => { + images.forEach((image) => { + posts.forEach((post) => { let shouldAttach = false; // this image was uploaded as an attachment to this post @@ -192,9 +192,9 @@ function mergeImagesIntoPosts(images, posts) { } function populateFrontmatter(posts) { - posts.forEach(post => { + posts.forEach((post) => { post.frontmatter = {}; - shared.config.frontmatterFields.forEach(field => { + shared.config.frontmatterFields.forEach((field) => { const [key, alias] = field.split(':'); let frontmatterGetter = frontmatter[key]; diff --git a/src/translator.js b/src/translator.js index 2d4661a..a775a28 100644 --- a/src/translator.js +++ b/src/translator.js @@ -18,13 +18,13 @@ function initTurndownService() { // preserve embedded tweets 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 }); // preserve embedded codepens turndownService.addRule('codepen', { - filter: node => { + filter: (node) => { // codepen embed snippets have changed over the years // but this series of checks should find the commonalities return ( @@ -95,7 +95,7 @@ function initTurndownService() { // convert
 into a code block with language when appropriate
 	turndownService.addRule('pre', {
-		filter: node => {
+		filter: (node) => {
 			// a 
 with  inside will already render nicely, so don't interfere
 			return node.nodeName === 'PRE' && !node.querySelector('code');
 		},
diff --git a/src/writer.js b/src/writer.js
index 140b78c..cb73b13 100644
--- a/src/writer.js
+++ b/src/writer.js
@@ -13,7 +13,7 @@ export async function writeFilesPromise(posts) {
 }
 
 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 () => {
 			try {
 				const data = await loadFunc(payload.item);
@@ -28,7 +28,7 @@ async function processPayloadsPromise(payloads, loadFunc) {
 	}));
 
 	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) {
 		console.log('Done, got them all!');
 	} else {
@@ -45,7 +45,7 @@ async function writeMarkdownFilesPromise(posts) {
 	// package up posts into payloads
 	let existingCount = 0;
 	let delay = 0;
-	const payloads = posts.flatMap(post => {
+	const payloads = posts.flatMap((post) => {
 		const destinationPath = shared.buildPostPath(post);
 		if (checkFile(destinationPath)) {
 			// 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
 	let existingCount = 0;
 	let delay = 0;
-	const payloads = posts.flatMap(post => {
+	const payloads = posts.flatMap((post) => {
 		const postPath = shared.buildPostPath(post);
 		const imagesDir = path.join(path.dirname(postPath), 'images');
-		return post.imageUrls.flatMap(imageUrl => {
+		return post.imageUrls.flatMap((imageUrl) => {
 			const filename = shared.getFilenameFromUrl(imageUrl);
 			const destinationPath = path.join(imagesDir, filename);
 			if (checkFile(destinationPath)) {