From 815e67f135f081331cc8dbf380f77a4268d3bd98 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sat, 24 Feb 2024 08:00:23 -0500 Subject: [PATCH] Frontmatter getters comments --- src/frontmatter/categories.js | 1 + src/frontmatter/coverImage.js | 2 ++ src/frontmatter/date.js | 1 + src/frontmatter/tags.js | 1 + src/frontmatter/title.js | 1 + src/parser.js | 6 +++--- 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/frontmatter/categories.js b/src/frontmatter/categories.js index c324403..82aad78 100644 --- a/src/frontmatter/categories.js +++ b/src/frontmatter/categories.js @@ -1,5 +1,6 @@ const settings = require('../settings'); +// get array of categories for post, filtered as specified in settings module.exports = (post) => { if (!post.data.category) { return []; diff --git a/src/frontmatter/coverImage.js b/src/frontmatter/coverImage.js index 1808ea5..e293312 100644 --- a/src/frontmatter/coverImage.js +++ b/src/frontmatter/coverImage.js @@ -1,3 +1,5 @@ +// get cover image filename, previously set on post.meta +// this one is unique as it relies on logic executed by the parser module.exports = (post) => { return post.meta.coverImage; }; diff --git a/src/frontmatter/date.js b/src/frontmatter/date.js index 16292b7..8b5c11f 100644 --- a/src/frontmatter/date.js +++ b/src/frontmatter/date.js @@ -2,6 +2,7 @@ const luxon = require('luxon'); const settings = require('../settings'); +// get post date, optionally formatted as specified in settings module.exports = (post) => { const dateTime = luxon.DateTime.fromRFC2822(post.data.pubDate[0], { zone: 'utc' }); diff --git a/src/frontmatter/tags.js b/src/frontmatter/tags.js index 1a44d98..9cb2c28 100644 --- a/src/frontmatter/tags.js +++ b/src/frontmatter/tags.js @@ -1,3 +1,4 @@ +// get array of tags for post module.exports = (post) => { if (!post.data.category) { return []; diff --git a/src/frontmatter/title.js b/src/frontmatter/title.js index 2b34f6c..d9bdb45 100644 --- a/src/frontmatter/title.js +++ b/src/frontmatter/title.js @@ -1,3 +1,4 @@ +// get simple post title module.exports = (post) => { return post.data.title[0]; }; diff --git a/src/parser.js b/src/parser.js index 892a7c0..cdec4ce 100644 --- a/src/parser.js +++ b/src/parser.js @@ -6,8 +6,8 @@ const shared = require('./shared'); const settings = require('./settings'); const translator = require('./translator'); -// dynamically requires all frontmatter loaders -const frontmatterLoaders = requireDirectory(module, './frontmatter', { recurse: false }); +// dynamically requires all frontmatter getters +const frontmatterGetters = requireDirectory(module, './frontmatter', { recurse: false }); async function parseFilePromise(config) { console.log('\nParsing...'); @@ -174,7 +174,7 @@ function populateFrontmatter(posts) { post.frontmatter = {}; settings.frontmatter_fields.forEach(field => { [key, alias] = field.split(':'); - post.frontmatter[alias || key] = frontmatterLoaders[key](post); + post.frontmatter[alias || key] = frontmatterGetters[key](post); }); }); }