mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Change when date is formatted
This commit is contained in:
+3
-14
@@ -1,6 +1,3 @@
|
||||
import * as luxon from 'luxon';
|
||||
import * as settings from './settings.js';
|
||||
|
||||
// get author, without decoding
|
||||
// WordPress doesn't allow funky characters in usernames anyway
|
||||
export function author(post) {
|
||||
@@ -26,18 +23,10 @@ export function coverImage(post) {
|
||||
return post.meta.coverImage;
|
||||
}
|
||||
|
||||
// get post date, optionally formatted as specified in settings
|
||||
// get post date, previously saved as a luxon datetime object on post.meta
|
||||
// this value is also used for year/month folders, date prefixes, etc. as needed
|
||||
export function date(post, config) {
|
||||
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 (config.includeTimeWithDate) {
|
||||
return dateTime.toISO();
|
||||
} else {
|
||||
return dateTime.toISODate();
|
||||
}
|
||||
export function date(post) {
|
||||
return post.meta.date;
|
||||
}
|
||||
|
||||
// get excerpt, not decoded, newlines collapsed
|
||||
|
||||
+11
-3
@@ -1,4 +1,5 @@
|
||||
import fs from 'fs';
|
||||
import * as luxon from 'luxon';
|
||||
import xml2js from 'xml2js';
|
||||
import * as frontmatter from './frontmatter.js';
|
||||
import * as shared from './shared.js';
|
||||
@@ -65,12 +66,15 @@ function collectPosts(channelData, postTypes, config) {
|
||||
|
||||
// meta data isn't written to file, but is used to help with other things
|
||||
meta: {
|
||||
type: postType,
|
||||
id: getPostId(postData),
|
||||
slug: getPostSlug(postData),
|
||||
date: getPostDate(postData, config),
|
||||
coverImageId: getPostCoverImageId(postData),
|
||||
coverImage: undefined, // possibly set later in mergeImagesIntoPosts()
|
||||
type: postType,
|
||||
imageUrls: [] // possibly set later in mergeImagesIntoPosts()
|
||||
|
||||
// these are possibly set later in mergeImagesIntoPosts()
|
||||
coverImage: undefined,
|
||||
imageUrls: []
|
||||
},
|
||||
|
||||
// contents of the post in markdown
|
||||
@@ -98,6 +102,10 @@ function getPostSlug(postData) {
|
||||
return decodeURIComponent(postData.post_name[0]);
|
||||
}
|
||||
|
||||
function getPostDate(postData, config) {
|
||||
return luxon.DateTime.fromRFC2822(postData.pubDate[0], { zone: config.customDateTimezone });
|
||||
}
|
||||
|
||||
function getPostCoverImageId(postData) {
|
||||
if (postData.postmeta === undefined) {
|
||||
return undefined;
|
||||
|
||||
@@ -125,6 +125,16 @@ export const all = [
|
||||
type: 'boolean',
|
||||
default: false
|
||||
},
|
||||
{
|
||||
name: 'custom-date-formatting',
|
||||
type: 'string',
|
||||
default: ''
|
||||
},
|
||||
{
|
||||
name: 'custom-date-timezone',
|
||||
type: 'string',
|
||||
default: 'utc'
|
||||
},
|
||||
{
|
||||
name: 'strict-ssl',
|
||||
type: 'boolean',
|
||||
|
||||
+7
-12
@@ -3,6 +3,7 @@ import chalk from 'chalk';
|
||||
import fs from 'fs';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import * as luxon from 'luxon';
|
||||
import path from 'path';
|
||||
import * as shared from './shared.js';
|
||||
|
||||
@@ -71,7 +72,7 @@ async function writeMarkdownFilesPromise(posts, config) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMarkdownFilePromise(post) {
|
||||
async function loadMarkdownFilePromise(post, config) {
|
||||
let output = '---\n';
|
||||
|
||||
Object.entries(post.frontmatter).forEach(([key, value]) => {
|
||||
@@ -82,7 +83,11 @@ async function loadMarkdownFilePromise(post) {
|
||||
outputValue = value.reduce((list, item) => `${list}\n - "${item}"`, '');
|
||||
}
|
||||
} else if (value instanceof luxon.DateTime) {
|
||||
outputValue = encodeDate(value);
|
||||
if (config.customDateFormatting) {
|
||||
outputValue = value.toFormat(config.customDateFormatting);
|
||||
} else {
|
||||
outputValue = config.includeTimeWithDate ? value.toISO() : value.toISODate();
|
||||
}
|
||||
} else {
|
||||
// single string value
|
||||
const escapedValue = (value || '').replace(/"/g, '\\"');
|
||||
@@ -100,16 +105,6 @@ async function loadMarkdownFilePromise(post) {
|
||||
return output;
|
||||
}
|
||||
|
||||
function encodeDate(dateTime) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
async function writeImageFilesPromise(posts, config) {
|
||||
// collect image data from all posts into a single flattened array of payloads
|
||||
let skipCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user