Skip to content

Commit 7771c33

Browse files
committed
Fix entry summary date transformation issue
1 parent d98550d commit 7771c33

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/lib/services/contents/entry/summary.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { parseInline } from 'marked';
55
import { parseEntities } from 'parse-entities';
66
import { get } from 'svelte/store';
77
import { _ } from 'svelte-i18n';
8-
import { applyTransformations } from '$lib/services/common/transformations';
8+
import {
9+
applyTransformations,
10+
DATE_TRANSFORMATION_REGEX,
11+
} from '$lib/services/common/transformations';
912
import { isCollectionIndexFile } from '$lib/services/contents/collection/index-file';
1013
import { getField, getFieldDisplayValue } from '$lib/services/contents/entry/fields';
1114

@@ -137,7 +140,12 @@ const replace = (placeholder, context) => {
137140
let value = replaceSub(tag, replaceSubContext);
138141

139142
if (value === undefined) {
140-
value = getFieldDisplayValue({ ...getFieldArgs, locale: defaultLocale });
143+
// If the `date` transformation is defined, e.g. `{{publish_date | date('YYYY-MM')}}`, use the
144+
// raw field value from the entry content. Otherwise, use the field display value. This is to
145+
// avoid applying the transformation to the display value, which leads to unexpected results.
146+
value = transformations.some((t) => DATE_TRANSFORMATION_REGEX.test(t))
147+
? valueMap[keyPath]
148+
: getFieldDisplayValue({ ...getFieldArgs, locale: defaultLocale });
141149
}
142150

143151
if (value === undefined) {

0 commit comments

Comments
 (0)