{"id":"f97b8300d5d14d82","repo":"gohugoio/hugo","slug":"failed-to-resolve-media-type-for-suffix-q","errorCode":null,"errorMessage":"failed to resolve media type for suffix %q","messagePattern":"failed to resolve media type for suffix %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagemeta/page_frontmatter.go","lineNumber":412,"sourceCode":"\t}\n\n\t// Note that NormalizePathStringBasic will make sure that we don't preserve the unnormalized path.\n\t// We do that when we create pages from the file system; mostly for backward compatibility,\n\t// but also because people tend to use the filename to name their resources (with spaces and all),\n\t// and this isn't relevant when creating resources from an API where it's easy to add textual meta data.\n\tp.Path = paths.NormalizePathStringBasic(p.Path)\n\n\treturn p.resolveContentType(\"\", mediaTypes)\n}\n\nfunc (p *PageConfigEarly) resolveContentType(ext string, mediaTypes media.Types) error {\n\tif p.Content.Markup == \"\" && p.Content.MediaType == \"\" {\n\t\tif ext == \"\" {\n\t\t\text = \"md\"\n\t\t}\n\t\tp.ContentMediaType = MarkupToMediaType(ext, mediaTypes)\n\t\tif p.ContentMediaType.IsZero() {\n\t\t\treturn fmt.Errorf(\"failed to resolve media type for suffix %q\", ext)\n\t\t}\n\t}\n\n\tvar s string\n\tif p.ContentMediaType.IsZero() {\n\t\tif p.Content.MediaType != \"\" {\n\t\t\ts = p.Content.MediaType\n\t\t\tp.ContentMediaType, _ = mediaTypes.GetByType(s)\n\t\t}\n\n\t\tif p.ContentMediaType.IsZero() && p.Content.Markup != \"\" {\n\t\t\ts = p.Content.Markup\n\t\t\tp.ContentMediaType = MarkupToMediaType(s, mediaTypes)\n\t\t}\n\t}\n\n\tif p.ContentMediaType.IsZero() {\n\t\treturn fmt.Errorf(\"failed to resolve media type for %q\", s)","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pagemeta/page_frontmatter.go#L394-L430","documentation":"When neither markup nor mediaType is set on a page, Hugo infers the content media type from the file suffix (defaulting to \"md\") via MarkupToMediaType against the configured media types. If the suffix maps to no configured media type, the result is zero and Hugo fails, because it cannot know how to render the content.","triggerScenarios":"resolveContentType called with an extension that no entry in the site's mediaTypes config claims — e.g. a content file with an unregistered extension processed through a content adapter or pages-from-data path, or a stripped-down custom mediaTypes config that removed markdown mappings.","commonSituations":"Custom [mediaTypes] config overriding defaults and dropping suffixes; content files with unusual extensions (.mdx, .txt variants) expected to render as markdown; typos in suffix lists when defining custom media types.","solutions":["Register the suffix under a media type in site config: [mediaTypes.\"text/markdown\"] suffixes = [\"md\", \"mdx\"].","Rename the content file to a supported extension (.md, .html, etc.).","If overriding mediaTypes, extend rather than replace the defaults so standard suffixes keep working."],"exampleFix":"# before: custom mediaTypes wiped markdown suffixes\n[mediaTypes.\"text/markdown\"]\nsuffixes = []\n# after\n[mediaTypes.\"text/markdown\"]\nsuffixes = [\"md\", \"markdown\", \"mdx\"]","handlingStrategy":"validation","validationCode":"# register unknown suffixes in site config before using them\n[mediaTypes.\"text/x-foo\"]\nsuffixes = [\"foo\"]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use standard content suffixes (.md, .html, .adoc, …) or register custom mediaTypes in config","Check for typos in file extensions and in content-adapter `mediaType`/path suffixes","After adding a custom media type, also map it to an output format if it must render"],"tags":["media-type","configuration","content","hugo"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}