Skip to content

Commit 77ad892

Browse files
authored
Reset contentType if already exists (#57132)
1 parent 63e69a0 commit 77ad892

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/content-render/scripts/add-content-type.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,7 @@ function processFile(filePath: string, options: ScriptOptions) {
102102
// Remove the legacy type property if option is passed
103103
const removeLegacyType = Boolean(options.removeType && data.type)
104104

105-
// Skip if contentType already exists and we're not removing legacy type
106-
if (data.contentType && !removeLegacyType) {
107-
console.log(`contentType already set on ${relativePath}`)
108-
return { processed: true, updated: false }
109-
}
110-
111-
const newContentType = data.contentType || determineContentType(relativePath, data.type || '')
105+
const newContentType = determineContentType(relativePath, data.type || '')
112106

113107
if (options.dryRun) {
114108
console.log(`\n${relativePath}`)
@@ -121,9 +115,24 @@ function processFile(filePath: string, options: ScriptOptions) {
121115
return { processed: true, updated: false }
122116
}
123117

124-
// Set the contentType property if it doesn't exist
125-
if (!data.contentType) {
118+
// Check if we're actually changing an existing contentType
119+
const isChangingContentType = data.contentType && data.contentType !== newContentType
120+
const isAddingContentType = !data.contentType
121+
122+
if (isChangingContentType) {
123+
console.log(
124+
`Changing contentType from '${data.contentType}' to '${newContentType}' on ${relativePath}`,
125+
)
126+
} else if (isAddingContentType) {
127+
console.log(`Adding contentType '${newContentType}' on ${relativePath}`)
128+
}
129+
130+
// Only update if there's actually a change needed
131+
if (isChangingContentType || isAddingContentType) {
126132
data.contentType = newContentType
133+
} else {
134+
console.log(`contentType is already set to '${data.contentType}' on ${relativePath}`)
135+
return { processed: true, updated: false }
127136
}
128137

129138
let legacyTypeValue

0 commit comments

Comments
 (0)