mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-19 22:54:11 +09:00
Dynamic frontmatter loading
This commit is contained in:
Generated
+9
@@ -17,6 +17,7 @@
|
|||||||
"luxon": "^3.4.4",
|
"luxon": "^3.4.4",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"request-promise-native": "^1.0.8",
|
"request-promise-native": "^1.0.8",
|
||||||
|
"require-directory": "^2.1.1",
|
||||||
"turndown": "^7.1.2",
|
"turndown": "^7.1.2",
|
||||||
"turndown-plugin-gfm": "^1.0.2",
|
"turndown-plugin-gfm": "^1.0.2",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
@@ -1545,6 +1546,14 @@
|
|||||||
"request": "^2.34"
|
"request": "^2.34"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/require-directory": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/resolve-from": {
|
"node_modules/resolve-from": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
"luxon": "^3.4.4",
|
"luxon": "^3.4.4",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"request-promise-native": "^1.0.8",
|
"request-promise-native": "^1.0.8",
|
||||||
|
"require-directory": "^2.1.1",
|
||||||
"turndown": "^7.1.2",
|
"turndown": "^7.1.2",
|
||||||
"turndown-plugin-gfm": "^1.0.2",
|
"turndown-plugin-gfm": "^1.0.2",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
|
|||||||
+9
-14
@@ -1,16 +1,13 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const requireDirectory = require('require-directory');
|
||||||
const xml2js = require('xml2js');
|
const xml2js = require('xml2js');
|
||||||
|
|
||||||
const shared = require('./shared');
|
const shared = require('./shared');
|
||||||
|
const settings = require('./settings');
|
||||||
const translator = require('./translator');
|
const translator = require('./translator');
|
||||||
|
|
||||||
const frontmatter = {
|
// dynamically requires all frontmatter loaders
|
||||||
title: require('./frontmatter/title'),
|
const frontmatterLoaders = requireDirectory(module, './frontmatter', { recurse: false });
|
||||||
date: require('./frontmatter/date'),
|
|
||||||
categories: require('./frontmatter/categories'),
|
|
||||||
tags: require('./frontmatter/tags'),
|
|
||||||
coverImage: require('./frontmatter/coverImage'),
|
|
||||||
};
|
|
||||||
|
|
||||||
async function parseFilePromise(config) {
|
async function parseFilePromise(config) {
|
||||||
console.log('\nParsing...');
|
console.log('\nParsing...');
|
||||||
@@ -174,13 +171,11 @@ function mergeImagesIntoPosts(images, posts) {
|
|||||||
|
|
||||||
function populateFrontmatter(posts) {
|
function populateFrontmatter(posts) {
|
||||||
posts.forEach(post => {
|
posts.forEach(post => {
|
||||||
post.frontmatter = {
|
post.frontmatter = {};
|
||||||
title: frontmatter.title(post),
|
settings.frontmatter_fields.forEach(field => {
|
||||||
date: frontmatter.date(post),
|
[key, alias] = field.split(':');
|
||||||
categories: frontmatter.categories(post),
|
post.frontmatter[alias || key] = frontmatterLoaders[key](post);
|
||||||
tags: frontmatter.tags(post),
|
});
|
||||||
coverImage: frontmatter.coverImage(post)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user