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

Feature: GetJson and GetCsv in short codes or other layout files. #748

Closed

Conversation

SchumacherFM
Copy link
Contributor

I have finished the integration of getJson and getCsv into hugo as far as I think it fits.

I'm not a hugo (and Go) expert of where to put these functions and correct naming of functions and vars.

I would be glad if you can comment on spotted errors, bugs, bad design, etc. or even help me to improve the code more.

All tests and the new tests are passing. Goimports has reordered some import paths.

I have written a blog post about that new feature: http://cyrillschumacher.com/2014/12/21/dynamic-pages-with-gohugo.io/

There is not yet any official documentation because I want to get the code right. I think once this feature is merged as a hidden feature into hugo and some people tested it in the wild with no given complaints I will write the docs.

Looking forward for a successful merge :-)

@bep
Copy link
Member

bep commented Dec 27, 2014

There are som failing tests on Windows. See the AppVeyor details above.

@SchumacherFM
Copy link
Contributor Author

Fixed

@bep
Copy link
Member

bep commented Dec 29, 2014

I guess @spf13 will chime in, but my first thoughts:

I love the simplicity of this approach. I know I was the one who wanted a cache for the remote resources, and I still believe that is important.

But I had a hope that there was a third-party Go cache libraries out there to use -- cause I would like that my cache entries was evicted and refreshed at some point (I want fresh content - but not on every livereload).

Other than that, this looks great -- a feature I look forward to use.

@bep
Copy link
Member

bep commented Dec 29, 2014

@ahsanulhaque You are the editor (or something) of the gopheracademy and have seen a lot of blog articles floating by - any good Go caching library out there?

@ghost
Copy link

ghost commented Dec 29, 2014

Hey, it really depends on what kind of caching you're trying to achieve. This is a fairly popular library and I've seen it used in many cool ways. I would probably write something minimal and use Redis.

@SchumacherFM
Copy link
Contributor Author

IMHO it would be easier to add a 2nd integer parameter to getJson/getCsv which specifies the cache validity in seconds.

  • < 0 means no caching
  • 0 means cache is unlimited time valid (or until you remove the files)
  • all other values > 0 are the seconds for being valid.
    The cache func only checks the file creation date and that's it.

@spf13
Copy link
Contributor

spf13 commented Dec 29, 2014

I like the idea of caching it.
I want to keep it really REALLY simple.
No external dependencies.

My thoughts are using a tmp/ directory or cache/.

  • It's really easy to invalidate (rm -rf cache/)
  • No external dependencies
  • No complicated libraries/logic
  • Lasts longer than a single process (really important)

We should add a setting --ignoreCache or something if we go this route.

We can also in the future easily build in some expiration functionality if we start here. It's easy enough to check the mtime on the file and choose not to use it.

This does mean that we do need to wrap all external calls to check cache first. There's probably a number of places where a cache would be helpful if we sit down and think about it.

@thomasmodeneis
Copy link

+1.
That will be great value for me, thank you all.

@bep
Copy link
Member

bep commented Jan 6, 2015

@spf13 I feel the API here is pretty set in stone (simple and clear). There may be stuff to improve on caching and documentation, but there are arguments to pull it in as a "silent feature" for a while ... to play with it and get a feeling.

@derekperkins
Copy link
Contributor

👍 Great idea!

@SchumacherFM
Copy link
Contributor Author

I should resolve the merge conflict and add the option --ignoreCache OR instead of introducing another CLI flag if --cacheDir has been omitted or --cacheDir=false then no caching. Hmm ...

@SchumacherFM
Copy link
Contributor Author

I've added the option ignoreCache, fixed a bug when the cache folder didn't exists and also rebased my branch with the current commits from master.

@thomasmodeneis
Copy link

up !
sorry to disturb,
any project collaborators up to do this merge? o/
thank you

@thomasmodeneis
Copy link

I have it running with the fork github.com/SchumacherFM/hugo.

But the url I want to call is composed with prefix + id + sufix
The problem is that I can not make it work a way to concatenate vars with hugo:

{{ $id := .Params._id }}
{{ $url_pre :=  "http://localhost:3000/db/persons/" }}
{{ $url_post := "/limit/10/skip/0" }}
{{ $finalurl  := $url_pre + $id + $url_post }}
 {{ $gistJ := getJson $finalurl }}
{{range first 5 $gistJ }}
<li><a href="#" target="_blank">{{.name}}</a></li>
{{end}}

Is there a way to concatenate vars to build this composed url ??
Thank you.

@bep
Copy link
Member

bep commented Feb 7, 2015

printf - see a recent discussion in the forum.

@SchumacherFM
Copy link
Contributor Author

I've just started writing and ... how should I name the new page in the docs?

Dynamic Content

Is my current favourite but not really a nice one. Has someone a better idea = name?

@thomasmodeneis
Copy link

Dynamic Pages is how they call it on Middleman.

@spf13
Copy link
Contributor

spf13 commented Feb 12, 2015

I like dynamic content

@SchumacherFM
Copy link
Contributor Author

Documentation has been added!

SchumacherFM@4cd023c

Please report any weird stuff and also if it is ok to include future features (people will get more excited about hugo 😋 )

@bep
Copy link
Member

bep commented Feb 15, 2015

The documentation should be about the current feature-set. Nobody knows what the future brings.

@SchumacherFM
Copy link
Contributor Author

Moved it to another branch. Anything else ok?

@spf13
Copy link
Contributor

spf13 commented Feb 18, 2015

I've merged this in. Excellent contribution @SchumacherFM. Looking forward to more.

@spf13 spf13 closed this Feb 18, 2015
@SchumacherFM
Copy link
Contributor Author

cheering_minions

Awesome! More stuff is coming.

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants