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

CSV Table not found with i18n #2906

Closed
2 tasks done
jbsilva opened this issue Jan 14, 2023 · 5 comments
Closed
2 tasks done

CSV Table not found with i18n #2906

jbsilva opened this issue Jan 14, 2023 · 5 comments

Comments

@jbsilva
Copy link

jbsilva commented Jan 14, 2023

Preliminary Checks

Description

Relative paths as done in the documentation don't work in multi-language websites.

Reproduction Link

https://github.com/jbsilva/starter-hugo-academic

Steps to Reproduce

  1. Clone the starter-hugo-academic repo
  2. Create i18n directory with the en.yaml file
  3. Move all content to content/en
  4. Uncomment contentDir: content/en in config/_default/languages.yaml
  5. Run hugo server

Expected Result

Hugo should build the website correctly and recognize that results.csv is under content/en/.

The correct path would be content/en/post/writing-technical-content/results.csv

Actual Result

hugo server --disableFastRender
Start building sites … 
hugo v0.109.0+extended linux/amd64 BuildDate=unknown
ERROR 2023/01/14 01:33:16 Failed to get CSV resource "content/post/writing-technical-content/results.csv": open /home/user/starter-hugo-academic/content/post/writing-technical-content/results.csv: no such file or directory

What Hugo Module versions does your site use?

github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy-plugin-reveal v1.0.0 // indirect
github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5 v5.7.1-0.20221127215619-58b270a3e103

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

Firefox

Which Wowchemy template are you using?

Academic

What version of Hugo are you using?

hugo v0.109.0+extended

@github-actions
Copy link

This issue is stale because it has not had any recent activity. The resources of the project maintainers are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the main branch, consider contributing a Pull Request with a fix.

If this is a feature request, and you feel that it is still relevant and valuable, consider contributing a Pull Request for review.

This issue will automatically close soon if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 13, 2023
@jbsilva
Copy link
Author

jbsilva commented Feb 13, 2023

Unfortunately, looks like #2919 did not solve this issue.

@github-actions github-actions bot removed the stale label Feb 14, 2023
@Agos95
Copy link
Contributor

Agos95 commented Feb 19, 2023

Hi, I did some test, and maybe I came up with something.
I tell you what I did, and if you can replicate it, maybe I think about opening a PR (there is a problem in Wowchemy table shortcode, but there are also some a bit obscure configurations needed by Hugo):

  • you need to add at least a second language in config/_default/languages.yaml, even if you are not actually using it. For example you need to have something like:
# Default language
en:
  languageCode: en
  contentDir: content/en
# At least another language, even if you do not use that
it:
  languageCode: it
  contentDir: content/it

If you just have one language, instead of making path like content/en/post/..., Hugo uses content/post/..., which breaks relative path for csv files

  • change this line in config/_default/config.yaml to:
defaultContentLanguageInSubdir: true

This ensures that even paths for the default language arte constructed under the appropriate subfolder (en in this case)

  • Wowchemy table shortcode needs to be fixed to work with multilingual (error is in this line). Create a file layouts/shortcodes/table.html in your website folder to override the default template with this content:
{{/* Table Shortcode for Wowchemy. */}}
{{/* Load a CSV table from page dir falling back back to remote URL */}}
{{/* Defaults to expecting a comma-separated CSV with a header row. */}}

{{/*
    Docs: https://wowchemy.com/docs/content/writing-markdown-latex/#csv-table

    Parameters
    ----------
    src :
        Path or url to the csv table. Path is relative to the folder where the shortcode is called.
    delimiter : default ","
        Field delimiter.
    header : default "true"
        If "true", the first row is rendered as the header.
    caption : optional
        Caption for the table.
*/}}

{{ $src := .Get "path" }}
{{ $delimiter := .Get "delimiter" | default "," }}
{{ $useHeaderRow := (eq (lower (.Get "header")) "true") | default true }}
{{ $caption := .Get "caption" }}

{{ $is_remote := strings.HasPrefix $src "http" }}
{{ if not $is_remote }}
  {{ $src = path.Join  "content" $.Page.RelPermalink $src }}
{{ end }}
{{ $rows := getCSV $delimiter $src }}

<table class="table">
  {{ if $useHeaderRow }}
    {{ $headerRow := index $rows 0 }}
    {{ $rows = after 1 $rows }}
    <tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
  {{ end }}
  {{ range $rows }}
    <tr>
      {{ range . }}
        {{ if (findRE "^\\d+$" .) }}
          <td data-table-dtype="number">{{ . }}</td>
        {{ else }}
          <td data-table-dtype="text">{{ . | markdownify | emojify }}</td>
        {{ end }}
      {{ end }}
    </tr>
  {{ end }}
  {{ if $caption }}
    <caption>{{ $caption | markdownify | emojify }}</caption>
  {{ end }}
</table>

I changed $.Page.File.Dir, which does not account for the language subfolder, with $.Page.RelPermalink.

Let me know if this helps you!

@jbsilva
Copy link
Author

jbsilva commented Mar 8, 2023

  • Wowchemy table shortcode needs to be fixed to work with multilingual (error is in this line). Create a file layouts/shortcodes/table.html in your website folder to override the default template with this content: ...

Unfortunately this did not work here.

I also tried something like the following without success:
{{ $resource := (.Resources.ByType "text").GetMatch src }}

@github-actions
Copy link

github-actions bot commented Apr 8, 2023

This issue is stale because it has not had any recent activity. The resources of the project maintainers are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the main branch, consider contributing a Pull Request with a fix.

If this is a feature request, and you feel that it is still relevant and valuable, consider contributing a Pull Request for review.

This issue will automatically close soon if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants