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

Working with ox-hugo #699

Closed
dhruvparamhans opened this Issue Sep 19, 2018 · 13 comments

Comments

Projects
None yet
4 participants
@dhruvparamhans

dhruvparamhans commented Sep 19, 2018

I am having some difficulties with creating posts. I am using org-mode and then exporting the file using ox-hugo. However, I am unable to rebuild the site and receive the following error:

ERROR 2018/09/20 01:50:24 Error while rendering "home" in "": template: index.html:4:3: executing "index.html" at <partial "widget_page...>: error calling partial: template: partials/widget_page.html:23:9: executing "partials/widget_page.html" at <partial $widget $par...>: error calling partial: template: partials/widgets/posts.html:65:51: executing "partials/widgets/posts.html" at <len .Params.tags>: error calling len: len of untyped nil

Is there an incompatibility between the template that the theme uses and the output generated by ox-hugo? I tried the same approach: ox-hugo-> md -> move to content folder and didnt face the same problem.

Thanks.

@Bertbk

This comment has been minimized.

Show comment
Hide comment
@Bertbk

Bertbk Sep 20, 2018

Seems that you don't have the right version of Hugo. You need Hugo 0.48 compiled with Go 1.11 (the latest point being important). See this issue for example

Are you on Debian or Archlinux ? If yes, then the Hugo package is still not updated.

Bertbk commented Sep 20, 2018

Seems that you don't have the right version of Hugo. You need Hugo 0.48 compiled with Go 1.11 (the latest point being important). See this issue for example

Are you on Debian or Archlinux ? If yes, then the Hugo package is still not updated.

@dhruvparamhans

This comment has been minimized.

Show comment
Hide comment
@dhruvparamhans

dhruvparamhans Sep 20, 2018

I am on MacOS at the moment. On running hugo version I find that I do indeed have version 0.48 installed. Output for info:
Hugo Static Site Generator v0.48/extended darwin/amd64 BuildDate: unknown

I installed hugo via homebrew. Do I need to build hugo with Go?

dhruvparamhans commented Sep 20, 2018

I am on MacOS at the moment. On running hugo version I find that I do indeed have version 0.48 installed. Output for info:
Hugo Static Site Generator v0.48/extended darwin/amd64 BuildDate: unknown

I installed hugo via homebrew. Do I need to build hugo with Go?

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

@dhruvparamhans Can you post the Markdown file here so that someone can reproduce the issue? Looking at the error, looks like len is called on nil i.e. you don't have the post's tags set at all. I'm not sure where that len is called.

If it's in this theme, the theme needs to be fixed. But all of these are just guesses till I see the Markdown file.

kaushalmodi commented Sep 20, 2018

@dhruvparamhans Can you post the Markdown file here so that someone can reproduce the issue? Looking at the error, looks like len is called on nil i.e. you don't have the post's tags set at all. I'm not sure where that len is called.

If it's in this theme, the theme needs to be fixed. But all of these are just guesses till I see the Markdown file.

@dhruvparamhans

This comment has been minimized.

Show comment
Hide comment
@dhruvparamhans

dhruvparamhans Sep 20, 2018

Here is the markdown file generated from the org-file.

+++
title = "Test post"
author = ["Dhruv Sharma"]
draft = false
+++

## Here is a big heading {#here-is-a-big-heading}

This is some text


### Here is a sub-heading {#here-is-a-sub-heading}

This is some more text

This file is placed in the folder content/post. However, placing the file in the home folder doesn't give the same error.

dhruvparamhans commented Sep 20, 2018

Here is the markdown file generated from the org-file.

+++
title = "Test post"
author = ["Dhruv Sharma"]
draft = false
+++

## Here is a big heading {#here-is-a-big-heading}

This is some text


### Here is a sub-heading {#here-is-a-sub-heading}

This is some more text

This file is placed in the folder content/post. However, placing the file in the home folder doesn't give the same error.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

@dhruvparamhans I confirm this to be a bug in this theme.

To reproduce error

# posts.org file in the exampleSite dir in this theme
#+hugo_base_dir: .
#+hugo_section: post
#+author:

* Post 1
:PROPERTIES:
:EXPORT_FILE_NAME: post-1
:END:
Hello

Do C-c C-e H A.

You get:

+++
title = "Post 1"
draft = false
+++

Hello

and error:

ERROR 2018/09/20 09:23:44 Error while rendering "home" in "": template: index.html:4:3: executing "index.html" at <partial "widget_page...>: error calling partial: template: partials/widget_page.html:23:9: executing "partials/widget_page.html" at <partial $widget $par...>: error calling partial: template: partials/widgets/posts.html:65:51: executing "partials/widgets/posts.html" at <len .Params.tags>: error calling len: len of untyped nil

To bypass this bug

Add a tag to the post

# posts.org file in the exampleSite dir in this theme
#+hugo_base_dir: .
#+hugo_section: post
#+author:

* Post 1   :foo:
:PROPERTIES:
:EXPORT_FILE_NAME: post-1
:END:
Hello

Do C-c C-e H A.

You get:

+++
title = "Post 1"
tags = ["foo"]
draft = false
+++

Hello

and that error goes away.

@gcushen You should use {{ with .Params.tags }} instead of checking len.

kaushalmodi commented Sep 20, 2018

@dhruvparamhans I confirm this to be a bug in this theme.

To reproduce error

# posts.org file in the exampleSite dir in this theme
#+hugo_base_dir: .
#+hugo_section: post
#+author:

* Post 1
:PROPERTIES:
:EXPORT_FILE_NAME: post-1
:END:
Hello

Do C-c C-e H A.

You get:

+++
title = "Post 1"
draft = false
+++

Hello

and error:

ERROR 2018/09/20 09:23:44 Error while rendering "home" in "": template: index.html:4:3: executing "index.html" at <partial "widget_page...>: error calling partial: template: partials/widget_page.html:23:9: executing "partials/widget_page.html" at <partial $widget $par...>: error calling partial: template: partials/widgets/posts.html:65:51: executing "partials/widgets/posts.html" at <len .Params.tags>: error calling len: len of untyped nil

To bypass this bug

Add a tag to the post

# posts.org file in the exampleSite dir in this theme
#+hugo_base_dir: .
#+hugo_section: post
#+author:

* Post 1   :foo:
:PROPERTIES:
:EXPORT_FILE_NAME: post-1
:END:
Hello

Do C-c C-e H A.

You get:

+++
title = "Post 1"
tags = ["foo"]
draft = false
+++

Hello

and that error goes away.

@gcushen You should use {{ with .Params.tags }} instead of checking len.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

@dhruvparamhans

This file is placed in the folder content/post. However, placing the file in the home folder doesn't give the same error.

That makes sense because grepping for len \.Params\.tag yields results showing this issue only in posts.html which I assume is used only for posts in content/post/:

layouts/partials/widgets/posts.html:34:52:        {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
layouts/partials/widgets/posts.html:65:52:        {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}

kaushalmodi commented Sep 20, 2018

@dhruvparamhans

This file is placed in the folder content/post. However, placing the file in the home folder doesn't give the same error.

That makes sense because grepping for len \.Params\.tag yields results showing this issue only in posts.html which I assume is used only for posts in content/post/:

layouts/partials/widgets/posts.html:34:52:        {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
layouts/partials/widgets/posts.html:65:52:        {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

@gcushen

Here's the proposed fix:

diff --git a/layouts/partials/widgets/posts.html b/layouts/partials/widgets/posts.html
index c2cea39..21e40b9 100644
--- a/layouts/partials/widgets/posts.html
+++ b/layouts/partials/widgets/posts.html
@@ -31,8 +31,10 @@
                 {{ $.Scratch.Set "show_post" "1" }}
 
                 {{/* If `tags_include` is set, exclude posts with no tags. */}}
-                {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
-                    {{ $.Scratch.Set "show_post" "0" }}
+                {{ with (not .Params.tags) }}
+                    {{ with $page.Params.tags_include }}
+                        {{ $.Scratch.Set "show_post" "0" }}
+                    {{end}}
                 {{end}}
 
                 {{/* If `tags_exclude` is set, exclude posts. */}}
@@ -62,8 +64,10 @@
                 {{ $.Scratch.Set "show_post" "1" }}
 
                 {{/* If `tags_include` is set, exclude posts with no tags. */}}
-                {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
-                    {{ $.Scratch.Set "show_post" "0" }}
+                {{ with (not .Params.tags) }}
+                    {{ with $page.Params.tags_include }}
+                        {{ $.Scratch.Set "show_post" "0" }}
+                    {{end}}
                 {{end}}
 
                 {{/* If `tags_exclude` is set, exclude posts. */}}

Aside: I see a lot of $.Scratch.Set use. As the minimum requirement for your theme is anyways 0.48, you might as well use the new variable re-assignment operator = and get rid of that Scratch cruft :)

kaushalmodi commented Sep 20, 2018

@gcushen

Here's the proposed fix:

diff --git a/layouts/partials/widgets/posts.html b/layouts/partials/widgets/posts.html
index c2cea39..21e40b9 100644
--- a/layouts/partials/widgets/posts.html
+++ b/layouts/partials/widgets/posts.html
@@ -31,8 +31,10 @@
                 {{ $.Scratch.Set "show_post" "1" }}
 
                 {{/* If `tags_include` is set, exclude posts with no tags. */}}
-                {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
-                    {{ $.Scratch.Set "show_post" "0" }}
+                {{ with (not .Params.tags) }}
+                    {{ with $page.Params.tags_include }}
+                        {{ $.Scratch.Set "show_post" "0" }}
+                    {{end}}
                 {{end}}
 
                 {{/* If `tags_exclude` is set, exclude posts. */}}
@@ -62,8 +64,10 @@
                 {{ $.Scratch.Set "show_post" "1" }}
 
                 {{/* If `tags_include` is set, exclude posts with no tags. */}}
-                {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
-                    {{ $.Scratch.Set "show_post" "0" }}
+                {{ with (not .Params.tags) }}
+                    {{ with $page.Params.tags_include }}
+                        {{ $.Scratch.Set "show_post" "0" }}
+                    {{end}}
                 {{end}}
 
                 {{/* If `tags_exclude` is set, exclude posts. */}}

Aside: I see a lot of $.Scratch.Set use. As the minimum requirement for your theme is anyways 0.48, you might as well use the new variable re-assignment operator = and get rid of that Scratch cruft :)

@gcushen

This comment has been minimized.

Show comment
Hide comment
@gcushen

gcushen Sep 20, 2018

Owner

It appears that this third party tool does not respect Academic's archetypes (content templates)... If the appropriate data structure from the archetypes is used, there are no issues.

Owner

gcushen commented Sep 20, 2018

It appears that this third party tool does not respect Academic's archetypes (content templates)... If the appropriate data structure from the archetypes is used, there are no issues.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

@gcushen It's less problem with the use of third party tool.

So a user has to use the theme archetype to make the theme work?

If a user manually types the following in content/post/foo.md:

+++
title = "Post 1"
draft = false
+++

Hello

they will get the same error.

My proposal fixes that issue in the current template.

kaushalmodi commented Sep 20, 2018

@gcushen It's less problem with the use of third party tool.

So a user has to use the theme archetype to make the theme work?

If a user manually types the following in content/post/foo.md:

+++
title = "Post 1"
draft = false
+++

Hello

they will get the same error.

My proposal fixes that issue in the current template.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 20, 2018

The Hugo archetypes are a convenience feature.. they should not be made mandatory for the layouts to work.

Also looks like the fix is simple. Your archetypes simply force add an empty tags = [] (and many other things). The proposed fix doesn't need one to have an empty tags = [].

kaushalmodi commented Sep 20, 2018

The Hugo archetypes are a convenience feature.. they should not be made mandatory for the layouts to work.

Also looks like the fix is simple. Your archetypes simply force add an empty tags = [] (and many other things). The proposed fix doesn't need one to have an empty tags = [].

@gcushen

This comment has been minimized.

Show comment
Hide comment
@gcushen

gcushen Sep 20, 2018

Owner

Thank you for refactoring the code to make it optional for users to use the archetype (content template), such as via hugo new post. I have just pushed the change.

My point is that Hugo itself always uses archetypes as templates for creating new content. It helps to form a consistent user experience if third party tools respect and align with this principle.

Aside: I see a lot of $.Scratch.Set use. As the minimum requirement for your theme is anyways 0.48, you might as well use the new variable re-assignment operator = and get rid of that Scratch cruft :)

Yes, this is the reason why we updated the framework to use Hugo v0.48 - some code is now written in this form :) Although, no one has yet retrospectively refactored older code to use the more concise form, so feel free to contribute if you like.

Owner

gcushen commented Sep 20, 2018

Thank you for refactoring the code to make it optional for users to use the archetype (content template), such as via hugo new post. I have just pushed the change.

My point is that Hugo itself always uses archetypes as templates for creating new content. It helps to form a consistent user experience if third party tools respect and align with this principle.

Aside: I see a lot of $.Scratch.Set use. As the minimum requirement for your theme is anyways 0.48, you might as well use the new variable re-assignment operator = and get rid of that Scratch cruft :)

Yes, this is the reason why we updated the framework to use Hugo v0.48 - some code is now written in this form :) Although, no one has yet retrospectively refactored older code to use the more concise form, so feel free to contribute if you like.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 21, 2018

Thank you for refactoring the code to make it optional for users to use the archetype (content template), such as via hugo new post. I have just pushed the change.

Awesome! Thank you.

@dhruvparamhans Please verify and close this issue.

My point is that Hugo itself always uses archetypes as templates for creating new content. It helps to form a consistent user experience

I respect that you use archetypes for users doing hugo new post/foo.md. But that shouldn't result in layout design causing errors like in this issue.

Look at this from a different angle. With this bug still not fixed, people wouldn't have been able to switch theme to this one easily even if one of their post missed tags = []. That's a major layout bug.

To Hugo, having tags = [] is the exact same as not having tags in the first place. The layouts should respect that too.

if third party tools respect and align with this principle.

The thing is that the third party (the Emacs ox-hugo package in this case) does not need archetypes at all. A lot of meta-data is auto-inferred from the Org mode structure. In essence, ox-hugo obsoletes Hugo archetypes for Org mode users.

Yes, this is the reason why we updated the framework to use Hugo v0.48 - some code is now written in this form :) Although, no one has yet retrospectively refactored older code to use the more concise form, so feel free to contribute if you like.

Glad to hear that. I don't use this theme, but I am happy to help with Go Templating syntax like in this issue when needed.

kaushalmodi commented Sep 21, 2018

Thank you for refactoring the code to make it optional for users to use the archetype (content template), such as via hugo new post. I have just pushed the change.

Awesome! Thank you.

@dhruvparamhans Please verify and close this issue.

My point is that Hugo itself always uses archetypes as templates for creating new content. It helps to form a consistent user experience

I respect that you use archetypes for users doing hugo new post/foo.md. But that shouldn't result in layout design causing errors like in this issue.

Look at this from a different angle. With this bug still not fixed, people wouldn't have been able to switch theme to this one easily even if one of their post missed tags = []. That's a major layout bug.

To Hugo, having tags = [] is the exact same as not having tags in the first place. The layouts should respect that too.

if third party tools respect and align with this principle.

The thing is that the third party (the Emacs ox-hugo package in this case) does not need archetypes at all. A lot of meta-data is auto-inferred from the Org mode structure. In essence, ox-hugo obsoletes Hugo archetypes for Org mode users.

Yes, this is the reason why we updated the framework to use Hugo v0.48 - some code is now written in this form :) Although, no one has yet retrospectively refactored older code to use the more concise form, so feel free to contribute if you like.

Glad to hear that. I don't use this theme, but I am happy to help with Go Templating syntax like in this issue when needed.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Sep 21, 2018

@gcushen Do you want to add a simple test case like:

+++
title = "Post 1"
draft = false
+++

Hello

to ensure that the problem is not repeated?

kaushalmodi commented Sep 21, 2018

@gcushen Do you want to add a simple test case like:

+++
title = "Post 1"
draft = false
+++

Hello

to ensure that the problem is not repeated?

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