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