OleVik / grav-plugin-static-generator

Indexing and static generation of Page(s) for Grav.
MIT License
22 stars 1 forks source link

What does "Use plugin's JavaScript in Admin" mean? #7

Closed SteveMcArthur closed 4 years ago

SteveMcArthur commented 4 years ago

What does "Use plugin's JavaScript in Admin" mean ?

The site.generator.admin.js seems to do something with a "toaster" notification. But I've never seen this.

SteveMcArthur commented 4 years ago

OK - I think the toaster pops up when you click the lightning bolt on the quick menu.

OleVik commented 4 years ago

Yes, this option basically includes the plugin's own JavaScript. This enables the mechanisms for quick indexing, and will also be used for generation in v2.0.0. They are necessary for interactivity in Admin, and the toasters you've noticed is the plugin reporting on the process of indexing through a task in Admin.

As explained, indexing and generation are two distinct tasks. The interface for generating from Admin is upcoming, but so far has some limitations because of how Admin is structured. Until further notice, generation of static Pages is only facilitated through the CLI. Indexing creates a structured set of data for searching.

SteveMcArthur commented 4 years ago

Hi @OleVik

Thanks for your response.

I was going to raise another issue with regards to generating static pages through the Admin.

I have actually had a go at trying to hack your code to get static generation working through the Admin. I thought the major problem would be circumventing your CLI output code. But I was wrong.

I hacked the GenerateStaticPageCommand.php as far as the serve function goes :

protected function serve(): void
    {
        include __DIR__ . '/../vendor/autoload.php';
        $config = Grav::instance()['config']->get('plugins.static-generator');
        $buildpath = realpath(GRAV_ROOT . '/../build') . DS;
        $location = $buildpath;
        $collection = '@root.descendants';
        $route = '/';
        $force = true;
        try {

            $Collection = new Collection(null, $collection, $route, $location, $force);
            $Collection->setup();
            $Collection->buildCollection();
            $Collection->teardown();
            $Collection->buildAssets();
            $Collection->teardown();

        } catch (\Exception $e) {
            throw new \Exception($e);
        }
    }

This works fine on the CLI. BTW I hacked the code so that any CLI output style code was negated.

So I thought I could transfer this to static-generator.phpfile so that it could be activated by admin/plugins/static-generator?static-generator=generate

public function onPageInitialized()
    {
        include __DIR__ . '/vendor/autoload.php';
        if (!empty($_GET['static-generator']) && $_GET['static-generator'] === 'generate') {

            $config = Grav::instance()['config']->get('plugins.static-generator');
            $buildpath = realpath(GRAV_ROOT . '/../build') . DS;
            $location = $buildpath;
            $collection = '@root.descendants';
            $route = '/';
            $force = true;
            try {

                $Collection = new Collection(null, $collection, $route, $location, $force);
                $Collection->setup();
                $Collection->buildCollection();
                $Collection->teardown();
                $Collection->buildAssets();
                $Collection->teardown();

            } catch (\Exception $e) {
                throw new \Exception($e);
            }

        }
    }

But no siree! Get a weird error about index.twig.html not existing. Think it is something to do with the cache.

Anyway - I think this should be an issue but I don't want to annoy you by raising another.

OleVik commented 4 years ago

@SteveMcArthur There is actually code for generating Page(s) via Admin, and like indexing this is done via Server Sent Events. The constraining factor right now is an issue in Admin, which hopefully the changes to the API will resolve.

You can see the code and its usage in the 2.0.0-branch, though it's currently disabled until I can make the API work and have templates properly register. The problem is not the cache, but how Theme's have been initialized until 1.6.21 of Core. I am testing to see if the changes in that version will fix it.