Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid index.json with multiline descriptions #517

Open
garz75 opened this issue Oct 7, 2021 · 1 comment
Open

invalid index.json with multiline descriptions #517

garz75 opened this issue Oct 7, 2021 · 1 comment

Comments

@garz75
Copy link

garz75 commented Oct 7, 2021

When using a yaml front matter with a multiline description that uses a Block Style Indicator (> or |)

---
title: Simple title
chapter: false
weight: 40
description: |
  This is the beginning of a multiline description...
---

The JSON file generated by the index.json template is invalid: The description contains a \n at the end:

[
{
        "uri": "/example.html",
        "title": "Simple title",
        "tags": [],
        "description": "This is the beginning of a multiline description...
",
        "content": "blah"
}
]

My attempt at fixing this issue is to trim the extra\n in the template:

diff --git a/layouts/index.json b/layouts/index.json
index 367f3b3..011b7c8 100644
--- a/layouts/index.json
+++ b/layouts/index.json
@@ -5,7 +5,7 @@
        "uri": "{{ $page.Permalink }}",
        "title": "{{ htmlEscape $page.Title}}",
        "tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
-       "description": "{{ htmlEscape .Description}}",
+       "description": "{{ trim .Description "\n" | htmlEscape }}",
        "content": {{$page.Plain | jsonify}}
 }
 {{- end -}}

This seems to work for me but I am very new at Hugo templating... Am I on the right track ? Is there a way to fix this in a better way ?

Thank you in Advance.

@McShelby
Copy link

McShelby commented Oct 7, 2021

Seems to work in the Relearn fork.

McShelby added a commit to McShelby/hugo-theme-relearn that referenced this issue Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants