@@ -5,7 +5,10 @@ import { parseInline } from 'marked';
55import { parseEntities } from 'parse-entities' ;
66import { get } from 'svelte/store' ;
77import { _ } 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' ;
912import { isCollectionIndexFile } from '$lib/services/contents/collection/index-file' ;
1013import { 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