mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-17 13:43:44 +09:00
merge master and move code as needed
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// get author, without decoding
|
||||
// WordPress doesn't allow funky characters in usernames anyway
|
||||
module.exports = (post) => {
|
||||
return post.data.creator[0];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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));
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
// 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;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const luxon = require('luxon');
|
||||
|
||||
const settings = require('../settings');
|
||||
|
||||
// get post date, optionally formatted as specified in settings
|
||||
module.exports = (post) => {
|
||||
const dateTime = luxon.DateTime.fromRFC2822(post.pubDate[0], { zone: settings.custom_date_timezone || 'utc' });
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
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];
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// get excerpt, not decoded, newlines collapsed
|
||||
module.exports = (post) => {
|
||||
return post.data.encoded[1].replace(/[\r\n]+/gm, ' ');
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// get ID
|
||||
module.exports = (post) => {
|
||||
return post.data.post_id[0];
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// get slug, previously decoded and set on post.meta
|
||||
module.exports = (post) => {
|
||||
return post.meta.slug;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// get simple post title, but not decoded like other frontmatter string fields
|
||||
module.exports = (post) => {
|
||||
return post.data.title[0];
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
// 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];
|
||||
}
|
||||
Reference in New Issue
Block a user