Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
v0.11.2: Assets simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry authored and Barry committed Mar 28, 2018
1 parent bce2212 commit d739500
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
20 changes: 13 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Blackhole
version: 0.11.1
version: 0.11.2
description: Static site generator for Grav
icon: circle
author:
Expand Down
37 changes: 16 additions & 21 deletions cli/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -194,13 +191,11 @@ function generate($route, $file_path, $data) {
$this->output->writeln('<green>GENERATING</green> ➜ ' . 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']) {
Expand Down

0 comments on commit d739500

Please sign in to comment.