diff --git a/index.js b/index.js index 1e3bdf5..cd286c6 100644 --- a/index.js +++ b/index.js @@ -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 () => { diff --git a/src/frontmatter.js b/src/frontmatter.js index 43eb6dd..390815a 100644 --- a/src/frontmatter.js +++ b/src/frontmatter.js @@ -1,5 +1,4 @@ import * as luxon from 'luxon'; - import * as settings from './settings.js'; // get author, without decoding diff --git a/src/frontmatter/author.js b/src/frontmatter/author.js deleted file mode 100644 index e6a9c4f..0000000 --- a/src/frontmatter/author.js +++ /dev/null @@ -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]; -} diff --git a/src/frontmatter/categories.js b/src/frontmatter/categories.js deleted file mode 100644 index 0328e0f..0000000 --- a/src/frontmatter/categories.js +++ /dev/null @@ -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)); -}; diff --git a/src/frontmatter/coverImage.js b/src/frontmatter/coverImage.js deleted file mode 100644 index ea63c6b..0000000 --- a/src/frontmatter/coverImage.js +++ /dev/null @@ -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; -}; diff --git a/src/frontmatter/date.js b/src/frontmatter/date.js deleted file mode 100644 index 0cbe1bb..0000000 --- a/src/frontmatter/date.js +++ /dev/null @@ -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(); - } -}; diff --git a/src/frontmatter/example.js b/src/frontmatter/example.js deleted file mode 100644 index 2159d87..0000000 --- a/src/frontmatter/example.js +++ /dev/null @@ -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]; -}; diff --git a/src/frontmatter/excerpt.js b/src/frontmatter/excerpt.js deleted file mode 100644 index bc6310d..0000000 --- a/src/frontmatter/excerpt.js +++ /dev/null @@ -1,4 +0,0 @@ -// get excerpt, not decoded, newlines collapsed -module.exports = (post) => { - return post.data.encoded[1].replace(/[\r\n]+/gm, ' '); -}; diff --git a/src/frontmatter/id.js b/src/frontmatter/id.js deleted file mode 100644 index 5403fc0..0000000 --- a/src/frontmatter/id.js +++ /dev/null @@ -1,4 +0,0 @@ -// get ID -module.exports = (post) => { - return post.data.post_id[0]; -} diff --git a/src/frontmatter/slug.js b/src/frontmatter/slug.js deleted file mode 100644 index 7664b22..0000000 --- a/src/frontmatter/slug.js +++ /dev/null @@ -1,4 +0,0 @@ -// get slug, previously decoded and set on post.meta -module.exports = (post) => { - return post.meta.slug; -}; diff --git a/src/frontmatter/tags.js b/src/frontmatter/tags.js deleted file mode 100644 index 0b53fd8..0000000 --- a/src/frontmatter/tags.js +++ /dev/null @@ -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; -}; diff --git a/src/frontmatter/title.js b/src/frontmatter/title.js deleted file mode 100644 index b10bd29..0000000 --- a/src/frontmatter/title.js +++ /dev/null @@ -1,4 +0,0 @@ -// get simple post title, but not decoded like other frontmatter string fields -module.exports = (post) => { - return post.data.title[0]; -}; diff --git a/src/frontmatter/type.js b/src/frontmatter/type.js deleted file mode 100644 index 25bfab4..0000000 --- a/src/frontmatter/type.js +++ /dev/null @@ -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]; -} diff --git a/src/parser.js b/src/parser.js index 0e751db..4083dd0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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...'); diff --git a/src/writer.js b/src/writer.js index 25bdb6e..510eaf3 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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);