mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-11 18:56:14 +09:00
Convert to ES modules and related changes
This commit is contained in:
+10
-15
@@ -1,15 +1,12 @@
|
||||
const fs = require('fs');
|
||||
const requireDirectory = require('require-directory');
|
||||
const xml2js = require('xml2js');
|
||||
import fs from 'fs';
|
||||
import xml2js from 'xml2js';
|
||||
|
||||
const shared = require('./shared');
|
||||
const settings = require('./settings');
|
||||
const translator = require('./translator');
|
||||
import * as shared from './shared.js';
|
||||
import * as settings from './settings.js';
|
||||
import * as translator from './translator.js';
|
||||
import * as frontmatter from './frontmatter.js';
|
||||
|
||||
// dynamically requires all frontmatter getters
|
||||
const frontmatterGetters = requireDirectory(module, './frontmatter', { recurse: false });
|
||||
|
||||
async function parseFilePromise(config) {
|
||||
export async function parseFilePromise(config) {
|
||||
console.log('\nParsing...');
|
||||
const content = await fs.promises.readFile(config.input, 'utf8');
|
||||
const allData = await xml2js.parseStringPromise(content, {
|
||||
@@ -174,19 +171,17 @@ function mergeImagesIntoPosts(images, posts) {
|
||||
|
||||
function populateFrontmatter(posts) {
|
||||
posts.forEach(post => {
|
||||
const frontmatter = {};
|
||||
post.frontmatter = {};
|
||||
settings.frontmatter_fields.forEach(field => {
|
||||
const [key, alias] = field.split(':');
|
||||
|
||||
let frontmatterGetter = frontmatterGetters[key];
|
||||
let frontmatterGetter = frontmatter['get' + key.replace(/^./, (match) => match.toUpperCase())];
|
||||
if (!frontmatterGetter) {
|
||||
throw `Could not find a frontmatter getter named "${key}".`;
|
||||
}
|
||||
|
||||
frontmatter[alias || key] = frontmatterGetter(post);
|
||||
post.frontmatter[alias || key] = frontmatterGetter(post);
|
||||
});
|
||||
post.frontmatter = frontmatter;
|
||||
});
|
||||
}
|
||||
|
||||
exports.parseFilePromise = parseFilePromise;
|
||||
|
||||
Reference in New Issue
Block a user