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

Beginners Question: is grav an SSG? #516

Closed
ursbraem opened this issue Dec 10, 2015 · 29 comments

Comments

Projects
None yet
7 participants
@ursbraem
Copy link

commented Dec 10, 2015

Hi
I am new to grav, found the link to grav on https://staticsitegenerators.net/
But is it an SSG in the sense that it can CREATE static sites?
Means, can it stage an entire site to a target directory that can run without php?
If so, how? Or, with which additions?
Or is the "static" element in grav just referring to it basing on flat files?
Thanks a lot for clearing that up!
Urs

@flaviocopes

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2015

Hi, no Grav is not a static site generator, it requires PHP to run. Not sure how it ended up in that list, we mention "static" nowhere on our site.

Grav is a Flat-File CMS, which has great advantages over static site generators, but of course everyone has different needs and each tool has its place.

@rhukster

This comment has been minimized.

Copy link
Member

commented Dec 10, 2015

Correct Grav is not an Static Site Generator, although this list does also list Flat File CMSes.

Grav is 100% file based, but not static. You do need PHP to run it. But you get the benefits of a dynamic CMS with near static performance, syncing, security, etc.

https://github.com/bevry/staticsitegenerators-list

Requirements for additions

There are generally three types of Content Management Systems:

Dynamic Servers (e.g. WordPress, Ghost, DocPad, Harp) — these allow you to have re-render on every request abilities
Flat File CMS (e.g. Yellow, Techy) — these allow you to write your content as files
Static Site Generators (e.g. Jekyll, DocPad) — these generate a static website from your input that you can deploy anywhere
Currently, this listing is only for projects that are either a Flat File CMS and/or Static Site Generator, but not for projects which are only Dynamic Servers (such as WordPress and Ghost).

@rhukster rhukster closed this Dec 10, 2015

@ursbraem

This comment has been minimized.

Copy link
Author

commented Dec 11, 2015

Thanks for clearing that up!

@corysimmons

This comment has been minimized.

Copy link

commented Oct 3, 2016

Thoughts on adding some sort of build step for static generation?

@flaviocopes

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2016

We have no plans for static generation, because you really lose the power that Grav provides.

That said, you can grab a static copy of the site with a simple wget run on your site, and publish it where you want.

@corysimmons

This comment has been minimized.

Copy link

commented Oct 4, 2016

I think that's a common argument: "if we provide an option for X then it doesn't promote all the magical power/conventions we worked hard on/think are right!"

I feel ya, but if it's as easy as providing a CLI flag to generate a static site... why not give people that kind of power and let them decide when they need all of Grav's sugar, and when they just want to use it for templating or something simple?

This comment thread https://www.smashingmagazine.com/2015/11/modern-static-website-generators-next-big-thing/#comment-1284851 would lead me towards something like Statamatic since it gives me the freedom to use whatever approach seems most appropriate at the time.

Grav looks cool/powerful/well thought out. I'd like to use it for a plethora of things, but I'd like to dip my toes in via SSG.

@w00fz

This comment has been minimized.

Copy link
Member

commented Oct 4, 2016

I thinks the point flavio is making is that SSG is outside the scope of Grav, that said this is still very much possible with Grav's API. Would actually make for a great plugin if anyone is interested.

@Perlkonig

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2016

As mentioned, you could do a CURL scrape of your Grav site and host that wherever. That would be static. This doesn't really work with the current plugin structure because the CLI can't access/scan the site (see Issue #1074). It would have to be triggered by a page view, which seems wrong 😄

@w00fz

This comment has been minimized.

Copy link
Member

commented Oct 4, 2016

A plugin can also just contain CLI command.
This plugin CLI would just do its curl and scrape the site to generate it statically.
The beauty of this would be that you don't have to leave the Grav environment and you could just run it (even via cronjob) through grav/plugin yourplugin static

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

I will make one if no one beats me to it :)

@Perlkonig

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

Go for it 😄

@w00fz

This comment has been minimized.

Copy link
Member

commented Oct 5, 2016

This is conceptually very similar in the way I built the getgrav.org repository by the way.
We have a CLI in a custom private plugin that runs an external class to gather informations and put together all the plugins and themes that are then available to you through GPM. The CLI command is then crontabbed to run periodically and always serve fresh data.

It's probably a bit more complex than what a static site generator would be but the principle is the same, we use the GitHub APIs to collect and make all the data available through the site for consumption.

Thanks to the fact that this runs as a Grav Plugin we then have all the details we need to populate the downloads page, all for free.

@flaviocopes

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

@corysimmons well nothing prevents you to use Grav to make a static site. I'm super happy if anyone starts a plugin to use it like that, I too have some sites that are just static and could benefit from such approach 😃 . We just never considered this to be included in the core. What you lose really is just the ability to use forms or the login system or any other plugin that relies on php-based interactivity, which not all sites need.

@corysimmons

This comment has been minimized.

Copy link

commented Oct 5, 2016

What you lose really is just the ability to use forms or the login system or any other plugin that relies on php-based interactivity, which not all sites need.

Right, I feel ya. I'd like to use Grav for templating and stuff for static sites (gh-pages, Netlify, etc.), then if I need forms and such, I can easily convert it to a nice lightweight PHP site.

#516 (comment) Sweeet. Ping me when a repo is ready if you don't mind. I might be able to prettify it with colors or something silly (if you're interested in that kinda thing).

#516 (comment)

Is the CLI on Github or completely private for some reason? I'd be interested in just seeing all the stuff it does. /shrug =)

@flaviocopes

This comment has been minimized.

@w00fz

This comment has been minimized.

Copy link
Member

commented Oct 5, 2016

Is the CLI on Github or completely private for some reason? I'd be interested in just seeing all the stuff it does. /shrug =)

The CLI for plugins is part of the Grav's API and available to the developer as flavio pointed out above.
The repository generator plugin we created is private and we cannot share that for security reasons but I'm more than happy to guide you and help if you have any questions.

@corysimmons

This comment has been minimized.

Copy link

commented Oct 5, 2016

@w00fz No thnx. I just get curious about all the things. 🐱

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

In working on this plugin, I'm learning to use the API for the first time to call all pages. For starters, I've tried a dozen different things and thought if I asked for help, I might get some clarity. Here's a snippet of my serve function. I've loaded Page/Pages at the top so I think I'm doing it right.

    protected function serve()
    {
        $this->output->writeln(Pages::all());
    }
}

This outputs

Fatal error: Call to undefined method Grav\Plugin\Console\BuildCommand::root() in /grav/system/src/Grav/Common/Page/Pages.php on line 433

I figured it may be because I have to put something inside of all() but everything I've tried to pass errors.

@Perlkonig

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

See issue #1074. It's not possible. I can initialize the URL as described in that issue, but I haven't had time to figure out how to initialize the rest of the Grav object.

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2016

Oh cool, well I'll find another way then.

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2016

https://github.com/barryanders/grav-plugin-blackhole

Here's a plugin that does exactly what you all were talking about.

bin/plugin blackhole generate BUILD_DIR so you can run Grav wherever you want and build wherever you want and Crontab that sucker so you don't ever have to manually build again.

Feel free to check it out, make changes or whatever. I don't expect that it's optimized, nor would I call it extremely secure, but I can say that it works efficiently at least in my test cases and I'm happy with the result in a short amount of time.

Hope you enjoy! I'll let it sit for a few days and if I don't hear anything crazy off with it, then I'll submit it to be added to Grav's official GPM.

@Perlkonig

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2016

But routes() doesn't include the taxonomy links like tag:Linux or category:blog. A proper web scrape needs to scan for all clickable links. Ideally we'd get the CLI module to a place where it can actually generate pages, at which point you could get the rendered HTML and process that.

All that said, there's really no need for a plugin to do a web scrape. You can use command-line tools, like wget:

$ wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains my.website.com \
     --no-parent \
         my.website.com

Even then, you'd still need to do some rewriting to make sure all the relative and absolute links work. Grav already has excellent caching. You're not going to save much by "static-ifying" a Grav site. If you really need a proper static site, then I would find a tool specifically designed for that.

@ursbraem

This comment has been minimized.

Copy link
Author

commented Oct 7, 2016

Without knowing grav well, I'm quite positive that the list of URLs to be
scraped shouldn't depend on scanning the actual pages, but come from the
CMS. So the CMS should be able to "know" which static pages it will produce
in order to be a real SSG. Or isn't that necessary?

@Perlkonig

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2016

That's my point. Grav is not an SSG. It does not purport to be. I was just commenting on the plugin @barryanders submitted. If you want an true SSG, I suggest finding a tool that's actually designed to do that.

@ursbraem

This comment has been minimized.

Copy link
Author

commented Oct 7, 2016

@Perlkonig yes – I was referring to the plugin, which should get a list of URLs to scrape from the CMS. Thanks for the link!

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2016

Ah yes, I hadn't checked whether or not routes covers every last thing, so thanks for that. It's true that you could just use wget, for sure. I mostly made this because of the interest in it above in this thread. I thought it might be fun to tinker around with it. StaticGen definitely already has a good list of things designed specifically for SSG. Anyway, I'll look into getting the other page possibilities some time. Thanks for the feedback.

@corysimmons

This comment has been minimized.

Copy link

commented Oct 7, 2016

FWIW, wget is extremely finicky and almost never generates an exact mirror of a site. I'm still interested in this functionality.

Other SSG's aren't as powerful as Grav. I'd appreciate being able to build a SS in Grav, and when/if I need more power, simply being able to add that power on top, tinker with my host, and everything JustWorks™.

Whereas if I make my site with a SSG like Jekyll or something, then decide I need more power and would like to migrate to Grav, I would essentially have to rewrite a huge part of my codebase.

I'm aware Grav wasn't built to compete in this space, and it is already very optimized, but if there is an elegant way to do this, it'd be really nice to have. It'd be really nice to just work exclusively in Grav for stuff rather than spreading skills across some SSG and Grav.

I also think this kind of "easily add power when you need it" approach would really set Grav apart in the SSG ecosystem.


@barryanders

$event_horizon

image

@BarryMode

This comment has been minimized.

Copy link
Contributor

commented Oct 8, 2016

After looking into the API a little more, I'm not sure how I would collect links to each taxonomy right off the bat. Perhaps some sort of findTaxonomy('poop') nonsense. Routes is sufficient for pages at least. If that's all you're using it for, then this plugin does the job, I'd say. I'll continue to rewrite it a bit to improve the quality.

@corysimmons lol, I know that was pretty dorky of me to throw that in there, but I'm glad someone appreciated it. I suppose the advantage OVER wget is if taken the time, Grav could be used to spit out the exact layout of the site.

Now where this gets into trouble is if someone is defining regex links. That's where I'll let someone else add the functionality if they need it :P in which case they'd probably just use another method instead, like @Perlkonig said.

@corysimmons

This comment has been minimized.

Copy link

commented Oct 8, 2016

I think I'm going to go ahead and make a portfolio site with Grav. Once I'm more familiar with the entire thing I'll take a swing at it as well. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.