Skip to content

getJSON deprecated; replace with resources.Get#70

Open
whyboris wants to merge 1 commit intoloup-brun:masterfrom
whyboris:deprecate-getJSON
Open

getJSON deprecated; replace with resources.Get#70
whyboris wants to merge 1 commit intoloup-brun:masterfrom
whyboris:deprecate-getJSON

Conversation

@whyboris
Copy link
Copy Markdown

@whyboris whyboris commented May 24, 2024

getJSON is deprecated in Hugo 0.123.0 see: https://gohugo.io/functions/data/getjson/

Recommended alternative: https://gohugo.io/functions/data/getjson/#global-resource-alternative

{{ $p := "data/books.json" }}
{{ with resources.Get $p }}
  {{ $data = . | transform.Unmarshal }}
{{ else }}

Thank you for creating hugo-cite 🙇‍♂️ I am using it on https://github.com/whyboris/utilitarianism.net

I was inlining {{< cite "Singer1972" >}} over 500+ times across my markdown files and the compilation time was about 10 seconds. After moving to resources.Get the compilation is back to < 500ms 🚀

I hope you can merge in this change ❤️

⚠️ looks like the resources.Get method requires the json file to be located in /assets 🤔 so we may need modification for this to work.

@whyboris
Copy link
Copy Markdown
Author

To clarify: your current code will try to open the json file as many times as you cite -- and in my case it's a 8mb json getting opened 500+ times. With the code updated to the new Hugo method, Hugo opens the json only once and caches it for every subsequent use 🚀

@loup-brun
Copy link
Copy Markdown
Owner

Thank you for the PR. It definitely makes sense. I will try to make time to manage the state of this project in the coming weeks (such as setting up a versioning system in order to better track features/evolutions of the module).

@whyboris
Copy link
Copy Markdown
Author

I've now adapted hugo-cite into my project (see PR: whyboris/utilitarianism.net#124 if you'd like).

I love how easily-customizable the system you created is 💖 I'm messing with the styling since I don't need APA I just want references to look good (see PR: whyboris/utilitarianism.net#127 -- for more than 3 authors it instead lists first author + "et al." 😎, etc)

I'm happy to assist with this PR or your project 😄🤝😊

@tomaz-suller
Copy link
Copy Markdown

@xbc5 could you have a look at this? I tried using it but now Hugo not only produces a warning, but also an error, so you effectively can't generate the site. I'm running v0.132.2.

@tomaz-suller
Copy link
Copy Markdown

Sorry, I just realised #62 is actually from 2022, not sure if you still have the time to do it

@xbc5
Copy link
Copy Markdown
Collaborator

xbc5 commented Aug 19, 2024

Yeah, I don't have the time. I currently am working on some other things, and I haven't used Hugo in 1-2 years, so I cannot be confident about what I am merging.

loup-brun added me as a maintainer because I intended to take it on, but things have changed for me. I will be creating a Hugo project in the next month or so -- once I familiarise myself with Hugo again, perhaps I will take another look at this.

@loup-brun, you can remove me as a maintainer if you think that it's an issue.

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

Successfully merging this pull request may close these issues.

4 participants