matcornic / hugo-theme-learn

Porting Grav Learn theme to Hugo
https://learn.netlify.com/en/
MIT License
1.6k stars 1.28k forks source link

Attachments with multilingual configuration missing subdir #387

Open sebastianschauenburg opened 4 years ago

sebastianschauenburg commented 4 years ago

According to the documentation ( https://learn.netlify.com/en/shortcodes/attachments/ ) it should be possible to add attachments. When I add a subdirectory called _index.files, the attachments are displayed correctly (yay), but when I click on them, they are missing the subdirectory of the language, which results in a 404. I've tried renaming the directory to add "en" (english language code) to the directory, but it didn't help.

So I expected a http://base.url.ext/en/_index.files/attachment.pdf URL (when clicking on the attachment) but got http://base.url.ext/_index.files/attachment.pdf instead, resulting in a 404.

What am I doing wrong here, or is this perhaps a bug? (perhaps related to this, the documentation states "Be aware that if you use a multilingual website, you will need to have as many folders as languages.")

Thanks for this great theme. I've been using it for documentation for a while and it's fantastic.

tarpdalton commented 4 years ago

The problem is here: https://github.com/matcornic/hugo-theme-learn/blob/master/layouts/shortcodes/attachments.html#L13

I'm not sure how it can be fixed. Maybe if there was a better way to get the full path of the current page

muffmolch commented 4 years ago

I've got the same problem. the attachment-shortcut does not work for multi lingual projects with languages by folder... Will there be a fix?

content/de
content/en

and the attachement tries to access the folder:

\content\gs\zusatzmodule\gsmosquitto\test\files:

but it should be:

\content\de\gs\zusatzmodule\gsmosquitto\test\files:
\content\en\gs\zusatzmodule\gsmosquitto\test\files:

but maybe I want to show attachemnts of a totally different folder?

eZioPan commented 4 years ago

i find a dirty way to get the path

{{ $raw_info := printf "%v" (os.Stat .File) }}
{{ $filename_string := index (findRE "filename:.* fs:" $raw_info) 0 }}
{{ $filename_string := strings.TrimLeft "filename:" $filename_string}}
{{ $filename := strings.TrimRight " fs:" $filename_string}}
{{ $filename }}

i do think it's a vulnerability, that os.Stat expose the absolute path of the file in filesystem.

maybe better use Page Bundle instead as https://github.com/matcornic/hugo-theme-learn/issues/100 described?

tarpdalton commented 4 years ago

Here are the docs for page resources/bundles. I think it could work https://gohugo.io/content-management/page-resources/

McShelby commented 3 years ago

@muffmolch: Fixed in McShelby/hugo-theme-relearn#105