mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Sort imports, delete old frontmatter getters
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
|
||||
import path from 'path';
|
||||
import process from 'process';
|
||||
|
||||
import * as wizard from './src/wizard.js';
|
||||
import * as parser from './src/parser.js';
|
||||
import * as wizard from './src/wizard.js';
|
||||
import * as writer from './src/writer.js';
|
||||
|
||||
(async () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as luxon from 'luxon';
|
||||
|
||||
import * as settings from './settings.js';
|
||||
|
||||
// get author, without decoding
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// get author, without decoding
|
||||
// WordPress doesn't allow funky characters in usernames anyway
|
||||
module.exports = (post) => {
|
||||
return post.data.creator[0];
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
const settings = require('../settings');
|
||||
|
||||
// get array of decoded category names, filtered as specified in settings
|
||||
module.exports = (post) => {
|
||||
if (!post.data.category) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const categories = post.data.category
|
||||
.filter(category => category.$.domain === 'category')
|
||||
.map(({ $: attributes }) => decodeURIComponent(attributes.nicename));
|
||||
|
||||
return categories.filter(category => !settings.filter_categories.includes(category));
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
// get cover image filename, previously decoded and set on post.meta
|
||||
// this one is unique as it relies on special logic executed by the parser
|
||||
module.exports = (post) => {
|
||||
return post.meta.coverImage;
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
const luxon = require('luxon');
|
||||
|
||||
const settings = require('../settings');
|
||||
|
||||
// get post date, optionally formatted as specified in settings
|
||||
// this value is also used for year/month folders, date prefixes, etc. as needed
|
||||
module.exports = (post) => {
|
||||
const dateTime = luxon.DateTime.fromRFC2822(post.data.pubDate[0], { zone: settings.custom_date_timezone });
|
||||
|
||||
if (settings.custom_date_formatting) {
|
||||
return dateTime.toFormat(settings.custom_date_formatting);
|
||||
} else if (settings.include_time_with_date) {
|
||||
return dateTime.toISO();
|
||||
} else {
|
||||
return dateTime.toISODate();
|
||||
}
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
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 frontmatter_fields in settings.js
|
||||
7. Remove this comment block and the debug console 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 'EXAMPLE: ' + post.data.title[0];
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
// get excerpt, not decoded, newlines collapsed
|
||||
module.exports = (post) => {
|
||||
return post.data.encoded[1].replace(/[\r\n]+/gm, ' ');
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
// get ID
|
||||
module.exports = (post) => {
|
||||
return post.data.post_id[0];
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
// get slug, previously decoded and set on post.meta
|
||||
module.exports = (post) => {
|
||||
return post.meta.slug;
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
// get array of decoded tag names
|
||||
module.exports = (post) => {
|
||||
if (!post.data.category) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const categories = post.data.category
|
||||
.filter(category => category.$.domain === 'post_tag')
|
||||
.map(({ $: attributes }) => decodeURIComponent(attributes.nicename));
|
||||
|
||||
return categories;
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
// get simple post title, but not decoded like other frontmatter string fields
|
||||
module.exports = (post) => {
|
||||
return post.data.title[0];
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
// get type, often this will always be "post"
|
||||
// but can also be "page" or other custom types
|
||||
module.exports = (post) => {
|
||||
return post.data.post_type[0];
|
||||
}
|
||||
+3
-4
@@ -1,10 +1,9 @@
|
||||
import fs from 'fs';
|
||||
import xml2js from 'xml2js';
|
||||
|
||||
import * as shared from './shared.js';
|
||||
import * as settings from './settings.js';
|
||||
import * as translator from './translator.js';
|
||||
import * as frontmatter from './frontmatter.js';
|
||||
import * as settings from './settings.js';
|
||||
import * as shared from './shared.js';
|
||||
import * as translator from './translator.js';
|
||||
|
||||
export async function parseFilePromise(config) {
|
||||
console.log('\nParsing...');
|
||||
|
||||
+1
-2
@@ -5,9 +5,8 @@ import http from 'http';
|
||||
import https from 'https';
|
||||
import * as luxon from 'luxon';
|
||||
import path from 'path';
|
||||
|
||||
import * as shared from './shared.js';
|
||||
import * as settings from './settings.js';
|
||||
import * as shared from './shared.js';
|
||||
|
||||
export async function writeFilesPromise(posts, config) {
|
||||
await writeMarkdownFilesPromise(posts, config);
|
||||
|
||||
Reference in New Issue
Block a user