gohugoio/hugo · error

failed to convert content for file

Error message

failed to convert content for file %q: %s

What it means

After metadata conversion, `convertJekyllContent` rewrites the body (Liquid tags, `{{ }}` includes, Jekyll-specific syntax) into Hugo/Markdown form. This wraps any failure during that content rewriting pass; `%q` is the filename, `%s` the conversion error.

Solutions

  1. Open the named file and locate the Liquid/Jekyll-specific tags the importer flagged.
  2. Replace unsupported tags with Markdown or Hugo shortcodes manually.
  3. Re-run the import after fixing; conversion is per-file so the rest succeeds.
  4. Audit the Jekyll export for third-party plugin syntax before importing.

Example fix

// before
{% youtube maxmustermann abc123 %}
// after
{{< youtube abc123 >}}
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-scan for unsupported Liquid tags so you can replace them ahead of import.
func hasUnsupportedLiquid(b []byte) bool {
  re := regexp.MustCompile(`\{%.*%\}`)
  return re.Match(b)
}

Type guard

null

Try / catch

// Fall back to importing the raw body if content conversion fails,
// so the post isn't lost entirely.
content, err := convertJekyllContent(meta, body)
if err != nil {
  log.Printf("content convert failed for %s: %v", filename, err)
  content = body // keep original Markdown
}

Prevention

When it happens

Trigger: Fires when the content converter hits a construct it cannot translate — an unsupported Jekyll/Liquid tag, a malformed include, or an error returned by a regex-based rewrite in `convertJekyllContent`.

Common situations: Jekyll posts with custom Liquid plugins (`{% tag %}`) that have no Hugo equivalent; a post using `{% include %}` with arguments the importer cannot parse; corrupted UTF-8 in the body that breaks content rewriting.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/a2697374f96b6c59. Report an issue: GitHub.

Appendix: source

Thrown at commands/import.go:332

	os.MkdirAll(targetParentDir, 0o777)

	contentBytes, err := os.ReadFile(path)
	if err != nil {
		c.r.logger.Errorln("Read file error:", path)
		return err
	}
	pf, err := pageparser.ParseFrontMatterAndContent(bytes.NewReader(contentBytes))
	if err != nil {
		return fmt.Errorf("failed to parse file %q: %s", filename, err)
	}
	newmetadata, err := c.convertJekyllMetaData(pf.FrontMatter, postName, postDate, draft)
	if err != nil {
		return fmt.Errorf("failed to convert metadata for file %q: %s", filename, err)
	}

	content, err := c.convertJekyllContent(newmetadata, string(pf.Content))
	if err != nil {
		return fmt.Errorf("failed to convert content for file %q: %s", filename, err)
	}

	fs := hugofs.Os
	if err := helpers.WriteToDisk(targetFile, strings.NewReader(content), fs); err != nil {
		return fmt.Errorf("failed to save file %q: %s", filename, err)
	}
	return nil
}

func (c *importCommand) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPostDirs map[string]bool) (err error) {
	fs := hugofs.Os

	fi, err := fs.Stat(jekyllRoot)
	if err != nil {
		return err
	}
	if !fi.IsDir() {
		return errors.New(jekyllRoot + " is not a directory")

View on GitHub (pinned to 52c9bd7908)