From 932e7546faf8d2a511205afb634da79112af5ec2 Mon Sep 17 00:00:00 2001 From: Eka <6597211+ekafyi@users.noreply.github.com> Date: Sat, 28 Mar 2020 22:04:44 +0700 Subject: [PATCH 01/11] add post excerpt to frontmatter --- src/parser.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser.js b/src/parser.js index e1dafa9..0a82f3e 100644 --- a/src/parser.js +++ b/src/parser.js @@ -110,6 +110,11 @@ function getPostCoverImageId(postData) { return id; } +function getPostExcerpt(post) { + const excerpt = post.encoded[1].replace(/(\r\n|\n|\r)/gm, " "); + return excerpt; +} + function collectAttachedImages(channelData) { const images = getItemsOfType(channelData, 'attachment') // filter to certain image file types From 635451a4e3bb3d8261ad89da7764e6a61dcca120 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 11:45:06 -0500 Subject: [PATCH 02/11] Move getPostExcerpt() into frontmatter getter --- src/frontmatter/excerpt.js | 5 +++++ src/parser.js | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 src/frontmatter/excerpt.js diff --git a/src/frontmatter/excerpt.js b/src/frontmatter/excerpt.js new file mode 100644 index 0000000..5c1e1f0 --- /dev/null +++ b/src/frontmatter/excerpt.js @@ -0,0 +1,5 @@ +// get excerpt, not decoded, newlines collapsed +module.exports = (post) => { + const excerpt = post.data.encoded[1].replace(/[(\r\n|\n|\r)]/gm, " "); + return excerpt; +}; diff --git a/src/parser.js b/src/parser.js index 0a82f3e..e1dafa9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -110,11 +110,6 @@ function getPostCoverImageId(postData) { return id; } -function getPostExcerpt(post) { - const excerpt = post.encoded[1].replace(/(\r\n|\n|\r)/gm, " "); - return excerpt; -} - function collectAttachedImages(channelData) { const images = getItemsOfType(channelData, 'attachment') // filter to certain image file types From 755f752019abd56c3f1066b1c231a30a3998c4cf Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 11:47:17 -0500 Subject: [PATCH 03/11] Tweak regex to avoid multiple spaces --- src/frontmatter/excerpt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontmatter/excerpt.js b/src/frontmatter/excerpt.js index 5c1e1f0..f2182bd 100644 --- a/src/frontmatter/excerpt.js +++ b/src/frontmatter/excerpt.js @@ -1,5 +1,5 @@ // get excerpt, not decoded, newlines collapsed module.exports = (post) => { - const excerpt = post.data.encoded[1].replace(/[(\r\n|\n|\r)]/gm, " "); + const excerpt = post.data.encoded[1].replace(/[\r\n]+/gm, ' '); return excerpt; }; From 36cbf638aa5904a13f5ecc8ab2335d60d4328338 Mon Sep 17 00:00:00 2001 From: Travis Fantina Date: Tue, 13 Feb 2024 17:40:44 -0800 Subject: [PATCH 04/11] Adds author to front matter This will likely need some configuration to enable it, I threw this together at work but if there is intrest I can add that. --- src/parser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/parser.js b/src/parser.js index e1dafa9..ffca48f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -110,6 +110,10 @@ function getPostCoverImageId(postData) { return id; } +function getAuthor(post) { + return post.creator[0] +} + function collectAttachedImages(channelData) { const images = getItemsOfType(channelData, 'attachment') // filter to certain image file types From a8929901e3518b43552329032fb618e4f9967431 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 12:40:33 -0500 Subject: [PATCH 05/11] Move author logic to frontmatter getter --- src/frontmatter/author.js | 5 +++++ src/parser.js | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 src/frontmatter/author.js diff --git a/src/frontmatter/author.js b/src/frontmatter/author.js new file mode 100644 index 0000000..ab5d78f --- /dev/null +++ b/src/frontmatter/author.js @@ -0,0 +1,5 @@ +// get author, without decoding +// WordPress doesn't allow funky characters in author names anyway +module.exports = (post) => { + return post.data.creator[0]; +} diff --git a/src/parser.js b/src/parser.js index ffca48f..e1dafa9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -110,10 +110,6 @@ function getPostCoverImageId(postData) { return id; } -function getAuthor(post) { - return post.creator[0] -} - function collectAttachedImages(channelData) { const images = getItemsOfType(channelData, 'attachment') // filter to certain image file types From 8477487047ac920c4592b2e4a3d0c6e6b660a876 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 12:41:35 -0500 Subject: [PATCH 06/11] I really need to do something about tabs --- src/frontmatter/categories.js | 2 +- src/frontmatter/excerpt.js | 4 ++-- src/frontmatter/tags.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontmatter/categories.js b/src/frontmatter/categories.js index 4408ba6..0328e0f 100644 --- a/src/frontmatter/categories.js +++ b/src/frontmatter/categories.js @@ -10,5 +10,5 @@ module.exports = (post) => { .filter(category => category.$.domain === 'category') .map(({ $: attributes }) => decodeURIComponent(attributes.nicename)); - return categories.filter(category => !settings.filter_categories.includes(category)); + return categories.filter(category => !settings.filter_categories.includes(category)); }; diff --git a/src/frontmatter/excerpt.js b/src/frontmatter/excerpt.js index f2182bd..f83e5ce 100644 --- a/src/frontmatter/excerpt.js +++ b/src/frontmatter/excerpt.js @@ -1,5 +1,5 @@ // get excerpt, not decoded, newlines collapsed module.exports = (post) => { - const excerpt = post.data.encoded[1].replace(/[\r\n]+/gm, ' '); - return excerpt; + const excerpt = post.data.encoded[1].replace(/[\r\n]+/gm, ' '); + return excerpt; }; diff --git a/src/frontmatter/tags.js b/src/frontmatter/tags.js index 2781145..8a2b23c 100644 --- a/src/frontmatter/tags.js +++ b/src/frontmatter/tags.js @@ -8,5 +8,5 @@ module.exports = (post) => { .filter(category => category.$.domain === 'post_tag') .map(({ $: attributes }) => decodeURIComponent(attributes.nicename)); - return categories; + return categories; }; From 735d0f552bd075a3269e54fa6c4bba1356eebaea Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 12:42:10 -0500 Subject: [PATCH 07/11] Indentation fix --- src/frontmatter/tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontmatter/tags.js b/src/frontmatter/tags.js index 8a2b23c..0b53fd8 100644 --- a/src/frontmatter/tags.js +++ b/src/frontmatter/tags.js @@ -8,5 +8,5 @@ module.exports = (post) => { .filter(category => category.$.domain === 'post_tag') .map(({ $: attributes }) => decodeURIComponent(attributes.nicename)); - return categories; + return categories; }; From da11ff0a8380279833934bb3407f373a63b65ccf Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 12:49:08 -0500 Subject: [PATCH 08/11] Frontmatter getter for ID --- src/frontmatter/id.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/frontmatter/id.js diff --git a/src/frontmatter/id.js b/src/frontmatter/id.js new file mode 100644 index 0000000..5403fc0 --- /dev/null +++ b/src/frontmatter/id.js @@ -0,0 +1,4 @@ +// get ID +module.exports = (post) => { + return post.data.post_id[0]; +} From 268e69abdda55f266d30b72e18ac1d523ede02bf Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 14:22:40 -0500 Subject: [PATCH 09/11] Frontmatter getter for type --- src/frontmatter/type.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/frontmatter/type.js diff --git a/src/frontmatter/type.js b/src/frontmatter/type.js new file mode 100644 index 0000000..25bfab4 --- /dev/null +++ b/src/frontmatter/type.js @@ -0,0 +1,5 @@ +// get type, often this will always be "post" +// but can also be "page" or other custom types +module.exports = (post) => { + return post.data.post_type[0]; +} From 0c2fe7eb545143013e1d6f065e2644f3270a9a1c Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 14:28:48 -0500 Subject: [PATCH 10/11] Comment clarification --- src/frontmatter/author.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontmatter/author.js b/src/frontmatter/author.js index ab5d78f..e6a9c4f 100644 --- a/src/frontmatter/author.js +++ b/src/frontmatter/author.js @@ -1,5 +1,5 @@ // get author, without decoding -// WordPress doesn't allow funky characters in author names anyway +// WordPress doesn't allow funky characters in usernames anyway module.exports = (post) => { return post.data.creator[0]; } From 3e2c6d956e8d7d22b7caf4c899d8e1ef29ec5dd0 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 26 Feb 2024 14:33:43 -0500 Subject: [PATCH 11/11] Minor code style --- src/frontmatter/excerpt.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frontmatter/excerpt.js b/src/frontmatter/excerpt.js index f83e5ce..bc6310d 100644 --- a/src/frontmatter/excerpt.js +++ b/src/frontmatter/excerpt.js @@ -1,5 +1,4 @@ // get excerpt, not decoded, newlines collapsed module.exports = (post) => { - const excerpt = post.data.encoded[1].replace(/[\r\n]+/gm, ' '); - return excerpt; + return post.data.encoded[1].replace(/[\r\n]+/gm, ' '); };