nekr0z
February 20, 2024, 7:14am
1
I have a plain txt file as a global resource. Up to 0.122 I was able to resources.Get
it and use its content as a string.
With 0.123.0 I get
ERROR failed to load data: failed to load data: "/home/user/website/assets/data/mystring.txt:1:1": unmarshal of format "" is not supported
Is this expected? How do I load a txt
from now on?
Are you calling its content method? Please post your code.
nekr0z
February 20, 2024, 7:58am
3
Yes, I am using the Content method, exactly as the documentation suggests :
{{- $mail_text := resources.Get (printf "data/comment.%s.txt" .Site.Language.Lang) -}}
{{- $mail_body := $mail_text.Content -}}
{{- $mail_body = replace $mail_body " " "%20" -}}
{{- $mail_body = replace $mail_body "\n" "%0D%0A" -}}
{{- $mail_id := replace ( .RelPermalink | strings.TrimPrefix "/en" ) "/" "%2F" -}}
{{- $mailto_link := (printf `mailto:comment@evgenykuznetsov.org?In-Reply-To=%s&subject=%s&body=%s` ($mail_id | safeURL) ( (printf `Re: %s` ( .RelPermalink | strings.TrimPrefix "/en" )) | safeURL ) ( $mail_body | safeURL )) -}}
{{- $mailto := (printf `<a href="%s" title="%s">%s</a>` $mailto_link (T "send_comment_email") (T "by_email") | safeHTML) -}}
I am unable to reproduce the problem as described, so I must be missing something:
git clone --single-branch -b hugo-forum-topic-48365 https://github.com/jmooring/hugo-testing hugo-forum-topic-48365
cd hugo-forum-topic-48365
hugo
Expected console output from the above:
WARN The content of the text file is:
WARN This is the content of assets/data/comment.en.txt.
structure
assets/
└── data/
└── comment.en.txt
layouts/_default/home.html
{{ warnf "The content of the text file is:" }}
{{ warnf (resources.Get (printf "data/comment.%s.txt" .Site.Language.Lang)).Content }}
Tested with hugo v0.123.0-3c8a471390
nekr0z
February 20, 2024, 8:47pm
5
You are right, it seems to be unrelated.
I get the same error even if I remove this code, as long as I leave the txt file in place. I have even tried removing all the Unmarshal
and unmarshal
calls in my whole code, but the error keeps popping up.
Will try to investigate more tomorrow.
Where is the text file located? Did you place it, or a copy of it, in the data directory by mistake?
Or have you mounted assets/data to data, or something like that?
nekr0z
February 21, 2024, 7:57pm
7
The text file is in assets/data
, and there only (and that’s the path in the error message). And no, that path isn’t mounted elsewhere, at least as far as hugo config
is aware.
I will dig deeper into this as soon as I have time.
I asked the previous questions because I can generate this error…
ERROR Rebuild failed: failed to load data: “/home/user/project/data/foo.txt:1:1”: unmarshal of format “” is not supported
…by placing any text file in the project’s data directory, and then calling {{ .Site.Data }}
from any template.
nekr0z
February 22, 2024, 6:04pm
9
Indeed, the call to .Site.Data
is the one that triggers the error. However, I’m sure that assets/data
is not mounted to data
.
Also, moving the offending txts to assets
(i.e. one level up) and changing the template respectively is a viable workaround.
What’s in the project/data folder?
nekr0z
February 22, 2024, 6:27pm
11
Oh, there’s a mes.yaml
that is used in date formatting. The YAML has month numbers with corresponding Russian names in proper declination, and I have a partial that looks like:
{{- if eq .ctx.Site.Language.Lang "ru" -}}{{ .date.Day }} {{ index .ctx.Site.Data.mes ( printf "%d" .date.Month ) }} {{ .date.Year }}{{- else -}}{{ .date.Format (.ctx.Site.Params.dateformat | default "Jan 02, 2006") }}{{- end -}}
I then call it somewhat like (partial "properdate" (dict "date" $date "ctx" $))
from various places where I need date properly formatted.
Can you share that file, or find someway of testing if there’s something about that file…
nekr0z
February 22, 2024, 6:51pm
13
Here it is in full:
1: "января"
2: "февраля"
3: "марта"
4: "апреля"
5: "мая"
6: "июня"
7: "июля"
8: "августа"
9: "сентября"
10: "октября"
11: "ноября"
12: "декабря"
No, that’s fine. If you can share your repo (privately if you wish) that would help.
nekr0z
February 22, 2024, 7:04pm
15
TBH, the theme is a mess that needs a heavy refactor I’ve been meaning to perform for a couple of years now, so I’m simply ashamed to do that.
1 Like
nekr0z
February 23, 2024, 2:30pm
16
Now that you have access, you can git revert 39e7ead8a
and have a repro, if you feel so inclined.
I found the problem. Will log an issue shortly.
https://github.com/gohugoio/hugo/issues/12133
1 Like
system
Closed
February 25, 2024, 4:02pm
18
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
This was fixed in v0.123.6 .
1 Like