diff --git a/src/frontmatter/debug.js b/src/frontmatter/debug.js new file mode 100644 index 0000000..348cc38 --- /dev/null +++ b/src/frontmatter/debug.js @@ -0,0 +1,19 @@ +/* + 1. Copy this file, rename to the frontmatter field name you want, camelcased + 2. Edit frontmatter_fields in settings.js to include your new field name + 3. Run the script to see post data dumps, to see what you can work with + 4. Write your code to get and return what you want + 5. Update "get whatever" comment to describe what you're getting + 6. Remove your field name from the default frontmatter_fields in settings.js + 7. Remove this comment block and the console debug code + 8. Make that pull request! +*/ + +// get whatever +module.exports = (post) => { + console.log('\nBEGIN POST DATA DUMP ===========================================================\n'); + console.dir(post, { depth: null }); + console.log('\nEND POST DATA DUMP =============================================================\n'); + + return 'DEBUG: ' + post.data.title[0]; +}; diff --git a/src/parser.js b/src/parser.js index 48985f5..3b9717d 100644 --- a/src/parser.js +++ b/src/parser.js @@ -171,7 +171,7 @@ function mergeImagesIntoPosts(images, posts) { function populateFrontmatter(posts) { posts.forEach(post => { - post.frontmatter = {}; + const frontmatter = {}; settings.frontmatter_fields.forEach(field => { [key, alias] = field.split(':'); @@ -180,8 +180,9 @@ function populateFrontmatter(posts) { throw `Could not find a frontmatter getter named "${key}".`; } - post.frontmatter[alias || key] = frontmatterGetter(post); + frontmatter[alias || key] = frontmatterGetter(post); }); + post.frontmatter = frontmatter; }); }