Small frontmatter getter refactor, more questions

This commit is contained in:
Will Boyd
2025-02-01 15:10:45 -05:00
parent f6197d1d70
commit 3bbf0274ce
5 changed files with 26 additions and 16 deletions
+11 -11
View File
@@ -3,12 +3,12 @@ import * as settings from './settings.js';
// get author, without decoding
// WordPress doesn't allow funky characters in usernames anyway
export function getAuthor(post) {
export function author(post) {
return post.data.creator[0];
}
// get array of decoded category names, filtered as specified in settings
export function getCategories(post) {
export function categories(post) {
if (!post.data.category) {
return [];
}
@@ -22,18 +22,18 @@ export function getCategories(post) {
// 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
export function getCoverImage(post) {
export function coverImage(post) {
return post.meta.coverImage;
}
// get post date, optionally formatted as specified in settings
// this value is also used for year/month folders, date prefixes, etc. as needed
export function getDate(post) {
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 (settings.include_time_with_date) {
} else if (config.includeTimeWithDate) {
return dateTime.toISO();
} else {
return dateTime.toISODate();
@@ -41,22 +41,22 @@ export function getDate(post) {
}
// get excerpt, not decoded, newlines collapsed
export function getExcerpt(post) {
export function excerpt(post) {
return post.data.encoded[1].replace(/[\r\n]+/gm, ' ');
}
// get ID
export function getId(post) {
export function id(post) {
return post.data.post_id[0];
}
// get slug, previously decoded and set on post.meta
export function getSlug(post) {
export function slug(post) {
return post.meta.slug;
}
// get array of decoded tag names
export function getTags(post) {
export function tags(post) {
if (!post.data.category) {
return [];
}
@@ -69,12 +69,12 @@ export function getTags(post) {
}
// get simple post title, but not decoded like other frontmatter string fields
export function getTitle(post) {
export function title(post) {
return post.data.title[0];
}
// get type, often this will always be "post"
// but can also be "page" or other custom types
export function getType(post) {
export function type(post) {
return post.data.post_type[0];
}