mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Frontmatter getters comments
This commit is contained in:
@@ -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 [];
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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' });
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// get array of tags for post
|
||||
module.exports = (post) => {
|
||||
if (!post.data.category) {
|
||||
return [];
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// get simple post title
|
||||
module.exports = (post) => {
|
||||
return post.data.title[0];
|
||||
};
|
||||
|
||||
+3
-3
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user