From d739500de0425f1fd54fe832df4046d26ff87964 Mon Sep 17 00:00:00 2001 From: Barry <5648875+BarryMode@users.noreply.github.com> Date: Wed, 28 Mar 2018 17:49:59 -0500 Subject: [PATCH] v0.11.2: Assets simplified --- CHANGELOG.md | 20 +++++++++++++------- README.md | 14 +++++--------- blueprints.yaml | 2 +- cli/GenerateCommand.php | 37 ++++++++++++++++--------------------- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cf506..62b6d6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ +# v0.11.2 +## 3/28/2018 +1. [](#improved) + * Breaking change: `--copy-assets` -> `--assets` + * Assets has been simplified and no longer accepts input. + # v0.11.1 -## 3/13/2018 +## 3/14/2018 1. [](#bugfix) * `--copy-assets` didn't previously take external assets into consideration @@ -27,16 +33,16 @@ ## 10/23/2017 1. [](#bugfix) - * Fixed bug where only the home page was generated when -r wasn't set + * Fixed bug where only the home page was generated when `-r` wasn't set # v0.9.0 ## 10/23/2017 1. [](#new) - * Force option allows for users to overwrite previously generated files - * Routes option allows the user to choose which pages get generated + * `--force` option allows for users to overwrite previously generated files + * `--routes` option allows the user to choose which pages get generated 1. [](#improved) - * Separate the admin plugin settings from the CLI + * Separated the admin plugin settings from the CLI # v0.8.4 ## 9/1/2017 @@ -136,7 +142,7 @@ 1. [](#improved) * Removed hacky JS shit - * Added `g` as an alt short form of generate + * Added `g` as an alt short form of `generate` 2. [](#bugfix) * Fixed link error to pages query ([#3](https://github.com/barrymode/grav-plugin-blackhole/issues/3)) @@ -172,7 +178,7 @@ ## 10/06/2016 1. [](#new) - * Use ?pages=all to bypass impossible call grav->['pages'] in CLI + * Use `?pages=all` to bypass impossible call `grav->['pages']` in CLI * Loop and curl to generate the pages * Named Blackhole to go with Grav * ChangeLog, Blueprints, README \ No newline at end of file diff --git a/README.md b/README.md index bced687..a1c3f0a 100644 --- a/README.md +++ b/README.md @@ -50,26 +50,22 @@ bin/plugin blackhole generate http://localhost/grav ``` - **Routes** `--routes` or `-r` - Define a list of routes to only generate certain pages. Accepts a comma-separated list. + Define a list of routes to only generate certain pages. ```bash --routes home,about,about/contact ``` -- **Copy Assets** `--copy-assets` or `-c` - Copy assets to the output path with a white list of file types. Accepts a comma-separated list. - - ```bash - --copy-assets css,js,jpg,png,gif,ico - ``` - - **Simultaneous Limit** `--simultaneous` or `-s` - Set how many files to generate at the same time (default: 10, must be greater than 1) + Set how many files to generate at the same time (default: 10, must be greater than 1). ```bash --simultaneous 10 ``` +- **Assets** `--assets` or `-a` + Copy assets to the output path. + - **Force** `--force` or `-f` Overwrite previously generated files. diff --git a/blueprints.yaml b/blueprints.yaml index e76b249..e6cad79 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Blackhole -version: 0.11.1 +version: 0.11.2 description: Static site generator for Grav icon: circle author: diff --git a/cli/GenerateCommand.php b/cli/GenerateCommand.php index 3d4c34f..0330a55 100644 --- a/cli/GenerateCommand.php +++ b/cli/GenerateCommand.php @@ -39,13 +39,7 @@ protected function configure() { 'routes', 'r', InputOption::VALUE_REQUIRED, - 'Define a list of routes to only generate certain pages. Accepts a comma-separated list.' - ) - ->addOption( - 'copy-assets', - 'c', - InputOption::VALUE_REQUIRED, - 'Copy assets to the output path with a white list of file types. Accepts a comma-separated list.' + 'Define a list of routes to only generate certain pages.' ) ->addOption( 'simultaneous', @@ -54,6 +48,12 @@ protected function configure() { 'Set how many files to generate at the same time.', 10 ) + ->addOption( + 'assets', + 'a', + InputOption::VALUE_NONE, + 'Copy assets to the output path.' + ) ->addOption( 'force', 'f', @@ -70,16 +70,16 @@ protected function serve() { 'output-url' => $this->input->getOption('output-url'), 'output-path' => $this->input->getOption('output-path'), 'routes' => $this->input->getOption('routes'), - 'asset-types' => $this->input->getOption('copy-assets'), 'simultaneous' => $this->input->getOption('simultaneous'), + 'assets' => $this->input->getOption('assets'), 'force' => $this->input->getOption('force') ]; $input_url = $this->options['input-url']; $output_url = $this->options['output-url']; $output_path = $this->options['output-path']; $routes = $this->options['routes']; - $asset_types = $this->options['asset-types']; $simultaneous = $this->options['simultaneous']; + $assets = $this->options['assets']; $force = $this->options['force']; // curl @@ -116,15 +116,12 @@ function portal($in, $out, $content) { } // get links to assets - function tidal_disruption($data, $asset_types, $elements, $attribute) { + function tidal_disruption($data, $elements, $attribute) { $doc = new \DOMDocument(); @$doc->loadHTML($data); $links = array(); foreach($doc->getElementsByTagName($elements) as $element) { - preg_match('/[^.]+$/', $element->getAttribute($attribute), $match); - if (!empty($match[0]) && in_array($match[0], $asset_types)) { - $links[] = $element->getAttribute($attribute); - } + $links[] = $element->getAttribute($attribute); } return $links; } @@ -162,7 +159,7 @@ function generate($route, $file_path, $data) { $request->bh_file_path = preg_replace('/\/\/+/', '/', $request->bh_route . '/index.html'); $request->input_url = $input_url; $request->output_url = $output_url; - $request->asset_types = $asset_types; + $request->assets = $assets; $request->simultaneous = (int)$simultaneous; $request->force = $force; $rollingCurl->add($request); @@ -194,13 +191,11 @@ function generate($route, $file_path, $data) { $this->output->writeln('GENERATING ➜ ' . realpath($request->bh_route)); } // copy assets - if (!empty($request->asset_types)) { - $asset_types = array(); foreach (explode(',', $request->asset_types) as $asset_type) { $asset_types[] = $asset_type; } + if ($request->assets) { $asset_links = array(); - $asset_links[] = tidal_disruption($grav_page_data, $asset_types, 'link', 'href'); - $asset_links[] = tidal_disruption($grav_page_data, $asset_types, 'script', 'src'); - $asset_links[] = tidal_disruption($grav_page_data, $asset_types, 'a', 'href'); - $asset_links[] = tidal_disruption($grav_page_data, $asset_types, 'img', 'src'); + $asset_links[] = tidal_disruption($grav_page_data, 'link', 'href'); + $asset_links[] = tidal_disruption($grav_page_data, 'script', 'src'); + $asset_links[] = tidal_disruption($grav_page_data, 'img', 'src'); $input_url_parts = parse_url($request->input_url); foreach (array_flatten($asset_links) as $asset) { if (strpos($asset, '/') === 0 || $input_url_parts['host'] === parse_url($asset)['host']) {